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

Parser improvements: != operator and key: [line_break] #220

Merged
merged 4 commits into from
Jun 27, 2022

Conversation

aibaars
Copy link
Contributor

@aibaars aibaars commented Jun 24, 2022

This pull request implements two fixes to the parser:

  • parsing of x!=1 (used to be parsed as x!(1) instead of x != 1)
  • handling of line breaks after a hash-key symbol, for example
foo x:
   "some text"

should be parsed as foo(x: "some text") but it was parsed as foo(x:); "some text" because the parser incorrectly interpreted the line break after x: as a statement terminator.

The first problem is addressed by letting the scanner handle identifiers that end with !, so it can do a negative lookahead test for a = character.

The second problem is addressed by adding a fake "no_line_break" token in the grammar right after the : symbol in a pair and change the scanner so it won't produce "line_break" symbols if a "no_line_break" symbol is expected. This solution feels a bit "hacky" to me, but it could not think of a better way. @maxbrunsfeld any ideas?

Checklist:

  • All tests pass in CI.
  • There are sufficient tests for the new fix/feature.
  • Grammar rules have not been renamed unless absolutely necessary.
  • The conflicts section hasn't grown too much.
  • The parser size hasn't grown too much (check the value of STATE_COUNT in src/parser.c).

@aryx aryx requested a review from maxbrunsfeld June 24, 2022 12:11
@@ -982,7 +998,7 @@ method call with keyword args
foo(a: true)
foo a: true
foo B: true
foo a:
foo a: ;
Copy link
Contributor

Choose a reason for hiding this comment

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

was this semicolon intended here?

Copy link
Contributor Author

@aibaars aibaars Jun 24, 2022

Choose a reason for hiding this comment

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

Yes it is intended. Without the semicolon the test case was not valid Ruby code. The tree-sitter grammar used to accept that code without semicolon, but it really shouldn't have.

@aibaars aibaars merged commit 5b305c3 into tree-sitter:master Jun 27, 2022
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.

2 participants