Skip to content

Commit

Permalink
Correctly parse \cases expressions (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
crumb authored Dec 12, 2023
1 parent ca10c43 commit 651a75e
Show file tree
Hide file tree
Showing 5 changed files with 536,489 additions and 491,150 deletions.
12 changes: 12 additions & 0 deletions grammar/exp.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,10 @@ module.exports = {
),

alt: $ => seq($._pat, $._alt_variants, optional(seq($.where, optional($.decls)))),
nalt: $ => seq(repeat1($._apat), $._alt_variants, optional(seq($.where, optional($.decls)))),

alts: $ => layouted($, $.alt),
nalts: $ => layouted($, $.nalt),

exp_case: $ => seq('case', $._exp, 'of', optional($.alts)),

Expand All @@ -194,6 +196,15 @@ module.exports = {
optional($.alts),
),

/**
* alts are NOT optional in a \cases expression
*/
exp_lambda_cases: $ => seq(
'\\',
'cases',
$.nalts,
),

rec: $ => seq(
'rec',
layouted($, $.stmt),
Expand Down Expand Up @@ -293,6 +304,7 @@ module.exports = {
$._aexp_projection,
$.exp_type_application,
$.exp_lambda_case,
$.exp_lambda_cases,
$.exp_do,
$.exp_projection,
),
Expand Down
2 changes: 2 additions & 0 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
"of"
] @conditional

(exp_lambda_cases "\\" ("cases" @conditional))

[
"import"
"qualified"
Expand Down
229 changes: 229 additions & 0 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -4317,6 +4317,51 @@
}
]
},
"nalt": {
"type": "SEQ",
"members": [
{
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "_apat"
}
},
{
"type": "SYMBOL",
"name": "_alt_variants"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "where"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "decls"
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
}
]
},
"alts": {
"type": "CHOICE",
"members": [
Expand Down Expand Up @@ -4480,6 +4525,169 @@
}
]
},
"nalts": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ";"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "nalt"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "REPEAT1",
"content": {
"type": "STRING",
"value": ";"
}
},
{
"type": "SYMBOL",
"name": "nalt"
}
]
}
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ";"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "}"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_layout_start"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "nalt"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "PREC_DYNAMIC",
"value": 1,
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ";"
},
{
"type": "SYMBOL",
"name": "_layout_semicolon"
}
]
}
},
{
"type": "SYMBOL",
"name": "nalt"
}
]
}
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": ";"
},
{
"type": "SYMBOL",
"name": "_layout_semicolon"
}
]
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "_layout_end"
}
]
}
]
},
"exp_case": {
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -4534,6 +4742,23 @@
}
]
},
"exp_lambda_cases": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\\"
},
{
"type": "STRING",
"value": "cases"
},
{
"type": "SYMBOL",
"name": "nalts"
}
]
},
"rec": {
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -5179,6 +5404,10 @@
"type": "SYMBOL",
"name": "exp_lambda_case"
},
{
"type": "SYMBOL",
"name": "exp_lambda_cases"
},
{
"type": "SYMBOL",
"name": "exp_do"
Expand Down
Loading

0 comments on commit 651a75e

Please sign in to comment.