whitequark / whitequark/parser
Newlines before comments
Open
Nobody has claimed this yet.
- Dominant language
- Yacc
- Stars
- 1.6k
- Forks
- 205
- PR merge metrics
- No merged PRs in 30d
Description
In the following code:
class C
# foo
end
I would expect the newline token after the C constant to be emitted before the comment token, but it is the opposite:
irb(main):005> Parser::CurrentRuby.new.tokenize(Parser::Source::Buffer.new("", source: "class C\n# foo\nend\n"))
=>
[s(:class,
s(:const, nil, :C), nil, nil),
[#<Parser::Source::Comment :2:1 "# foo">],
[[:kCLASS, ["class", #<Parser::Source::Range 0...5>]],
[:tCONSTANT, ["C", #<Parser::Source::Range 6...7>]],
[:tCOMMENT, ["# foo", #<Parser::Source::Range 8...13>]],
[:tNL, [nil, #<Parser::Source::Range 7...8>]],
[:kEND, ["end", #<Parser::Source::Range 14...17>]],
[:tNL, [nil, #<Parser::Source::Range 17...18>]]]]
I can work around this, but I just want to clarify what the rule is here?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Parser::CurrentRuby.tokenize example using the shown class and comment source, and inspect how the comment and newline tokens are emitted. Compare the observed order with the parser's intended rule for comments and newlines; the issue is done when that rule is clarified and the expected behavior is established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100