tree-sitter-ruby icon indicating copy to clipboard operation
tree-sitter-ruby copied to clipboard

bug: accepting incorrect syntax

Open stackmystack opened this issue 9 months ago • 0 comments

Did you check existing issues?

  • [x] I have read all the tree-sitter docs if it relates to using the parser
  • [x] I have searched the existing issues of tree-sitter-c

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

No response

Describe the bug

The parser accepts incorrect syntax in at least 2 cases:

Unary

Should reject:

bool = not true

Should accept:

bool = (not true)

Ranges

Should reject:

range = 0..
range = 1..2

Which is interpreted as:

range = 0..(range = 1..2)

by the official ruby parser.

Should accept:

range = (0..)
range = 1..2

Steps To Reproduce/Bad Parse Tree

Use tree-sitter-parse.

For the not example:

(program [0, 0] - [1, 0]
  (assignment [0, 0] - [0, 15]
    left: (identifier [0, 0] - [0, 4])
    right: (unary [0, 7] - [0, 15]
      operand: (true [0, 11] - [0, 15]))))

For the ranges example:

(program [0, 0] - [2, 0]
  (assignment [0, 0] - [0, 11]
    left: (identifier [0, 0] - [0, 5])
    right: (range [0, 8] - [0, 11]
      begin: (integer [0, 8] - [0, 9])))
  (assignment [1, 0] - [1, 12]
    left: (identifier [1, 0] - [1, 5])
    right: (range [1, 8] - [1, 12]
      begin: (integer [1, 8] - [1, 9])
      end: (integer [1, 11] - [1, 12]))))

Expected Behavior/Parse Tree

Using tree-sitter parse on the provided example should fail.

Repro


stackmystack avatar Mar 17 '25 16:03 stackmystack