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

fix: binop minus without space #152

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

gthb
Copy link
Contributor

@gthb gthb commented Feb 27, 2024

What

Fix the bug that the expression 42-51 fails to parse, because the tokenizer greedily treats -51 as being a number token.

Closes #133

How

Move the lexer definitions for int and float to be below the op_minus definition. This changes the precedence so that the lexer emits a unary minus followed by an integer, rather than emitting a single negative-integer token.

Update tests in src/lexer.spec.ts to expect this.

Update tests in src/syntax/expr.spec.ts to expect the resulting wrapping of integer literals with type: unary AST nodes. In particular, replace the incorrect assertion checkInvalidExpr('42.-51'); with one expecting a binary AST node because that expression is valid.

Change the parser definitions expr_member and simplestatements_set_timezone_val to parse the unary-followed-by-integer token sequence as a negative integer, as that is the only thing that makes sense in those expressions, and it limits the footprint of the change.

Change some test expectations to expect a unary minus expression.

Change the parsing of ->>-9 and of SET TIMEZONE -9 to convert the unary minus expression to a negative integer.
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.

Expression that subtracts a literal number without space fails to parse
1 participant