Skip to content

Commit

Permalink
Another pattern fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TimWhiting committed May 23, 2023
1 parent 6924019 commit 1a525ed
Show file tree
Hide file tree
Showing 7 changed files with 94,010 additions and 91,513 deletions.
44 changes: 38 additions & 6 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ module.exports = grammar({
[$.record_type_field, $._var_or_type, $._final_var_or_type, $._function_formal_parameter],
[$._var_or_type, $._final_var_or_type],
[$._final_const_var_or_type, $._final_var_or_type],
[$._var_or_type, $._for_loop_parts, $.pattern_variable_declaration],
[$.pattern_variable_declaration, $._for_loop_parts, $._final_const_var_or_type],
[$._var_or_type, $._final_var_or_type, $._function_formal_parameter],
[$.set_or_map_literal, $.map_pattern],
[$.list_literal, $.list_pattern],
Expand Down Expand Up @@ -813,12 +815,12 @@ module.exports = grammar({

logical_or_expression: $ => prec.left( //left
DART_PREC.Logical_OR,
sep2($._real_expression, '||')
sep2($._real_expression, $.logical_or_operator)
),

logical_and_expression: $ => prec.left( //left
DART_PREC.Logical_AND,
sep2($._real_expression, '&&')
sep2($._real_expression, $.logical_and_operator)
),

equality_expression: $ => prec( //neither
Expand Down Expand Up @@ -1314,10 +1316,16 @@ module.exports = grammar({
),

_pattern: $ => choice(
seq($._pattern, '||', $._pattern),
seq($._pattern, '&&', $._pattern),
seq(choice($.relational_operator, $.equality_operator), $.bitwise_or_expression),
$._unary_pattern,
$._logical_or_pattern,
),

_logical_or_pattern: $ => seq($._logical_and_pattern, repeat(seq($.logical_or_operator, $._logical_and_pattern))),
_logical_and_pattern: $ => seq($._relational_pattern, repeat(seq($.logical_and_operator, $._relational_pattern))),
_relational_pattern: $ =>
prec(DART_PREC.Relational, choice(
seq(choice($.relational_operator, $.equality_operator), $._real_expression),
$._unary_pattern,
)
),

_unary_pattern: $ => choice(
Expand Down Expand Up @@ -1531,6 +1539,12 @@ module.exports = grammar({
),),
field('condition', optional($._expression)), $._semicolon,
commaSep(field('update', $._expression)),
),
seq(
choice($.final_builtin, $.inferred_type),
$._outer_pattern,
'in',
field('value', $._expression)
)
),

Expand Down Expand Up @@ -2785,6 +2799,14 @@ module.exports = grammar({
DART_PREC.BUILTIN,
'new',
),
logical_and_operator: $ => prec(
DART_PREC.BUILTIN,
'&&',
),
logical_or_operator: $ => prec(
DART_PREC.BUILTIN,
'||'
),
const_builtin: $ => token('const'),
final_builtin: $ => token('final'),
_late_builtin: $ => prec(
Expand Down Expand Up @@ -2869,6 +2891,16 @@ function commaSepTrailingComma(rule) {
return optional(commaSep1TrailingComma(rule))
}

function pureBinaryRun(rule, separator, precedence){
return prec.left(
precedence,
choice(
sep2(
rule,
separator
)))
}

function binaryRunLeft(rule, separator, superItem, precedence) {
return prec.left( //left
precedence,
Expand Down
203 changes: 146 additions & 57 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -2397,8 +2397,8 @@
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "||"
"type": "SYMBOL",
"name": "logical_or_operator"
},
{
"type": "SYMBOL",
Expand Down Expand Up @@ -2426,8 +2426,8 @@
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "&&"
"type": "SYMBOL",
"name": "logical_and_operator"
},
{
"type": "SYMBOL",
Expand Down Expand Up @@ -4427,67 +4427,96 @@
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_pattern"
},
{
"type": "STRING",
"value": "||"
},
{
"type": "SYMBOL",
"name": "_pattern"
}
]
},
"type": "SYMBOL",
"name": "_logical_or_pattern"
}
]
},
"_logical_or_pattern": {
"type": "SEQ",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_pattern"
},
{
"type": "STRING",
"value": "&&"
},
{
"type": "SYMBOL",
"name": "_pattern"
}
]
"type": "SYMBOL",
"name": "_logical_and_pattern"
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "relational_operator"
},
{
"type": "SYMBOL",
"name": "equality_operator"
}
]
},
{
"type": "SYMBOL",
"name": "bitwise_or_expression"
}
]
},
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "logical_or_operator"
},
{
"type": "SYMBOL",
"name": "_logical_and_pattern"
}
]
}
}
]
},
"_logical_and_pattern": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_unary_pattern"
"name": "_relational_pattern"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "logical_and_operator"
},
{
"type": "SYMBOL",
"name": "_relational_pattern"
}
]
}
}
]
},
"_relational_pattern": {
"type": "PREC",
"value": 8,
"content": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "relational_operator"
},
{
"type": "SYMBOL",
"name": "equality_operator"
}
]
},
{
"type": "SYMBOL",
"name": "_real_expression"
}
]
},
{
"type": "SYMBOL",
"name": "_unary_pattern"
}
]
}
},
"_unary_pattern": {
"type": "CHOICE",
"members": [
Expand Down Expand Up @@ -6221,6 +6250,40 @@
]
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "final_builtin"
},
{
"type": "SYMBOL",
"name": "inferred_type"
}
]
},
{
"type": "SYMBOL",
"name": "_outer_pattern"
},
{
"type": "STRING",
"value": "in"
},
{
"type": "FIELD",
"name": "value",
"content": {
"type": "SYMBOL",
"name": "_expression"
}
}
]
}
]
},
Expand Down Expand Up @@ -11868,6 +11931,22 @@
"value": "new"
}
},
"logical_and_operator": {
"type": "PREC",
"value": 0,
"content": {
"type": "STRING",
"value": "&&"
}
},
"logical_or_operator": {
"type": "PREC",
"value": 0,
"content": {
"type": "STRING",
"value": "||"
}
},
"const_builtin": {
"type": "TOKEN",
"content": {
Expand Down Expand Up @@ -12205,6 +12284,16 @@
"_final_const_var_or_type",
"_final_var_or_type"
],
[
"_var_or_type",
"_for_loop_parts",
"pattern_variable_declaration"
],
[
"pattern_variable_declaration",
"_for_loop_parts",
"_final_const_var_or_type"
],
[
"_var_or_type",
"_final_var_or_type",
Expand Down
Loading

0 comments on commit 1a525ed

Please sign in to comment.