From 4ea2003b7b0ea7a2343d0b1c08f5fe87bbb882cb Mon Sep 17 00:00:00 2001 From: David Majda Date: Sun, 14 Nov 2010 17:11:36 +0100 Subject: [PATCH] Export PEG.VERSION property with PEG.js version Value of the property is read in build time from the VERSION file. --- Rakefile | 10 ++++++---- src/peg.js | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Rakefile b/Rakefile index 94e67de..90e5846 100644 --- a/Rakefile +++ b/Rakefile @@ -12,18 +12,20 @@ PEGJS_OUT_FILE = "#{LIB_DIR}/peg.js" PARSER_SRC_FILE = "#{SRC_DIR}/parser.pegjs" PARSER_OUT_FILE = "#{SRC_DIR}/parser.js" -def preprocess(input, base_dir) +PEGJS_VERSION = File.read("VERSION").strip + +def preprocess(input, base_dir, version) input.split("\n").map do |line| if line =~ /^\s*\/\/\s*@include\s*"([^"]*)"\s*$/ included_file = "#{base_dir}/#$1" if !File.exist?(included_file) abort "Included file \"#{included_file}\" does not exist." end - preprocess(File.read(included_file), base_dir) + preprocess(File.read(included_file), base_dir, version) else line end - end.join("\n") + end.join("\n").gsub("@VERSION", version) end file PARSER_OUT_FILE => PARSER_SRC_FILE do @@ -32,7 +34,7 @@ end file PEGJS_OUT_FILE => SRC_FILES do File.open(PEGJS_OUT_FILE, "w") do |f| - f.write(preprocess(File.read(PEGJS_SRC_FILE), SRC_DIR)) + f.write(preprocess(File.read(PEGJS_SRC_FILE), SRC_DIR, PEGJS_VERSION)) end end diff --git a/src/peg.js b/src/peg.js index c68b626..5d1364f 100644 --- a/src/peg.js +++ b/src/peg.js @@ -3,6 +3,9 @@ var undefined; var PEG = { + /* PEG.js version. */ + VERSION: "@VERSION", + /* * Generates a parser from a specified grammar and returns it. *