Add Generator class
This commit is contained in:
1 parent
a34272dfd6
commit
d2fac07249
3 files changed
+27
-14
No files matched your search
@@ -0,0 +1,22 @@
|
||||
module Imbecile
|
||||
|
||||
# Class to generate the parser generator source.
|
||||
class Generator
|
||||
|
||||
def initialize(grammar)
|
||||
@grammar = grammar
|
||||
end
|
||||
|
||||
def generate(output_file)
|
||||
lexer_dfa = LexerDFA.new(@grammar.tokens)
|
||||
classname = @grammar.classname || output_file.sub(%r{[^a-zA-Z0-9].*}, "").capitalize
|
||||
erb = ERB.new(File.read(File.join(File.dirname(File.expand_path(__FILE__)), "../../assets/parser.d.erb")), nil, "<>")
|
||||
result = erb.result(binding.clone)
|
||||
File.open(output_file, "wb") do |fh|
|
||||
fh.write(result)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
Reference in new issue
Block a user