tree-sitter grammar update
This commit is contained in:
@@ -25,6 +25,7 @@ module.exports = grammar({
|
|||||||
conflicts: $ => [
|
conflicts: $ => [
|
||||||
[$.expression, $.qualified_identifier],
|
[$.expression, $.qualified_identifier],
|
||||||
[$.constant_declaration, $.variable_declaration, $.expression],
|
[$.constant_declaration, $.variable_declaration, $.expression],
|
||||||
|
[$.constant_declaration, $.variable_declaration, $.expression, $.qualified_identifier],
|
||||||
[$.function_declaration],
|
[$.function_declaration],
|
||||||
[$.if_statement],
|
[$.if_statement],
|
||||||
[$.enum_literal],
|
[$.enum_literal],
|
||||||
@@ -36,7 +37,6 @@ module.exports = grammar({
|
|||||||
[$.field_initializer, $.expression],
|
[$.field_initializer, $.expression],
|
||||||
[$.tuple_literal],
|
[$.tuple_literal],
|
||||||
[$.capture_list, $.expression],
|
[$.capture_list, $.expression],
|
||||||
[$.for_statement, $.expression],
|
|
||||||
[$.match_capture, $.expression],
|
[$.match_capture, $.expression],
|
||||||
],
|
],
|
||||||
|
|
||||||
@@ -149,7 +149,11 @@ module.exports = grammar({
|
|||||||
),
|
),
|
||||||
|
|
||||||
record_field: $ => choice(
|
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)),
|
field('type', choice($.type, $.struct_type)),
|
||||||
),
|
),
|
||||||
|
|
||||||
@@ -173,7 +177,7 @@ module.exports = grammar({
|
|||||||
parameter: $ => seq(
|
parameter: $ => seq(
|
||||||
optional('$'),
|
optional('$'),
|
||||||
field('name', choice($.identifier, $.sink)),
|
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),
|
field('type', $.type),
|
||||||
),
|
),
|
||||||
|
|
||||||
@@ -189,8 +193,11 @@ module.exports = grammar({
|
|||||||
$.pointer_type,
|
$.pointer_type,
|
||||||
$.array_type,
|
$.array_type,
|
||||||
$.function_type,
|
$.function_type,
|
||||||
|
$.parenthesized_type,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
parenthesized_type: $ => seq('(', repeat($._newline), $.type, repeat($._newline), ')'),
|
||||||
|
|
||||||
named_type: $ => prec.right(seq(
|
named_type: $ => prec.right(seq(
|
||||||
$.qualified_identifier,
|
$.qualified_identifier,
|
||||||
optional($.argument_list),
|
optional($.argument_list),
|
||||||
@@ -233,7 +240,7 @@ module.exports = grammar({
|
|||||||
_type_constant: $ => seq(optional('-'), choice($.integer, $.character)),
|
_type_constant: $ => seq(optional('-'), choice($.integer, $.character)),
|
||||||
|
|
||||||
builtin_type: _ => choice(
|
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',
|
'i8', 'i16', 'i32', 'i64', 'u8', 'u16', 'u32', 'u64',
|
||||||
'isize', 'usize', 'f32', 'f64',
|
'isize', 'usize', 'f32', 'f64',
|
||||||
'c_char', 'c_schar', 'c_uchar', 'c_short', 'c_ushort',
|
'c_char', 'c_schar', 'c_uchar', 'c_short', 'c_ushort',
|
||||||
@@ -365,16 +372,18 @@ module.exports = grammar({
|
|||||||
repeat($._newline),
|
repeat($._newline),
|
||||||
field('iterable', $.expression),
|
field('iterable', $.expression),
|
||||||
repeat($._newline),
|
repeat($._newline),
|
||||||
'|',
|
$._for_capture_bar,
|
||||||
optional('@'),
|
optional('@'),
|
||||||
field('item', $.identifier),
|
field('item', $.identifier),
|
||||||
optional(seq(',', field('index', $.identifier))),
|
optional(seq(',', field('index', $.identifier))),
|
||||||
'|',
|
$._for_capture_bar,
|
||||||
repeat($._newline),
|
repeat($._newline),
|
||||||
optional(seq(field('label', $.identifier), ':', repeat($._newline))),
|
optional(seq(field('label', $.identifier), ':', repeat($._newline))),
|
||||||
field('body', $.block),
|
field('body', $.block),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
_for_capture_bar: _ => token(prec(1, '|')),
|
||||||
|
|
||||||
match_statement: $ => seq(
|
match_statement: $ => seq(
|
||||||
'match',
|
'match',
|
||||||
repeat($._newline),
|
repeat($._newline),
|
||||||
|
|||||||
@@ -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"
|
"name": "_newline"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "$"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "BLANK"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "FIELD",
|
"type": "FIELD",
|
||||||
"name": "name",
|
"name": "name",
|
||||||
@@ -1124,6 +1168,41 @@
|
|||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "function_type"
|
"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",
|
"type": "STRING",
|
||||||
"value": "void"
|
"value": "void"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "type"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "STRING",
|
"type": "STRING",
|
||||||
"value": "anyopaque"
|
"value": "anyopaque"
|
||||||
@@ -2532,8 +2615,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "STRING",
|
"type": "SYMBOL",
|
||||||
"value": "|"
|
"name": "_for_capture_bar"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "CHOICE",
|
"type": "CHOICE",
|
||||||
@@ -2581,8 +2664,8 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "STRING",
|
"type": "SYMBOL",
|
||||||
"value": "|"
|
"name": "_for_capture_bar"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "REPEAT",
|
"type": "REPEAT",
|
||||||
@@ -2633,6 +2716,17 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"_for_capture_bar": {
|
||||||
|
"type": "TOKEN",
|
||||||
|
"content": {
|
||||||
|
"type": "PREC",
|
||||||
|
"value": 1,
|
||||||
|
"content": {
|
||||||
|
"type": "STRING",
|
||||||
|
"value": "|"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"match_statement": {
|
"match_statement": {
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
"members": [
|
"members": [
|
||||||
@@ -4903,6 +4997,12 @@
|
|||||||
"variable_declaration",
|
"variable_declaration",
|
||||||
"expression"
|
"expression"
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
"constant_declaration",
|
||||||
|
"variable_declaration",
|
||||||
|
"expression",
|
||||||
|
"qualified_identifier"
|
||||||
|
],
|
||||||
[
|
[
|
||||||
"function_declaration"
|
"function_declaration"
|
||||||
],
|
],
|
||||||
@@ -4942,10 +5042,6 @@
|
|||||||
"capture_list",
|
"capture_list",
|
||||||
"expression"
|
"expression"
|
||||||
],
|
],
|
||||||
[
|
|
||||||
"for_statement",
|
|
||||||
"expression"
|
|
||||||
],
|
|
||||||
[
|
[
|
||||||
"match_capture",
|
"match_capture",
|
||||||
"expression"
|
"expression"
|
||||||
|
|||||||
@@ -1683,6 +1683,21 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "parenthesized_type",
|
||||||
|
"named": true,
|
||||||
|
"fields": {},
|
||||||
|
"children": {
|
||||||
|
"multiple": false,
|
||||||
|
"required": true,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "type",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "pointer_type",
|
"type": "pointer_type",
|
||||||
"named": true,
|
"named": true,
|
||||||
@@ -1773,6 +1788,16 @@
|
|||||||
"type": "record_field",
|
"type": "record_field",
|
||||||
"named": true,
|
"named": true,
|
||||||
"fields": {
|
"fields": {
|
||||||
|
"default": {
|
||||||
|
"multiple": false,
|
||||||
|
"required": false,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "expression",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"name": {
|
"name": {
|
||||||
"multiple": false,
|
"multiple": false,
|
||||||
"required": false,
|
"required": false,
|
||||||
@@ -2141,6 +2166,10 @@
|
|||||||
"type": "optional_type",
|
"type": "optional_type",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "parenthesized_type",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "pointer_type",
|
"type": "pointer_type",
|
||||||
"named": true
|
"named": true
|
||||||
@@ -2879,6 +2908,10 @@
|
|||||||
"type": "try",
|
"type": "try",
|
||||||
"named": false
|
"named": false
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "type",
|
||||||
|
"named": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "u16",
|
"type": "u16",
|
||||||
"named": false
|
"named": false
|
||||||
|
|||||||
+245850
-213968
File diff suppressed because it is too large
Load Diff
@@ -643,3 +643,86 @@ ops func(value u8, count u8) u8 {
|
|||||||
(identifier))
|
(identifier))
|
||||||
(expression
|
(expression
|
||||||
(integer)))))))))))))
|
(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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user