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

Added Sequence Operations, selector and test cases #23

Merged
merged 5 commits into from
Jul 14, 2024
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
32 changes: 28 additions & 4 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,11 @@ module.exports = grammar({
// Expressions

expression: $ => prec(1, choice(
$.sequence_operation,
$.comparison_operator,
$.not_operator,
$.boolean_operator,
$.selector_expression,
$.primary_expression,
$.as_expression,
$.conditional_expression,
Expand All @@ -547,7 +549,12 @@ module.exports = grammar({
field('alias', $.expression),
)),

primary_expression: $ => prec(2, choice(
selector_expression: $ => prec.left(4, seq(
$.expression,
repeat1($.select_suffix)
)),

primary_expression: $ => prec.left(2, choice(
$.binary_operator,
$.identifier,
$.string,
Expand All @@ -560,6 +567,7 @@ module.exports = grammar({
$.unary_operator,
$.attribute,
$.subscript,
$.select_suffix,
$.call,
$.list,
$.list_comprehension,
Expand Down Expand Up @@ -704,21 +712,32 @@ module.exports = grammar({
];

// @ts-ignore
return choice(...table.map(([fn, operator, precedence]) => fn(precedence, seq(
return prec(13, choice(...table.map(([fn, operator, precedence]) => fn(precedence, seq(
field('left', $.primary_expression),
// @ts-ignore
field('operator', operator),
field('right', $.primary_expression),
))));
)))));
},

unary_operator: $ => prec(PREC.unary, seq(
field('operator', choice('+', '-', '~')),
field('argument', $.primary_expression),
)),

sequence_operation: $ => seq(choice(
$.in_operation,
$.not_in_operation,
$.binary_operator,
$.subscript,
$.call,
)),

in_operation: $ => prec.left(3, seq(choice($.list_comprehension, $.dictionary_comprehension, $.list, $.dictionary), 'in', choice($.list_comprehension, $.dictionary_comprehension, $.list, $.dictionary))),
not_in_operation: $ => prec.left(11, seq(choice($.list_comprehension, $.dictionary_comprehension, $.list, $.dictionary), 'not', 'in', $.expression)),

comparison_operator: $ => prec.left(2, seq(
choice($.primary_expression,$.identifier,$.dotted_name),
choice($.primary_expression,$.identifier,$.dotted_name, $.selector_expression),
repeat1(seq(
field('operators',
choice(
Expand Down Expand Up @@ -760,6 +779,11 @@ module.exports = grammar({
':',
field('right', $.schema_expr),
),

select_suffix: $ => prec(44, choice(
seq('.', $.identifier),
seq('?.', $.identifier)
)),

attribute: $ => prec.right(11, seq(
field('name', $.identifier),
Expand Down
Loading
Loading