Skip to content

Commit

Permalink
Merge pull request #46 from tonyfettes/main
Browse files Browse the repository at this point in the history
suffix ~/?
  • Loading branch information
tonyfettes authored Nov 26, 2024
2 parents de367df + 80adec6 commit 5f88ac4
Show file tree
Hide file tree
Showing 11 changed files with 292 additions and 326 deletions.
46 changes: 19 additions & 27 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const
PREC = {
apply: 19,
access: 18,
unwrap: 18,
unary: 17,
multiplicative: 16,
additive: 15,
Expand Down Expand Up @@ -124,7 +123,7 @@ module.exports = grammar({
$.uppercase_identifier,
optional(seq(
'(',
commaList1(choice($.type, seq($.labeled_identifier, $.colon, $.type))),
commaList1(choice($.type, seq($.parameter_label, $.colon, $.type))),
')'
))
),
Expand Down Expand Up @@ -236,11 +235,6 @@ module.exports = grammar({
$.try_expression,
),

unwrap_expression: $ => prec(PREC.unwrap, seq(
$.simple_expression,
$.question_operator
)),

simple_expression: $ => choice(
$.atomic_expression,
$.qualified_identifier,
Expand All @@ -260,7 +254,6 @@ module.exports = grammar({
$.tuple_expression,
$.constraint_expression,
$.array_expression,
$.unwrap_expression,
'_'
),

Expand Down Expand Up @@ -476,28 +469,27 @@ module.exports = grammar({
),

argument_label: $ => seq(
choice(
$.lowercase_identifier,
$.labeled_identifier,
seq(
$.labeled_identifier,
$.question_operator
)
),
$.simple_expression,
optional($.question_operator),
'='
),

argument_pun: $ => seq(
$.simple_expression,
choice('~', $.question_operator)
),

argument: $ => choice(
seq(
optional($.argument_label),
$.expression
),
$.labeled_identifier
$.argument_pun,
),

apply_expression: $ => prec(PREC.apply, seq(
$.simple_expression,
optional(choice('!', '?')),
optional(choice('!', $.question_operator)),
'(',
commaList($.argument),
')'
Expand Down Expand Up @@ -729,7 +721,7 @@ module.exports = grammar({
seq('(', $.pattern, ')'),
$.literal,
$.lowercase_identifier,
$.labeled_identifier,
$.parameter_label,
$.constructor_pattern,
$.tuple_pattern,
$.constraint_pattern,
Expand Down Expand Up @@ -807,17 +799,19 @@ module.exports = grammar({

return_type: $ => seq('->', $.type, optional(seq('!', optional($.type)))),

parameter_label: $ => choice(
parameter_label: $ => seq(
$.lowercase_identifier,
$.labeled_identifier,
seq(
$.labeled_identifier,
choice(
'~',
$.question_operator
)
),
),

parameter: $ => seq(
$.parameter_label,
choice(
$.parameter_label,
$.lowercase_identifier,
),
optional($.type_annotation),
optional(seq('=', $.expression)),
),
Expand Down Expand Up @@ -851,8 +845,6 @@ module.exports = grammar({

package_identifier: _ => /@[_\p{XID_Start}][_\p{XID_Continue}]*/,

labeled_identifier: $ => /~[_\p{XID_Start}][_\p{XID_Continue}]*/,

qualified_identifier: $ => choice(
$.lowercase_identifier,
seq($.package_identifier, $.dot_identifier)
Expand Down
106 changes: 49 additions & 57 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@
"members": [
{
"type": "SYMBOL",
"name": "labeled_identifier"
"name": "parameter_label"
},
{
"type": "SYMBOL",
Expand Down Expand Up @@ -669,7 +669,7 @@
"members": [
{
"type": "SYMBOL",
"name": "labeled_identifier"
"name": "parameter_label"
},
{
"type": "SYMBOL",
Expand Down Expand Up @@ -1339,23 +1339,6 @@
}
]
},
"unwrap_expression": {
"type": "PREC",
"value": 18,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "simple_expression"
},
{
"type": "SYMBOL",
"name": "question_operator"
}
]
}
},
"simple_expression": {
"type": "CHOICE",
"members": [
Expand Down Expand Up @@ -1431,10 +1414,6 @@
"type": "SYMBOL",
"name": "array_expression"
},
{
"type": "SYMBOL",
"name": "unwrap_expression"
},
{
"type": "STRING",
"value": "_"
Expand Down Expand Up @@ -2668,29 +2647,19 @@
"argument_label": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "simple_expression"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "lowercase_identifier"
},
{
"type": "SYMBOL",
"name": "labeled_identifier"
"name": "question_operator"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "labeled_identifier"
},
{
"type": "SYMBOL",
"name": "question_operator"
}
]
"type": "BLANK"
}
]
},
Expand All @@ -2700,6 +2669,28 @@
}
]
},
"argument_pun": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "simple_expression"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "~"
},
{
"type": "SYMBOL",
"name": "question_operator"
}
]
}
]
},
"argument": {
"type": "CHOICE",
"members": [
Expand All @@ -2726,7 +2717,7 @@
},
{
"type": "SYMBOL",
"name": "labeled_identifier"
"name": "argument_pun"
}
]
},
Expand All @@ -2751,8 +2742,8 @@
"value": "!"
},
{
"type": "STRING",
"value": "?"
"type": "SYMBOL",
"name": "question_operator"
}
]
},
Expand Down Expand Up @@ -4361,7 +4352,7 @@
},
{
"type": "SYMBOL",
"name": "labeled_identifier"
"name": "parameter_label"
},
{
"type": "SYMBOL",
Expand Down Expand Up @@ -5045,22 +5036,18 @@
]
},
"parameter_label": {
"type": "CHOICE",
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "lowercase_identifier"
},
{
"type": "SYMBOL",
"name": "labeled_identifier"
},
{
"type": "SEQ",
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "labeled_identifier"
"type": "STRING",
"value": "~"
},
{
"type": "SYMBOL",
Expand All @@ -5074,8 +5061,17 @@
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "parameter_label"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "parameter_label"
},
{
"type": "SYMBOL",
"name": "lowercase_identifier"
}
]
},
{
"type": "CHOICE",
Expand Down Expand Up @@ -5232,10 +5228,6 @@
"type": "PATTERN",
"value": "@[_\\p{XID_Start}][_\\p{XID_Continue}]*"
},
"labeled_identifier": {
"type": "PATTERN",
"value": "~[_\\p{XID_Start}][_\\p{XID_Continue}]*"
},
"qualified_identifier": {
"type": "CHOICE",
"members": [
Expand Down
Loading

0 comments on commit 5f88ac4

Please sign in to comment.