Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cosmosdb/CosmosDBLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ BIT_OR_SYMBOL: '|';
DOUBLE_BAR_SYMBOL: '||';
BIT_XOR_SYMBOL: '^';
EQUAL_SYMBOL: '=';
LESS_THAN_OPERATOR: '<';
LESS_THAN_EQUAL_OPERATOR: '<=';
GREATER_THAN_OPERATOR: '>';
GREATER_THAN_EQUAL_OPERATOR: '>=';
LEFT_SHIFT_OPERATOR: '<<';
Comment on lines +75 to +77
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

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

Duplicate token definitions. LESS_THAN_OPERATOR and GREATER_THAN_OPERATOR are already defined as LA_BRACKET_SYMBOL (line 57) and RA_BRACKET_SYMBOL (line 58). In ANTLR lexers, when multiple token rules match the same input, the first rule wins. This means these operators will never be recognized as LESS_THAN_OPERATOR or GREATER_THAN_OPERATOR - they will always be tokenized as bracket symbols.

Remove these duplicate definitions and update the parser to reference the bracket symbol tokens instead, or remove the bracket symbol definitions from lines 57-58.

Copilot uses AI. Check for mistakes.
RIGHT_SHIFT_OPERATOR: '>>';
ZERO_FILL_RIGHT_SHIFT_OPERATOR: '>>>';
Comment on lines +73 to +79
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

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

Token ordering issue: In ANTLR lexers, longer tokens must be defined before shorter tokens when they share prefixes to avoid ambiguity. The single-character operators < and > should be defined AFTER their multi-character variants (<=, >=, <<, >>, >>>).

Recommended order:

  1. ZERO_FILL_RIGHT_SHIFT_OPERATOR: '>>>' (longest)
  2. LEFT_SHIFT_OPERATOR: '<<'
  3. RIGHT_SHIFT_OPERATOR: '>>'
  4. LESS_THAN_EQUAL_OPERATOR: '<='
  5. GREATER_THAN_EQUAL_OPERATOR: '>='
  6. LESS_THAN_OPERATOR: '<' (shortest)
  7. GREATER_THAN_OPERATOR: '>' (shortest)

Without this ordering, the lexer may incorrectly tokenize <= as < followed by =, or >> as two separate > tokens.

Suggested change
LESS_THAN_OPERATOR: '<';
LESS_THAN_EQUAL_OPERATOR: '<=';
GREATER_THAN_OPERATOR: '>';
GREATER_THAN_EQUAL_OPERATOR: '>=';
LEFT_SHIFT_OPERATOR: '<<';
RIGHT_SHIFT_OPERATOR: '>>';
ZERO_FILL_RIGHT_SHIFT_OPERATOR: '>>>';
ZERO_FILL_RIGHT_SHIFT_OPERATOR: '>>>';
LEFT_SHIFT_OPERATOR: '<<';
RIGHT_SHIFT_OPERATOR: '>>';
LESS_THAN_EQUAL_OPERATOR: '<=';
GREATER_THAN_EQUAL_OPERATOR: '>=';
LESS_THAN_OPERATOR: '<';
GREATER_THAN_OPERATOR: '>';

Copilot uses AI. Check for mistakes.


/* Identifiers */
IDENTIFIER: [a-z] [a-z_0-9]*;
Expand Down
10 changes: 9 additions & 1 deletion cosmosdb/CosmosDBParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,15 @@ binary_operator:
| BIT_XOR_SYMBOL
| BIT_OR_SYMBOL
| DOUBLE_BAR_SYMBOL
| EQUAL_SYMBOL;
| EQUAL_SYMBOL
| LESS_THAN_OPERATOR
| LESS_THAN_EQUAL_OPERATOR
| GREATER_THAN_OPERATOR
| GREATER_THAN_EQUAL_OPERATOR
| LEFT_SHIFT_OPERATOR
| RIGHT_SHIFT_OPERATOR
| ZERO_FILL_RIGHT_SHIFT_OPERATOR
;

unary_operator: BIT_NOT_SYMBOL | PLUS_SYMBOL | MINUS_SYMBOL;

Expand Down
Loading
Loading