more tree-sitter-y and await expr

This commit is contained in:
2025-09-21 13:34:55 +02:00
parent dcc8500e2c
commit e3ec5fee64
4 changed files with 31084 additions and 27201 deletions

View File

@@ -12,7 +12,7 @@ module.exports = grammar({
reserved: {
toplevel_kw: $ =>
['type', 'with', 'extensible', 'extend', 'union', 'def'],
['type', 'with', 'extensible', 'extend', 'union', 'def', 'await', 'if', 'then', 'else', 'in', 'match'],
},
extras: ($) => [
@@ -24,6 +24,7 @@ module.exports = grammar({
precedences: _ => [
[
"ident",
"exponent",
"multiplication",
"negate",
@@ -35,12 +36,13 @@ module.exports = grammar({
"let",
"new_match_arm",
"match_arm",
"await",
"tag",
],
],
conflicts: $ => [
[$.match_expr, $.match_expr],
[$.match_expr, $.match_expr], // TODO
],
rules: {
@@ -172,8 +174,8 @@ module.exports = grammar({
list_expression: $ =>
seq(
'[',
repeat(seq($.expression, ',')),
optional($.expression),
repeat(seq($._expression, ',')),
optional($._expression),
']'),
field_access: $ => prec.left(
@@ -181,13 +183,14 @@ module.exports = grammar({
function_call: $ => prec.left(1,
seq($._atom, '(',
repeat(seq($.expression, ',')), optional($.expression),
repeat(seq($._expression, ',')), optional($._expression),
')')),
ident_expr: $ => $.identifier,
ident_expr: $ => prec("ident",
$.path),
record_expr_field: $ =>
seq($.identifier, ':', $.expression),
seq($.identifier, ':', $._expression),
record_expr: $ => seq(
'{',
@@ -196,7 +199,7 @@ module.exports = grammar({
'}'),
_atom: $ => choice(
prec(0, seq('(', $.expression, ')')),
prec(0, seq('(', $._expression, ')')),
$.ident_expr,
$.char_literal,
$.string_literal,
@@ -209,86 +212,90 @@ module.exports = grammar({
let_binding: $ => prec("let", seq(
'let',
$.identifier,
field('name', $.identifier),
'=',
$.expression,
field('value', $._expression),
optional('in'),
$.expression,
field('body', $._expression),
)),
await_binding: $ => prec("let", seq(
'await',
$.identifier,
field('name', $.identifier),
'=',
$.expression,
field('value', $._expression),
optional('in'),
$.expression,
field('body', $._expression),
)),
type_downcast: $ => seq(
$._atom,
field('expr', $._atom),
'::',
$._type,
field('as', $._type),
),
lambda: $ => prec.right(4, seq(
$.identifier,
optional(seq(':', $._type_non_fn)),
field('arg', $.identifier),
optional(seq(':', field('arg_type', $._type_non_fn))),
'->',
$.expression
field('body', $._expression)
)),
with_expr: $ => prec.left("with",
seq($.expression, 'with', $._atom)),
seq($._expression, 'with', $._atom)),
and_expr: $ => prec.left("with",
seq($.expression, 'and', $._atom)),
seq($._expression, 'and', $._atom)),
if_expr: $ => prec("if",
seq('if', $.expression, 'then', $.expression, 'else', $.expression)),
seq('if', $._expression, 'then', $._expression, 'else', $._expression)),
sub_expr: $ => prec.left("addition",
seq($.expression, '-', $.expression)),
seq($._expression, '-', $._expression)),
add_expr: $ => prec.left("addition",
seq($.expression, '+', $.expression)),
seq($._expression, '+', $._expression)),
divide_expr: $ => prec.left("multiplication",
seq($.expression, '/', $.expression)),
seq($._expression, '/', $._expression)),
multiply_expr: $ => prec.left("multiplication",
seq($.expression, '*', $.expression)),
seq($._expression, '*', $._expression)),
equal_expr: $ => prec.left("equal",
seq($.expression, '=', $.expression)),
seq($._expression, '=', $._expression)),
concat_expr: $ => prec.left("concat",
seq($.expression, '++', $.expression)),
seq($._expression, '++', $._expression)),
compose_expr: $ => prec.left("concat",
seq($.expression, '=>', $.expression)),
seq($._expression, '=>', $._expression)),
exponent_expr: $ => prec.left("exponent",
seq($.expression, '^', $._atom)),
seq($._expression, '^', $._atom)),
match_arm: $ => prec("match_arm",
seq(
field('cases', seq($._atom, repeat(seq('|', $._atom)))),
'->', $.expression)),
'->', $._expression)),
match_expr: $ =>
seq('match', $.expression, 'with',
seq('match', $._expression, 'with',
$.match_arm,
prec("new_match_arm", repeat(seq('|', $.match_arm)))),
negate_expr: $ => prec.right("negate",
seq('-', $.expression)),
seq('-', $._expression)),
tag_expr: $ => prec.right("tag",
seq($.tag, $.expression)),
seq($.tag, $._expression)),
expression: $ => choice(
await_expr: $ => prec.right("await",
seq('await', $._expression)),
_expression: $ => choice(
$._atom,
$.let_binding,
$.await_binding,
$.await_expr,
$.type_downcast,
$.lambda,
$.with_expr,
@@ -309,12 +316,13 @@ module.exports = grammar({
),
def: $ => seq(
'def', $.path,
'def',
field('name', $.path),
choice(
seq(':', $._type),
seq(':', field('signature', $._type)),
seq(
optional(seq(':', $._type)),
seq('=', $.expression),
optional(seq(':', field('signature', $._type))),
seq('=', field('value', $._expression)),
)
),
),

View File

@@ -714,7 +714,7 @@
"members": [
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
},
{
"type": "STRING",
@@ -728,7 +728,7 @@
"members": [
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
},
{
"type": "BLANK"
@@ -783,7 +783,7 @@
"members": [
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
},
{
"type": "STRING",
@@ -797,7 +797,7 @@
"members": [
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
},
{
"type": "BLANK"
@@ -812,8 +812,12 @@
}
},
"ident_expr": {
"type": "PREC",
"value": "ident",
"content": {
"type": "SYMBOL",
"name": "identifier"
"name": "path"
}
},
"record_expr_field": {
"type": "SEQ",
@@ -828,7 +832,7 @@
},
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
}
]
},
@@ -888,7 +892,7 @@
},
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
},
{
"type": "STRING",
@@ -942,16 +946,24 @@
"value": "let"
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "STRING",
"value": "="
},
{
"type": "FIELD",
"name": "value",
"content": {
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
}
},
{
"type": "CHOICE",
@@ -966,8 +978,12 @@
]
},
{
"type": "FIELD",
"name": "body",
"content": {
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
}
}
]
}
@@ -983,16 +999,24 @@
"value": "await"
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "STRING",
"value": "="
},
{
"type": "FIELD",
"name": "value",
"content": {
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
}
},
{
"type": "CHOICE",
@@ -1007,8 +1031,12 @@
]
},
{
"type": "FIELD",
"name": "body",
"content": {
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
}
}
]
}
@@ -1017,17 +1045,25 @@
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "expr",
"content": {
"type": "SYMBOL",
"name": "_atom"
}
},
{
"type": "STRING",
"value": "::"
},
{
"type": "FIELD",
"name": "as",
"content": {
"type": "SYMBOL",
"name": "_type"
}
}
]
},
"lambda": {
@@ -1037,8 +1073,12 @@
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "arg",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "CHOICE",
@@ -1051,9 +1091,13 @@
"value": ":"
},
{
"type": "FIELD",
"name": "arg_type",
"content": {
"type": "SYMBOL",
"name": "_type_non_fn"
}
}
]
},
{
@@ -1066,8 +1110,12 @@
"value": "->"
},
{
"type": "FIELD",
"name": "body",
"content": {
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
}
}
]
}
@@ -1080,7 +1128,7 @@
"members": [
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
},
{
"type": "STRING",
@@ -1101,7 +1149,7 @@
"members": [
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
},
{
"type": "STRING",
@@ -1126,7 +1174,7 @@
},
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
},
{
"type": "STRING",
@@ -1134,7 +1182,7 @@
},
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
},
{
"type": "STRING",
@@ -1142,7 +1190,7 @@
},
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
}
]
}
@@ -1155,7 +1203,7 @@
"members": [
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
},
{
"type": "STRING",
@@ -1163,7 +1211,7 @@
},
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
}
]
}
@@ -1176,7 +1224,7 @@
"members": [
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
},
{
"type": "STRING",
@@ -1184,7 +1232,7 @@
},
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
}
]
}
@@ -1197,7 +1245,7 @@
"members": [
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
},
{
"type": "STRING",
@@ -1205,7 +1253,7 @@
},
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
}
]
}
@@ -1218,7 +1266,7 @@
"members": [
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
},
{
"type": "STRING",
@@ -1226,7 +1274,7 @@
},
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
}
]
}
@@ -1239,7 +1287,7 @@
"members": [
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
},
{
"type": "STRING",
@@ -1247,7 +1295,7 @@
},
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
}
]
}
@@ -1260,7 +1308,7 @@
"members": [
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
},
{
"type": "STRING",
@@ -1268,7 +1316,7 @@
},
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
}
]
}
@@ -1281,7 +1329,7 @@
"members": [
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
},
{
"type": "STRING",
@@ -1289,7 +1337,7 @@
},
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
}
]
}
@@ -1302,7 +1350,7 @@
"members": [
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
},
{
"type": "STRING",
@@ -1356,7 +1404,7 @@
},
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
}
]
}
@@ -1370,7 +1418,7 @@
},
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
},
{
"type": "STRING",
@@ -1414,7 +1462,7 @@
},
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
}
]
}
@@ -1431,12 +1479,29 @@
},
{
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
}
]
}
},
"expression": {
"await_expr": {
"type": "PREC_RIGHT",
"value": "await",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "await"
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
},
"_expression": {
"type": "CHOICE",
"members": [
{
@@ -1451,6 +1516,10 @@
"type": "SYMBOL",
"name": "await_binding"
},
{
"type": "SYMBOL",
"name": "await_expr"
},
{
"type": "SYMBOL",
"name": "type_downcast"
@@ -1525,8 +1594,12 @@
"value": "def"
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "path"
}
},
{
"type": "CHOICE",
@@ -1539,9 +1612,13 @@
"value": ":"
},
{
"type": "FIELD",
"name": "signature",
"content": {
"type": "SYMBOL",
"name": "_type"
}
}
]
},
{
@@ -1558,9 +1635,13 @@
"value": ":"
},
{
"type": "FIELD",
"name": "signature",
"content": {
"type": "SYMBOL",
"name": "_type"
}
}
]
},
{
@@ -1576,8 +1657,12 @@
"value": "="
},
{
"type": "FIELD",
"name": "value",
"content": {
"type": "SYMBOL",
"name": "expression"
"name": "_expression"
}
}
]
}
@@ -1606,6 +1691,10 @@
],
"precedences": [
[
{
"type": "STRING",
"value": "ident"
},
{
"type": "STRING",
"value": "exponent"
@@ -1650,6 +1739,10 @@
"type": "STRING",
"value": "match_arm"
},
{
"type": "STRING",
"value": "await"
},
{
"type": "STRING",
"value": "tag"
@@ -1684,6 +1777,30 @@
{
"type": "STRING",
"value": "def"
},
{
"type": "STRING",
"value": "await"
},
{
"type": "STRING",
"value": "if"
},
{
"type": "STRING",
"value": "then"
},
{
"type": "STRING",
"value": "else"
},
{
"type": "STRING",
"value": "in"
},
{
"type": "STRING",
"value": "match"
}
]
}

File diff suppressed because it is too large Load Diff

54529
tree-sitter/src/parser.c generated

File diff suppressed because it is too large Load Diff