pgsql-ast-parser
pgsql-ast-parser copied to clipboard
fix: binop minus without space
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.