Export PEG.VERSION property with PEG.js version
Value of the property is read in build time from the VERSION file.
This commit is contained in:
parent
e3effab86b
commit
4ea2003b7b
10
Rakefile
10
Rakefile
|
@ -12,18 +12,20 @@ PEGJS_OUT_FILE = "#{LIB_DIR}/peg.js"
|
||||||
PARSER_SRC_FILE = "#{SRC_DIR}/parser.pegjs"
|
PARSER_SRC_FILE = "#{SRC_DIR}/parser.pegjs"
|
||||||
PARSER_OUT_FILE = "#{SRC_DIR}/parser.js"
|
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|
|
input.split("\n").map do |line|
|
||||||
if line =~ /^\s*\/\/\s*@include\s*"([^"]*)"\s*$/
|
if line =~ /^\s*\/\/\s*@include\s*"([^"]*)"\s*$/
|
||||||
included_file = "#{base_dir}/#$1"
|
included_file = "#{base_dir}/#$1"
|
||||||
if !File.exist?(included_file)
|
if !File.exist?(included_file)
|
||||||
abort "Included file \"#{included_file}\" does not exist."
|
abort "Included file \"#{included_file}\" does not exist."
|
||||||
end
|
end
|
||||||
preprocess(File.read(included_file), base_dir)
|
preprocess(File.read(included_file), base_dir, version)
|
||||||
else
|
else
|
||||||
line
|
line
|
||||||
end
|
end
|
||||||
end.join("\n")
|
end.join("\n").gsub("@VERSION", version)
|
||||||
end
|
end
|
||||||
|
|
||||||
file PARSER_OUT_FILE => PARSER_SRC_FILE do
|
file PARSER_OUT_FILE => PARSER_SRC_FILE do
|
||||||
|
@ -32,7 +34,7 @@ end
|
||||||
|
|
||||||
file PEGJS_OUT_FILE => SRC_FILES do
|
file PEGJS_OUT_FILE => SRC_FILES do
|
||||||
File.open(PEGJS_OUT_FILE, "w") do |f|
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
var undefined;
|
var undefined;
|
||||||
|
|
||||||
var PEG = {
|
var PEG = {
|
||||||
|
/* PEG.js version. */
|
||||||
|
VERSION: "@VERSION",
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generates a parser from a specified grammar and returns it.
|
* Generates a parser from a specified grammar and returns it.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue