-
-
Notifications
You must be signed in to change notification settings - Fork 142
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
Conversation
30a61d8
to
8600fea
Compare
grammar.js
Outdated
sep1($._simple_statement, ';'), | ||
optional(';'), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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])
There was a problem hiding this comment.
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])
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
Thanks! |
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.