lib/lrama/command.rb in lrama-0.6.1 vs lib/lrama/command.rb in lrama-0.6.2
- old
+ new
@@ -1,7 +1,10 @@
module Lrama
class Command
+ LRAMA_LIB = File.realpath(File.join(File.dirname(__FILE__)))
+ STDLIB_FILE_PATH = File.join(LRAMA_LIB, 'grammar', 'stdlib.y')
+
def run(argv)
begin
options = OptionParser.new.parse(argv)
rescue => e
message = e.message
@@ -12,12 +15,17 @@
Report::Duration.enable if options.trace_opts[:time]
warning = Lrama::Warning.new
text = options.y.read
options.y.close if options.y != STDIN
- parser = Lrama::Parser.new(text, options.grammar_file, options.debug)
begin
- grammar = parser.parse
+ grammar = Lrama::Parser.new(text, options.grammar_file, options.debug).parse
+ unless grammar.no_stdlib
+ stdlib_grammar = Lrama::Parser.new(File.read(STDLIB_FILE_PATH), STDLIB_FILE_PATH, options.debug).parse
+ grammar.insert_before_parameterizing_rules(stdlib_grammar.parameterizing_rules)
+ end
+ grammar.prepare
+ grammar.validate!
rescue => e
raise e if options.debug
message = e.message
message = message.gsub(/.+/, "\e[1m\\&\e[m") if Exception.to_tty?
abort message