tree-sitter grammar update

This commit is contained in:
2026-07-19 01:46:35 +02:00
parent 95f90cc306
commit 2e09864adf
6 changed files with 246106 additions and 213982 deletions
+15 -6
View File
@@ -25,6 +25,7 @@ module.exports = grammar({
conflicts: $ => [
[$.expression, $.qualified_identifier],
[$.constant_declaration, $.variable_declaration, $.expression],
[$.constant_declaration, $.variable_declaration, $.expression, $.qualified_identifier],
[$.function_declaration],
[$.if_statement],
[$.enum_literal],
@@ -36,7 +37,6 @@ module.exports = grammar({
[$.field_initializer, $.expression],
[$.tuple_literal],
[$.capture_list, $.expression],
[$.for_statement, $.expression],
[$.match_capture, $.expression],
],
@@ -149,7 +149,11 @@ module.exports = grammar({
),
record_field: $ => choice(
seq(field('name', $.identifier), field('type', choice($.type, $.struct_type))),
seq(
field('name', $.identifier),
field('type', choice($.type, $.struct_type)),
optional(seq('=', repeat($._newline), field('default', $.expression))),
),
field('type', choice($.type, $.struct_type)),
),
@@ -173,7 +177,7 @@ module.exports = grammar({
parameter: $ => seq(
optional('$'),
field('name', choice($.identifier, $.sink)),
repeat(seq(',', repeat($._newline), field('name', choice($.identifier, $.sink)))),
repeat(seq(',', repeat($._newline), optional('$'), field('name', choice($.identifier, $.sink)))),
field('type', $.type),
),
@@ -189,8 +193,11 @@ module.exports = grammar({
$.pointer_type,
$.array_type,
$.function_type,
$.parenthesized_type,
),
parenthesized_type: $ => seq('(', repeat($._newline), $.type, repeat($._newline), ')'),
named_type: $ => prec.right(seq(
$.qualified_identifier,
optional($.argument_list),
@@ -233,7 +240,7 @@ module.exports = grammar({
_type_constant: $ => seq(optional('-'), choice($.integer, $.character)),
builtin_type: _ => choice(
'void', 'anyopaque', 'bool', 'int', 'uint', 'float', 'range',
'void', 'type', 'anyopaque', 'bool', 'int', 'uint', 'float', 'range',
'i8', 'i16', 'i32', 'i64', 'u8', 'u16', 'u32', 'u64',
'isize', 'usize', 'f32', 'f64',
'c_char', 'c_schar', 'c_uchar', 'c_short', 'c_ushort',
@@ -365,16 +372,18 @@ module.exports = grammar({
repeat($._newline),
field('iterable', $.expression),
repeat($._newline),
'|',
$._for_capture_bar,
optional('@'),
field('item', $.identifier),
optional(seq(',', field('index', $.identifier))),
'|',
$._for_capture_bar,
repeat($._newline),
optional(seq(field('label', $.identifier), ':', repeat($._newline))),
field('body', $.block),
),
_for_capture_bar: _ => token(prec(1, '|')),
match_statement: $ => seq(
'match',
repeat($._newline),
+104 -8
View File
@@ -753,6 +753,38 @@
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "="
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_newline"
}
},
{
"type": "FIELD",
"name": "default",
"content": {
"type": "SYMBOL",
"name": "expression"
}
}
]
},
{
"type": "BLANK"
}
]
}
]
},
@@ -1039,6 +1071,18 @@
"name": "_newline"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "$"
},
{
"type": "BLANK"
}
]
},
{
"type": "FIELD",
"name": "name",
@@ -1124,6 +1168,41 @@
{
"type": "SYMBOL",
"name": "function_type"
},
{
"type": "SYMBOL",
"name": "parenthesized_type"
}
]
},
"parenthesized_type": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_newline"
}
},
{
"type": "SYMBOL",
"name": "type"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_newline"
}
},
{
"type": "STRING",
"value": ")"
}
]
},
@@ -1464,6 +1543,10 @@
"type": "STRING",
"value": "void"
},
{
"type": "STRING",
"value": "type"
},
{
"type": "STRING",
"value": "anyopaque"
@@ -2532,8 +2615,8 @@
}
},
{
"type": "STRING",
"value": "|"
"type": "SYMBOL",
"name": "_for_capture_bar"
},
{
"type": "CHOICE",
@@ -2581,8 +2664,8 @@
]
},
{
"type": "STRING",
"value": "|"
"type": "SYMBOL",
"name": "_for_capture_bar"
},
{
"type": "REPEAT",
@@ -2633,6 +2716,17 @@
}
]
},
"_for_capture_bar": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "STRING",
"value": "|"
}
}
},
"match_statement": {
"type": "SEQ",
"members": [
@@ -4903,6 +4997,12 @@
"variable_declaration",
"expression"
],
[
"constant_declaration",
"variable_declaration",
"expression",
"qualified_identifier"
],
[
"function_declaration"
],
@@ -4942,10 +5042,6 @@
"capture_list",
"expression"
],
[
"for_statement",
"expression"
],
[
"match_capture",
"expression"
+33
View File
@@ -1683,6 +1683,21 @@
]
}
},
{
"type": "parenthesized_type",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": true,
"types": [
{
"type": "type",
"named": true
}
]
}
},
{
"type": "pointer_type",
"named": true,
@@ -1773,6 +1788,16 @@
"type": "record_field",
"named": true,
"fields": {
"default": {
"multiple": false,
"required": false,
"types": [
{
"type": "expression",
"named": true
}
]
},
"name": {
"multiple": false,
"required": false,
@@ -2141,6 +2166,10 @@
"type": "optional_type",
"named": true
},
{
"type": "parenthesized_type",
"named": true
},
{
"type": "pointer_type",
"named": true
@@ -2879,6 +2908,10 @@
"type": "try",
"named": false
},
{
"type": "type",
"named": false
},
{
"type": "u16",
"named": false
+245850 -213968
View File
File diff suppressed because it is too large Load Diff
@@ -643,3 +643,86 @@ ops func(value u8, count u8) u8 {
(identifier))
(expression
(integer)))))))))))))
==================
Struct field defaults and grouped types
==================
Config :: struct {
capacity usize = 8
}
work func() void ! (Config | errors.Full) {}
clear func($K, $V type) void {
for 0..entries.len |i| {
entries[i].hash = 0
}
}
---
(source_file
(type_declaration
(identifier)
(struct_type
(record_body
(record_field
(identifier)
(type
(builtin_type))
(expression
(integer))))))
(function_declaration
(identifier)
(parameter_list)
(type
(builtin_type))
(type
(parenthesized_type
(type
(named_type
(qualified_identifier
(identifier)))
(named_type
(qualified_identifier
(identifier)
(identifier))))))
(block))
(function_declaration
(identifier)
(parameter_list
(parameter
(identifier)
(identifier)
(type
(builtin_type))))
(type
(builtin_type))
(block
(statement
(for_statement
(expression
(binary_expression
(expression
(integer))
(expression
(field_expression
(expression
(identifier))
(identifier)))))
(identifier)
(block
(statement
(assignment_statement
(expression
(field_expression
(expression
(index_expression
(expression
(identifier))
(expression
(identifier))))
(identifier)))
(expression
(integer))))))))))
@@ -0,0 +1,21 @@
Config :: struct {
# ^^^^^^ type
capacity usize = 8
# ^^^^^^^^ property
# ^ operator
}
work func() void ! (Config | errors.Full) {}
# ^^^^ keyword
# ^ operator
# ^^^^^^ type
# ^ operator
clear func($K, $V type) void {
# ^ variable.parameter
# ^ variable.parameter
# ^^^^ type.builtin
for 0..entries.len |i| {}
# ^^^ keyword
# ^ operator
}