Export PEG.VERSION property with PEG.js version

Value of the property is read in build time from the VERSION file.
redux
David Majda 14 years ago
parent e3effab86b
commit 4ea2003b7b

@ -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

@ -3,6 +3,9 @@
var undefined;
var PEG = {
/* PEG.js version. */
VERSION: "@VERSION",
/*
* Generates a parser from a specified grammar and returns it.
*

Loading…
Cancel
Save