Skip to content

Commit

Permalink
Replace NewParser With Parser ruby#2
Browse files Browse the repository at this point in the history
- Skip %empty token as a comment
- Set collect line when parsing empty rhs line
  • Loading branch information
junk0612 committed Oct 15, 2023
1 parent 06c87ff commit 8e3cfbb
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/lrama/new_lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ def lex_token
when @scanner.scan(/\/\//)
@scanner.scan_until(/\n/)
newline
when @scanner.scan(/%empty/)
# noop
else
break
end
Expand Down
4 changes: 2 additions & 2 deletions lib/lrama/new_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 @@ -272,11 +272,11 @@ rule

rhs_list: rhs
{
result = [{rhs: val[0], lineno: val[0].first&.line || @lexer.line}]
result = [{rhs: val[0], lineno: val[0].first&.line || @lexer.line - 1}]
}
| rhs_list "|" rhs
{
result = val[0].append({rhs: val[2], lineno: val[2].first&.line || @lexer.line})
result = val[0].append({rhs: val[2], lineno: val[2].first&.line || @lexer.line - 1})
}
| rhs_list ";"

Expand Down
2 changes: 1 addition & 1 deletion spec/lrama/new_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@
])
end

xit "nullable" do
it "nullable" do
y = File.read(fixture_path("common/nullable.y"))
grammar = Lrama::NewParser.new(y).parse

Expand Down

0 comments on commit 8e3cfbb

Please sign in to comment.