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 2 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
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)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Put x + y into the binary expression grammar and consider x - y, x * y, and x ** y, etc, as well as their priorities.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In Binary expression I found that it already has x+y, x-y, x*y, x**y
So, Do you want me to add binary_operator inside sequence_operation inplace of concatenation to cover it all

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, you can remove concatenation here.

min: $ => prec.left(13, seq('min', '(', choice($.list_comprehension, $.dictionary_comprehension, $.list, $.dictionary), ')')),
Peefy marked this conversation as resolved.
Show resolved Hide resolved
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
Loading