Skip to content

Commit

Permalink
Merge pull request #168 from yui-knk/initialize_ivars
Browse files Browse the repository at this point in the history
Refactoring prec instance variables in parser
  • Loading branch information
yui-knk authored Oct 30, 2023
2 parents 116d364 + 9eff504 commit f9d3772
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 26 deletions.
50 changes: 28 additions & 22 deletions lib/lrama/parser.rb

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

14 changes: 10 additions & 4 deletions parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,13 @@ rule

rhs: /* empty */
{
reset_precs
result = []
@prec_seen = false
@code_after_prec = false
}
| "%empty"
{
reset_precs
result = []
@prec_seen = false
@code_after_prec = false
}
| rhs symbol named_ref_opt
{
Expand Down Expand Up @@ -405,6 +403,7 @@ def parse
@lexer = Lrama::Lexer.new(@text)
@grammar = Lrama::Grammar.new
@precedence_number = 0
reset_precs
do_parse
@grammar.extract_references
@grammar.prepare
Expand All @@ -427,3 +426,10 @@ def on_error(error_token_id, error_value, value_stack)
#{' ' * @lexer.column}^
ERROR
end

private

def reset_precs
@prec_seen = false
@code_after_prec = false
end

0 comments on commit f9d3772

Please sign in to comment.