Skip to content

Commit

Permalink
Added Sequence Operations and test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishalk91-4 committed Jul 2, 2024
1 parent a9e20d4 commit 2b2f646
Show file tree
Hide file tree
Showing 5 changed files with 92,568 additions and 72,166 deletions.
16 changes: 16 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ module.exports = grammar({
// Expressions

expression: $ => prec(1, choice(
$.sequence_operation,
$.comparison_operator,
$.not_operator,
$.boolean_operator,
Expand Down Expand Up @@ -717,6 +718,21 @@ module.exports = grammar({
field('argument', $.primary_expression),
)),

sequence_operation: $ => seq(choice(
$.in_operation,
$.not_in_operation,
$.concatenation,
$.subscript,
$.min,
$.max
)),

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),
repeat1(seq(
Expand Down
257 changes: 257 additions & 0 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,10 @@
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "sequence_operation"
},
{
"type": "SYMBOL",
"name": "comparison_operator"
Expand Down Expand Up @@ -2565,6 +2569,259 @@
]
}
},
"sequence_operation": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "in_operation"
},
{
"type": "SYMBOL",
"name": "not_in_operation"
},
{
"type": "SYMBOL",
"name": "concatenation"
},
{
"type": "SYMBOL",
"name": "subscript"
},
{
"type": "SYMBOL",
"name": "min"
},
{
"type": "SYMBOL",
"name": "max"
}
]
}
]
},
"in_operation": {
"type": "PREC_LEFT",
"value": 3,
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "list_comprehension"
},
{
"type": "SYMBOL",
"name": "dictionary_comprehension"
},
{
"type": "SYMBOL",
"name": "list"
},
{
"type": "SYMBOL",
"name": "dictionary"
}
]
},
{
"type": "STRING",
"value": "in"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "list_comprehension"
},
{
"type": "SYMBOL",
"name": "dictionary_comprehension"
},
{
"type": "SYMBOL",
"name": "list"
},
{
"type": "SYMBOL",
"name": "dictionary"
}
]
}
]
}
},
"not_in_operation": {
"type": "PREC_LEFT",
"value": 11,
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "list_comprehension"
},
{
"type": "SYMBOL",
"name": "dictionary_comprehension"
},
{
"type": "SYMBOL",
"name": "list"
},
{
"type": "SYMBOL",
"name": "dictionary"
}
]
},
{
"type": "STRING",
"value": "not"
},
{
"type": "STRING",
"value": "in"
},
{
"type": "SYMBOL",
"name": "expression"
}
]
}
},
"concatenation": {
"type": "PREC_LEFT",
"value": 12,
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "list_comprehension"
},
{
"type": "SYMBOL",
"name": "dictionary_comprehension"
},
{
"type": "SYMBOL",
"name": "list"
},
{
"type": "SYMBOL",
"name": "dictionary"
}
]
},
{
"type": "STRING",
"value": "+"
},
{
"type": "SYMBOL",
"name": "expression"
}
]
}
},
"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 Down
Loading

0 comments on commit 2b2f646

Please sign in to comment.