Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Export PEG.VERSION property with PEG.js version

Value of the property is read in build time from the VERSION file.
  • Loading branch information...
commit 4ea2003b7b0ea7a2343d0b1c08f5fe87bbb882cb 1 parent e3effab
@dmajda dmajda authored
Showing with 9 additions and 4 deletions.
  1. +6 −4 Rakefile
  2. +3 −0  src/peg.js
View
10 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
View
3  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.
*
Please sign in to comment.
Something went wrong with that request. Please try again.