2010-07-25 17:54:09 +02:00
|
|
|
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
|
|
|
|
|
2010-04-11 11:05:44 +02:00
|
|
|
desc "Generate the grammar parser"
|
2010-08-15 19:14:43 +02:00
|
|
|
task :parser do
|
2010-07-25 17:54:09 +02:00
|
|
|
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
|
2010-03-13 15:18:57 +01:00
|
|
|
end
|
2010-07-25 17:54:09 +02:00
|
|
|
|
|
|
|
task :default => :build
|