diff --git a/.gitignore b/.gitignore index f207758..cdecab1 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -lib/*.min.js +lib/* diff --git a/README.md b/README.md index 6577fbe..f18e9ac 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,15 @@ Features * Handles wide class of grammars (superset of LL(*k*) and LR(*k*)) * Precise and human-friendly error reporting +Building +-------- + +To build PEG.js, simply run the `rake` command: + + $ rake + +Of course, you need to have [Rake](http://rake.rubyforge.org/) installed. The command creates PEG.js library in `lib/peg.js` by processing files in the `src` directory. + Usage ----- diff --git a/Rakefile b/Rakefile index 5a786fd..a769c20 100644 --- a/Rakefile +++ b/Rakefile @@ -1,4 +1,31 @@ +SRC_DIR = "src" +LIB_DIR = "lib" +BIN_DIR = "bin" + +def preprocess(input, base_dir) + 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) + else + line + end + end.join("\n") +end + desc "Generate the grammar parser" task :metaparser do - system "bin/pegjs PEG.parser lib/metagrammar.pegjs" + system "#{BIN_DIR}/pegjs PEG.parser #{SRC_DIR}/parser.pegjs" +end + +desc "Build the peg.js file" +task :build do + File.open("#{LIB_DIR}/peg.js", "w") do |f| + f.write(preprocess(File.read("#{SRC_DIR}/peg.js"), SRC_DIR)) + end end + +task :default => :build diff --git a/benchmark/index.html b/benchmark/index.html index 3bc29a5..ac61e97 100644 --- a/benchmark/index.html +++ b/benchmark/index.html @@ -60,8 +60,7 @@ - - + - - + - +