whitequark / whitequark/parser
Unary `+` precedence
Nobody has claimed this yet.
- Dominant language
- Yacc
- Stars
- 1.6k
- Forks
- 205
- PR merge metrics
- No merged PRs in 30d
Description
There are two issues with unary + precedence that I can find.
The first is that the parser is creating a send node, when there isn't really going to be a method call. This is, for example:
class Integer; def +@; self * 10; end; end
+5 ** 2 # => 25
+ 5 ** 2 # => 2500
As you can see, the space affects the result. If there is no space, then no method call is generated. However, in both cases you get the same AST:
(send
(send
(int 5) :**
(int 2)) :+@)
The other issue is that the precedence in this AST is incorrect in both cases. This is implying that the expression should be parsed as:
+(5 ** 2)
but in reality, in both cases it should be parsed as:
(+5) ** 2 # => 25
(+ 5) ** 2 # => 2500
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 by reproducing the two unary + examples from the issue and inspect the parser code that builds the shown send AST. Compare the AST and evaluation for spaced and unspaced forms, then verify that the resulting trees reflect the documented grouping and method-call behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100