pegjs/Rakefile
David Majda e59f3ba338 Split the source code into several files, introduce build system
The source code is now in the src directory. The library needs to be
built using "rake", which creates the lib/peg.js file by combining the
source files.
2010-08-15 19:45:51 +02:00

32 lines
737 B
Ruby

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