parser.y in lrama-0.6.11 vs parser.y in lrama-0.7.0
- old
+ new
@@ -23,11 +23,11 @@
}
| "%require" STRING
bison_declaration: grammar_declaration
| "%expect" INTEGER { @grammar.expect = val[1] }
- | "%define" variable value
+ | "%define" variable value { @grammar.define[val[1].s_value] = val[2]&.s_value }
| "%param" param+
| "%lex-param" param+
{
val[1].each {|token|
@grammar.lex_param = Grammar::Code::NoReferenceCode.new(type: :lex_param, token_code: token).token_code.s_value
@@ -426,20 +426,21 @@
---- inner
include Lrama::Report::Duration
-def initialize(text, path, debug = false)
+def initialize(text, path, debug = false, define = {})
@grammar_file = Lrama::Lexer::GrammarFile.new(path, text)
@yydebug = debug
@rule_counter = Lrama::Grammar::Counter.new(0)
@midrule_action_counter = Lrama::Grammar::Counter.new(1)
+ @define = define
end
def parse
report_duration(:parse) do
@lexer = Lrama::Lexer.new(@grammar_file)
- @grammar = Lrama::Grammar.new(@rule_counter)
+ @grammar = Lrama::Grammar.new(@rule_counter, @define)
@precedence_number = 0
reset_precs
do_parse
@grammar
end