diff --git a/lib/lrama/grammar/parameterizing_rule/rhs.rb b/lib/lrama/grammar/parameterizing_rule/rhs.rb index b1b4a83d..a5c6ef35 100644 --- a/lib/lrama/grammar/parameterizing_rule/rhs.rb +++ b/lib/lrama/grammar/parameterizing_rule/rhs.rb @@ -4,18 +4,20 @@ module Lrama class Grammar class ParameterizingRule class Rhs - attr_accessor :symbols, :user_code, :precedence_sym + attr_accessor :symbols, :user_code, :precedence_sym, :if_clause def initialize @symbols = [] @user_code = nil @precedence_sym = nil + @if_clause = nil end def skip?(bindings) - return false unless @symbols.last - last_sym = bindings.resolve_symbol(@symbols.last) - last_sym.is_a?(Lexer::Token::ControlSyntax) && last_sym.if? && last_sym.false? + return false unless @if_clause + + resolved = bindings.resolve_symbol(@if_clause) + resolved.is_a?(Lexer::Token::ControlSyntax) && resolved.if? && resolved.false? end def resolve_user_code(bindings) diff --git a/lib/lrama/parser.rb b/lib/lrama/parser.rb index 3e84c0a5..1507395b 100644 --- a/lib/lrama/parser.rb +++ b/lib/lrama/parser.rb @@ -1689,7 +1689,7 @@ def _reduce_61(val, _values, result) module_eval(<<'.,.,', 'parser.y', 201) def _reduce_64(val, _values, result) builder = val[0] - builder.symbols << val[1] if val[1] + builder.if_clause = val[1] result = [builder] result @@ -1699,7 +1699,7 @@ def _reduce_64(val, _values, result) module_eval(<<'.,.,', 'parser.y', 207) def _reduce_65(val, _values, result) builder = val[2] - builder.symbols << val[3] if val[3] + builder.if_clause = val[3] result = val[0].append(builder) result diff --git a/parser.y b/parser.y index aab9d252..75351b9c 100644 --- a/parser.y +++ b/parser.y @@ -200,13 +200,13 @@ rule rule_rhs_list: rule_rhs if_clause? { builder = val[0] - builder.symbols << val[1] if val[1] + builder.if_clause = val[1] result = [builder] } | rule_rhs_list "|" rule_rhs if_clause? { builder = val[2] - builder.symbols << val[3] if val[3] + builder.if_clause = val[3] result = val[0].append(builder) }