Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the semicolon queryable #135

Merged
merged 4 commits into from
Nov 12, 2021
Merged

Conversation

resolritter
Copy link
Contributor

closes #134

First I tried to make the semicolon rule inline, like done in the JS grammar, but then a conflict came up and I was not able to solve it. On the other hand, this alternative of inlining the semicolon literal did work.

For me it's reasonable to not give up on the semicolon rule and instead rework it so that the use-case of #134 is achieved, but as already explained, I was not able to make this idea work.

grammar.js Show resolved Hide resolved
grammar.js Outdated
Comment on lines 81 to 82
sep1($._simple_statement, ';'),
optional(';'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this isn't exactly the same as the before, it doesn't cover the first case, only the second, and it allows the third.

a = 'a'; b = 'b''
a = 'a'; b = 'b';
a = 'a'; b = 'b';;  # this is wrong

Would be great to add a test for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests in 29b828e. They are passing locally.

Copy link
Contributor

@stsewd stsewd Nov 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the last expression shouldn't be valid

~/github/tree-sitter-python on  semicolon! ⌚ 13:45:27
$ cat test.py
   1   a = 'a'; b = 'b'

~/github/tree-sitter-python on  semicolon! ⌚ 13:45:29
$ npm run parse -- test.py

> [email protected] parse
> tree-sitter parse "test.py"

(module [0, 0] - [1, 0]
  (expression_statement [0, 0] - [0, 7]
    (assignment [0, 0] - [0, 7]
      left: (identifier [0, 0] - [0, 1])
      right: (string [0, 4] - [0, 7])))
  (expression_statement [0, 9] - [0, 16]
    (assignment [0, 9] - [0, 16]
      left: (identifier [0, 9] - [0, 10])
      right: (string [0, 13] - [0, 16]))))


~/github/tree-sitter-python on  semicolon! ⌚ 13:45:32
$ cat test.py
   1   a = 'a'; b = 'b';

~/github/tree-sitter-python on  semicolon! ⌚ 13:45:40
$ npm run parse -- test.py

> [email protected] parse
> tree-sitter parse "test.py"

(module [0, 0] - [1, 0]
  (expression_statement [0, 0] - [0, 7]
    (assignment [0, 0] - [0, 7]
      left: (identifier [0, 0] - [0, 1])
      right: (string [0, 4] - [0, 7])))
  (expression_statement [0, 9] - [0, 16]
    (assignment [0, 9] - [0, 16]
      left: (identifier [0, 9] - [0, 10])
      right: (string [0, 13] - [0, 16]))))

~/github/tree-sitter-python on  semicolon! ⌚ 13:45:42
$ cat test.py
   1   a = 'a'; b = 'b';;  # this is wrong

~/github/tree-sitter-python on  semicolon! ⌚ 13:45:51
$ npm run parse -- test.py

> [email protected] parse
> tree-sitter parse "test.py"

(module [0, 0] - [1, 0]
  (expression_statement [0, 0] - [0, 7]
    (assignment [0, 0] - [0, 7]
      left: (identifier [0, 0] - [0, 1])
      right: (string [0, 4] - [0, 7])))
  (expression_statement [0, 9] - [0, 16]
    (assignment [0, 9] - [0, 16]
      left: (identifier [0, 9] - [0, 10])
      right: (string [0, 13] - [0, 16])))
  (expression_statement [0, 17] - [0, 17]
    (identifier [0, 17] - [0, 17]))
  (comment [0, 20] - [0, 35]))
test.py 0 ms    (MISSING identifier [0, 17] - [0, 17])

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With master, the last case results in

(module [0, 0] - [1, 0]
  (expression_statement [0, 0] - [0, 7]
    (assignment [0, 0] - [0, 7]
      left: (identifier [0, 0] - [0, 1])
      right: (string [0, 4] - [0, 7])))
  (ERROR [0, 7] - [0, 17]
    (expression_statement [0, 9] - [0, 16]
      (assignment [0, 9] - [0, 16]
        left: (identifier [0, 9] - [0, 10])
        right: (string [0, 13] - [0, 16])))))
test.py 0 ms    (ERROR [0, 7] - [0, 17])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried reverting to how the rule is in master but it did not result in an error. Might have something to do with the semicolon now being a literal instead of a $ => * rule.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, I think this is fine (it generates a missing node)

@maxbrunsfeld maxbrunsfeld merged commit 24b530c into tree-sitter:master Nov 12, 2021
@maxbrunsfeld
Copy link
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to query semicolons
3 participants