Skip to content

Commit

Permalink
Apply hack
Browse files Browse the repository at this point in the history
  • Loading branch information
theHamsta committed Dec 4, 2021
1 parent 2e38411 commit d253bb8
Show file tree
Hide file tree
Showing 5 changed files with 48,028 additions and 28,058 deletions.
30 changes: 18 additions & 12 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ module.exports = grammar({
[$.list, $.list_pattern],
[$.with_item, $._collection_elements],
[$.named_expression, $.as_pattern],
[$.primary_expression, $.concatenated_string],
[$.concatenated_string],
],

supertypes: $ => [
Expand Down Expand Up @@ -75,6 +77,7 @@ module.exports = grammar({

_statement: $ => choice(
$._simple_statements,
$._maybe_match_statement,
$._compound_statement
),

Expand Down Expand Up @@ -223,14 +226,13 @@ module.exports = grammar({

_compound_statement: $ => choice(
$.if_statement,
$.match_statement,
$.for_statement,
$.while_statement,
$.try_statement,
$.with_statement,
$.function_definition,
$.class_definition,
$.decorated_definition
$.decorated_definition,
),

if_statement: $ => seq(
Expand All @@ -255,12 +257,16 @@ module.exports = grammar({
field('body', $._suite)
),

match_statement: $ => seq(
'match',
field('subject', $.expression),
':',
repeat(field('alternative', $.case_clause)),
),
_maybe_match_statement: $ => seq(
choice($.match_statement,
alias(seq(alias("match", $.identifier),
choice(
seq('=', field('right', $._right_hand_side)),
seq(':', field('type', $.type)),
seq(':', field('type', $.type), '=', field('right', $._right_hand_side))
)), $.assignment))),

match_statement: $ => seq('match', field('subject', $.expression), ':', repeat(field('alternative', $.case_clause))),

case_clause: $ => seq(
'case',
Expand Down Expand Up @@ -652,8 +658,8 @@ module.exports = grammar({
'is',
seq('is', 'not')
)),
$.primary_expression
))
$.primary_expression
))
)),

lambda: $ => prec(PREC.lambda, seq(
Expand Down Expand Up @@ -990,10 +996,10 @@ module.exports = grammar({
}
})

function commaSep1 (rule) {
function commaSep1(rule) {
return sep1(rule, ',')
}

function sep1 (rule, separator) {
function sep1(rule, separator) {
return seq(rule, repeat(seq(separator, rule)))
}
111 changes: 107 additions & 4 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
"type": "SYMBOL",
"name": "_simple_statements"
},
{
"type": "SYMBOL",
"name": "_maybe_match_statement"
},
{
"type": "SYMBOL",
"name": "_compound_statement"
Expand Down Expand Up @@ -745,10 +749,6 @@
"type": "SYMBOL",
"name": "if_statement"
},
{
"type": "SYMBOL",
"name": "match_statement"
},
{
"type": "SYMBOL",
"name": "for_statement"
Expand Down Expand Up @@ -885,6 +885,102 @@
}
]
},
"_maybe_match_statement": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "match_statement"
},
{
"type": "ALIAS",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "="
},
{
"type": "FIELD",
"name": "right",
"content": {
"type": "SYMBOL",
"name": "_right_hand_side"
}
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "type"
}
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "type",
"content": {
"type": "SYMBOL",
"name": "type"
}
},
{
"type": "STRING",
"value": "="
},
{
"type": "FIELD",
"name": "right",
"content": {
"type": "SYMBOL",
"name": "_right_hand_side"
}
}
]
}
]
}
]
},
"named": true,
"value": "assignment"
}
]
}
]
},
"match_statement": {
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -4983,6 +5079,13 @@
[
"named_expression",
"as_pattern"
],
[
"primary_expression",
"concatenated_string"
],
[
"concatenated_string"
]
],
"precedences": [],
Expand Down
28 changes: 24 additions & 4 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
"type": "if_statement",
"named": true
},
{
"type": "match_statement",
"named": true
},
{
"type": "try_statement",
"named": true
Expand Down Expand Up @@ -698,6 +694,18 @@
{
"type": "_simple_statement",
"named": true
},
{
"type": "assignment",
"named": true
},
{
"type": "augmented_assignment",
"named": true
},
{
"type": "match_statement",
"named": true
}
]
}
Expand Down Expand Up @@ -1881,6 +1889,18 @@
{
"type": "_simple_statement",
"named": true
},
{
"type": "assignment",
"named": true
},
{
"type": "augmented_assignment",
"named": true
},
{
"type": "match_statement",
"named": true
}
]
}
Expand Down
Loading

0 comments on commit d253bb8

Please sign in to comment.