Skip to content

Commit

Permalink
Merge pull request #128 from junk0612/replace-new-parser-4
Browse files Browse the repository at this point in the history
Replace NewParser with Parser #4
  • Loading branch information
yui-knk authored Oct 16, 2023
2 parents aba9428 + c239880 commit 0358e87
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 31 deletions.
68 changes: 45 additions & 23 deletions lib/lrama/new_parser.rb

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

20 changes: 17 additions & 3 deletions parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ rule

token_declaration_for_precedence: id

id: IDENTIFIER
| CHARACTER
id: IDENTIFIER { raise "Ident after %prec" if @prec_seen }
| CHARACTER { raise "Char after %prec" if @prec_seen }

grammar: rules_or_grammar_declaration
| grammar rules_or_grammar_declaration
Expand All @@ -280,7 +280,12 @@ rule
}
| rhs_list ";"

rhs: /* empty */ { result = [] }
rhs: /* empty */
{
result = []
@prec_seen = false
@code_after_prec = false
}
| rhs symbol named_ref_opt
{
token = val[1]
Expand All @@ -289,6 +294,10 @@ rule
}
| rhs "{"
{
if @prec_seen
raise "Multiple User_code after %prec" if @code_after_prec
@code_after_prec = true
end
@lexer.status = :c_declaration
@lexer.end_symbol = '}'
}
Expand All @@ -305,6 +314,10 @@ rule
}
| "{"
{
if @prec_seen
raise "Multiple User_code after %prec" if @code_after_prec
@code_after_prec = true
end
@lexer.status = :c_declaration
@lexer.end_symbol = '}'
}
Expand All @@ -323,6 +336,7 @@ rule
{
sym = @grammar.find_symbol_by_id!(val[2])
result = val[0].append(sym)
@prec_seen = true
}

named_ref_opt: # empty
Expand Down
10 changes: 5 additions & 5 deletions spec/lrama/new_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ class : keyword_class tSTRING keyword_end { code 1 }
])
end

xit "error token" do
it "error token" do
y = header + <<~INPUT
%%
Expand Down Expand Up @@ -648,7 +648,7 @@ class : keyword_class tSTRING keyword_end { code 1 }
])
end

xit "action in the middle of RHS" do
it "action in the middle of RHS" do
y = header + <<~INPUT
%%
Expand Down Expand Up @@ -744,7 +744,7 @@ class : keyword_class { code 1 } tSTRING { code 2 } keyword_end { code 3 }
end

describe "invalid_prec" do
xit do
it do
y = header + <<~INPUT
%%
Expand All @@ -761,7 +761,7 @@ class : keyword_class tSTRING %prec tPLUS keyword_end { code 1 }
expect { parser.parse }.to raise_error("Ident after %prec")
end

xit do
it do
y = header + <<~INPUT
%%
Expand All @@ -778,7 +778,7 @@ class : keyword_class { code 2 } tSTRING %prec "=" '!' keyword_end { code 3 }
expect { parser.parse }.to raise_error("Char after %prec")
end

xit do
it do
y = header + <<~INPUT
%%
Expand Down

0 comments on commit 0358e87

Please sign in to comment.