Skip to content

Commit

Permalink
Use if_clause instead of symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Aug 21, 2024
1 parent 395f5c3 commit 78e6231
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
10 changes: 6 additions & 4 deletions lib/lrama/grammar/parameterizing_rule/rhs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/lrama/parser.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 78e6231

Please sign in to comment.