tree-sitter / tree-sitter-ruby

Ruby grammar for tree-sitter
MIT License
176 stars 58 forks source link

bug: String concatenation using << and without spaces considers it as a heredoc #256

Open Bennet-Sunder opened 4 months ago

Bennet-Sunder commented 4 months ago

Did you check existing issues?

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

tree-sitter = "0.20.6", tree-sitter-ruby = "0.20.1"

Describe the bug

When using string concatenation without any spaces using << operator it looks like it is mistaking it for a heredoc string.

Steps To Reproduce/Bad Parse Tree

Using the ruby code

"test"<<"ruby"

Generates the following tree

program [0, 0] - [1, 0]
  string [0, 0] - [0, 6]
    string_content [0, 1] - [0, 5]
  MISSING ; [0, 6] - [0, 6]
  heredoc_beginning [0, 6] - [0, 14]
  heredoc_body [0, 14] - [1, 0]
    heredoc_content [0, 14] - [1, 0]
    heredoc_end [1, 0] - [1, 0]

Here the string followed by << is considered as a heredoc but this code evaluates to "testruby". When I add a space after the << I get the below tree which is what I'm looking for.

for code

"test"<< "ruby"

This is the tree

program [0, 0] - [1, 0]
binary [0, 0] - [0, 15]
    left: string [0, 0] - [0, 6]
    string_content [0, 1] - [0, 5]
    right: string [0, 9] - [0, 15]
    string_content [0, 10] - [0, 14]

Expected Behavior/Parse Tree

Tree with spaces

This is the tree

program [0, 0] - [1, 0]
binary [0, 0] - [0, 15]
    left: string [0, 0] - [0, 6]
    string_content [0, 1] - [0, 5]
    right: string [0, 9] - [0, 15]
    string_content [0, 10] - [0, 14]

Repro

No response