Skip to content

Commit

Permalink
Added grammar for selector expression
Browse files Browse the repository at this point in the history
Signed-off-by: Vishal <[email protected]>
  • Loading branch information
Vishalk91-4 committed Jul 9, 2024
1 parent c9d14bc commit 87f1074
Show file tree
Hide file tree
Showing 7 changed files with 89,551 additions and 86,998 deletions.
20 changes: 14 additions & 6 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ module.exports = grammar({
$.comparison_operator,
$.not_operator,
$.boolean_operator,
$.selector_expression,
$.primary_expression,
$.as_expression,
$.conditional_expression,
Expand All @@ -548,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 Down Expand Up @@ -723,18 +729,15 @@ module.exports = grammar({
$.not_in_operation,
$.concatenation,
$.subscript,
$.min,
$.max
$.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)),
concatenation: $ => prec.left(12, seq(choice($.list_comprehension, $.dictionary_comprehension, $.list, $.dictionary), '+', $.expression)),
min: $ => prec.left(13, seq('min', '(', choice($.list_comprehension, $.dictionary_comprehension, $.list, $.dictionary), ')')),
max: $ => prec.left(14, seq('max', '(', choice($.list_comprehension, $.dictionary_comprehension, $.list, $.dictionary), ')')),

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 @@ -776,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
155 changes: 65 additions & 90 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,10 @@
"type": "SYMBOL",
"name": "boolean_operator"
},
{
"type": "SYMBOL",
"name": "selector_expression"
},
{
"type": "SYMBOL",
"name": "primary_expression"
Expand Down Expand Up @@ -1536,8 +1540,28 @@
]
}
},
"selector_expression": {
"type": "PREC_LEFT",
"value": 4,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "select_suffix"
}
}
]
}
},
"primary_expression": {
"type": "PREC",
"type": "PREC_LEFT",
"value": 2,
"content": {
"type": "CHOICE",
Expand Down Expand Up @@ -2593,11 +2617,7 @@
},
{
"type": "SYMBOL",
"name": "min"
},
{
"type": "SYMBOL",
"name": "max"
"name": "call"
}
]
}
Expand Down Expand Up @@ -2738,90 +2758,6 @@
]
}
},
"min": {
"type": "PREC_LEFT",
"value": 13,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "min"
},
{
"type": "STRING",
"value": "("
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "list_comprehension"
},
{
"type": "SYMBOL",
"name": "dictionary_comprehension"
},
{
"type": "SYMBOL",
"name": "list"
},
{
"type": "SYMBOL",
"name": "dictionary"
}
]
},
{
"type": "STRING",
"value": ")"
}
]
}
},
"max": {
"type": "PREC_LEFT",
"value": 14,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "max"
},
{
"type": "STRING",
"value": "("
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "list_comprehension"
},
{
"type": "SYMBOL",
"name": "dictionary_comprehension"
},
{
"type": "SYMBOL",
"name": "list"
},
{
"type": "SYMBOL",
"name": "dictionary"
}
]
},
{
"type": "STRING",
"value": ")"
}
]
}
},
"comparison_operator": {
"type": "PREC_LEFT",
"value": 2,
Expand All @@ -2842,6 +2778,10 @@
{
"type": "SYMBOL",
"name": "dotted_name"
},
{
"type": "SYMBOL",
"name": "selector_expression"
}
]
},
Expand Down Expand Up @@ -3135,6 +3075,41 @@
}
]
},
"select_suffix": {
"type": "PREC",
"value": 44,
"content": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "."
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "?."
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
}
]
}
},
"attribute": {
"type": "PREC_RIGHT",
"value": 11,
Expand Down
Loading

0 comments on commit 87f1074

Please sign in to comment.