Skip to content

Commit

Permalink
add old match pattern syntax
Browse files Browse the repository at this point in the history
It is still supported and used in the Fennel compiler
  • Loading branch information
otommod committed Aug 29, 2021
1 parent 9ab6464 commit f57cc57
Show file tree
Hide file tree
Showing 5 changed files with 7,507 additions and 6,238 deletions.
11 changes: 10 additions & 1 deletion grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,22 @@ module.exports = grammar({
_pattern: $ => choice(
$._simple_pattern,
$.where_pattern,
$.guard_pattern,
),

_simple_pattern: $ => choice(
$.multi_value_pattern,
$._non_multi_value_pattern,
),

guard_pattern: $ => seq(
'(',
$._simple_pattern,
'?',
field('guard', repeat1($._sexp)),
')',
),

where_pattern: $ => seq(
'(',
'where',
Expand All @@ -294,7 +303,7 @@ module.exports = grammar({
')',
),
),
optional($._sexp),
field('guard', repeat($._sexp)),
')',
),

Expand Down
49 changes: 42 additions & 7 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,10 @@
{
"type": "SYMBOL",
"name": "where_pattern"
},
{
"type": "SYMBOL",
"name": "guard_pattern"
}
]
},
Expand All @@ -904,6 +908,38 @@
}
]
},
"guard_pattern": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "_simple_pattern"
},
{
"type": "STRING",
"value": "?"
},
{
"type": "FIELD",
"name": "guard",
"content": {
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "_sexp"
}
}
},
{
"type": "STRING",
"value": ")"
}
]
},
"where_pattern": {
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -949,16 +985,15 @@
]
},
{
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "guard",
"content": {
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_sexp"
},
{
"type": "BLANK"
}
]
}
},
{
"type": "STRING",
Expand Down
Loading

0 comments on commit f57cc57

Please sign in to comment.