Skip to content

Commit

Permalink
Eliminate parse errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ydah committed Feb 14, 2024
1 parent 15d7e3f commit 56912c3
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 48 deletions.
6 changes: 6 additions & 0 deletions lib/lrama/grammar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require "lrama/grammar/code"
require "lrama/grammar/counter"
require "lrama/grammar/error_token"
require "lrama/grammar/inline"
require "lrama/grammar/parameterizing_rule"
require "lrama/grammar/percent_code"
require "lrama/grammar/precedence"
Expand Down Expand Up @@ -50,6 +51,7 @@ def initialize(rule_counter)
@rules = []
@sym_to_rules = {}
@parameterizing_rule_resolver = ParameterizingRule::Resolver.new
@inline_resolver = Inline::Resolver.new
@empty_symbol = nil
@eof_symbol = nil
@error_symbol = nil
Expand Down Expand Up @@ -118,6 +120,10 @@ def insert_before_parameterizing_rules(rules)
@parameterizing_rule_resolver.rules = rules + @parameterizing_rule_resolver.rules
end

def add_inline_rule(rule)
@inline_resolver.add_inline_rule(rule)
end

def prologue_first_lineno=(prologue_first_lineno)
@aux.prologue_first_lineno = prologue_first_lineno
end
Expand Down
3 changes: 3 additions & 0 deletions lib/lrama/grammar/inline.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require_relative 'inline/resolver'
require_relative 'inline/rhs'
require_relative 'inline/rule'
84 changes: 42 additions & 42 deletions lib/lrama/parser.rb

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

2 changes: 1 addition & 1 deletion parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ rule
result = builder
}

inline_declarations: "%inline" IDENTIFIER ":" inline_rhs_list
inline_declarations: "%inline" id_colon ":" inline_rhs_list
{
rule = Grammar::Inline::Rule.new(val[1].s_value, val[3])
@grammar.add_inline_rule(rule)
Expand Down
11 changes: 6 additions & 5 deletions spec/fixtures/inlining/basic.y
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ static int yyerror(YYLTYPE *loc, const char *str);

%token <i> number

%inline op: '+' { (+) }
| '-' { (-) }
| '*' { (*) }
| '/' { (/) }
%inline op : '+' { (+) }
| '-' { (-) }
| '*' { (*) }
| '/' { (/) }
;

%%

expression : number
: expression op expression { $$ = $1 $2 $3; }
| expression op expression { $$ = $1 $2 $3; }
;

%%
Expand Down

0 comments on commit 56912c3

Please sign in to comment.