reflection foundation, tuples, debug.print
This commit is contained in:
@@ -30,6 +30,9 @@ module.exports = grammar({
|
||||
[$.array_type, $.expression],
|
||||
[$.array_type, $.array_literal],
|
||||
[$.expression_statement, $.parenthesized_expression],
|
||||
[$.block, $.tuple_literal],
|
||||
[$.field_initializer, $.expression],
|
||||
[$.tuple_literal],
|
||||
],
|
||||
|
||||
rules: {
|
||||
@@ -124,8 +127,8 @@ module.exports = grammar({
|
||||
'}',
|
||||
),
|
||||
|
||||
record_field: $ => seq(
|
||||
field('name', $.identifier),
|
||||
record_field: $ => choice(
|
||||
seq(field('name', $.identifier), field('type', choice($.type, $.struct_type))),
|
||||
field('type', choice($.type, $.struct_type)),
|
||||
),
|
||||
|
||||
@@ -336,6 +339,7 @@ module.exports = grammar({
|
||||
),
|
||||
|
||||
for_statement: $ => seq(
|
||||
optional('inline'),
|
||||
'for',
|
||||
repeat($._newline),
|
||||
field('iterable', $.expression),
|
||||
@@ -393,6 +397,7 @@ module.exports = grammar({
|
||||
$.slice_expression,
|
||||
$.postfix_expression,
|
||||
$.struct_literal,
|
||||
$.tuple_literal,
|
||||
$.comptime_block,
|
||||
$.function_literal,
|
||||
$.struct_type,
|
||||
@@ -442,7 +447,7 @@ module.exports = grammar({
|
||||
field_expression: $ => prec.left(PREC.POSTFIX, seq(
|
||||
field('value', $.expression),
|
||||
'.',
|
||||
field('field', $.identifier),
|
||||
field('field', choice($.identifier, $.integer)),
|
||||
)),
|
||||
|
||||
intrinsic_call_expression: $ => prec(PREC.POSTFIX, seq(
|
||||
@@ -495,8 +500,8 @@ module.exports = grammar({
|
||||
repeat($._newline),
|
||||
seq(
|
||||
repeat($._newline),
|
||||
$.field_initializer,
|
||||
repeat(seq(repeat($._newline), ',', repeat($._newline), $.field_initializer)),
|
||||
choice($.field_initializer, $.expression),
|
||||
repeat(seq(repeat($._newline), ',', repeat($._newline), choice($.field_initializer, $.expression))),
|
||||
optional(seq(repeat($._newline), ',')),
|
||||
repeat($._newline),
|
||||
),
|
||||
@@ -509,6 +514,16 @@ module.exports = grammar({
|
||||
optional(seq('=', repeat($._newline), field('value', $.expression))),
|
||||
),
|
||||
|
||||
tuple_literal: $ => prec(1, choice(
|
||||
seq('{', repeat($._newline), '}'),
|
||||
seq(
|
||||
'{', repeat($._newline), $.expression,
|
||||
',', repeat($._newline),
|
||||
repeat(seq($.expression, ',', repeat($._newline))),
|
||||
optional($.expression), repeat($._newline), '}',
|
||||
),
|
||||
)),
|
||||
|
||||
enum_literal: $ => seq(
|
||||
'.',
|
||||
field('name', $.identifier),
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
(call_expression function: (expression (identifier) @function))
|
||||
(call_expression function: (expression (field_expression field: (identifier) @function)))
|
||||
(field_expression field: (identifier) @property)
|
||||
(field_expression field: (integer) @property)
|
||||
(field_initializer name: (identifier) @property)
|
||||
(keyed_field_initializer name: (identifier) @property)
|
||||
(record_field name: (identifier) @property)
|
||||
@@ -71,6 +72,7 @@
|
||||
"if"
|
||||
"while"
|
||||
"for"
|
||||
"inline"
|
||||
"break"
|
||||
"continue"
|
||||
"defer"
|
||||
|
||||
@@ -656,15 +656,37 @@
|
||||
]
|
||||
},
|
||||
"record_field": {
|
||||
"type": "SEQ",
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "name",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
}
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "name",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "type",
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "type"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "struct_type"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
@@ -2375,6 +2397,18 @@
|
||||
"for_statement": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "inline"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "for"
|
||||
@@ -2768,6 +2802,10 @@
|
||||
"type": "SYMBOL",
|
||||
"name": "struct_literal"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "tuple_literal"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "comptime_block"
|
||||
@@ -3316,8 +3354,17 @@
|
||||
"type": "FIELD",
|
||||
"name": "field",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "integer"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
@@ -3708,8 +3755,17 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "field_initializer"
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "field_initializer"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
@@ -3735,8 +3791,17 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "field_initializer"
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "field_initializer"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -3827,6 +3892,112 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"tuple_literal": {
|
||||
"type": "PREC",
|
||||
"value": 1,
|
||||
"content": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "{"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_newline"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "}"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "{"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_newline"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ","
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_newline"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": ","
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_newline"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "expression"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_newline"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "}"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"enum_literal": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
@@ -4436,6 +4607,17 @@
|
||||
[
|
||||
"expression_statement",
|
||||
"parenthesized_expression"
|
||||
],
|
||||
[
|
||||
"block",
|
||||
"tuple_literal"
|
||||
],
|
||||
[
|
||||
"field_initializer",
|
||||
"expression"
|
||||
],
|
||||
[
|
||||
"tuple_literal"
|
||||
]
|
||||
],
|
||||
"precedences": [],
|
||||
|
||||
@@ -770,6 +770,10 @@
|
||||
"type": "struct_type",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "tuple_literal",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "unary_expression",
|
||||
"named": true
|
||||
@@ -807,6 +811,10 @@
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -1306,6 +1314,10 @@
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "field_initializer",
|
||||
"named": true
|
||||
@@ -1677,7 +1689,7 @@
|
||||
"fields": {
|
||||
"name": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "identifier",
|
||||
@@ -1950,6 +1962,21 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "tuple_literal",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "type",
|
||||
"named": true,
|
||||
@@ -2608,6 +2635,10 @@
|
||||
"type": "import",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "inline",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "int",
|
||||
"named": false
|
||||
|
||||
+123242
-115100
File diff suppressed because it is too large
Load Diff
@@ -277,3 +277,91 @@ choose func() i32 {
|
||||
(return_statement
|
||||
(expression
|
||||
(identifier)))))))
|
||||
|
||||
==================
|
||||
Tuples and inline for
|
||||
==================
|
||||
|
||||
Pair :: struct { i32, []u8 }
|
||||
|
||||
main func() void {
|
||||
pair Pair = Pair {42, "bro"}
|
||||
singleton :: {1,}
|
||||
empty :: {}
|
||||
_ = pair.0
|
||||
inline for singleton |value| {
|
||||
_ = value
|
||||
}
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(type_declaration
|
||||
(identifier)
|
||||
(struct_type
|
||||
(record_body
|
||||
(record_field
|
||||
(type
|
||||
(builtin_type)))
|
||||
(record_field
|
||||
(type
|
||||
(array_type
|
||||
(type
|
||||
(builtin_type))))))))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list)
|
||||
(type
|
||||
(builtin_type))
|
||||
(block
|
||||
(statement
|
||||
(variable_declaration
|
||||
(identifier)
|
||||
(type
|
||||
(named_type
|
||||
(qualified_identifier
|
||||
(identifier))))
|
||||
(expression
|
||||
(struct_literal
|
||||
(qualified_identifier
|
||||
(identifier))
|
||||
(initializer_list
|
||||
(expression
|
||||
(integer))
|
||||
(expression
|
||||
(string
|
||||
(string_content))))))))
|
||||
(statement
|
||||
(constant_declaration
|
||||
(identifier)
|
||||
(expression
|
||||
(tuple_literal
|
||||
(expression
|
||||
(integer))))))
|
||||
(statement
|
||||
(constant_declaration
|
||||
(identifier)
|
||||
(expression
|
||||
(tuple_literal))))
|
||||
(statement
|
||||
(assignment_statement
|
||||
(expression
|
||||
(sink))
|
||||
(expression
|
||||
(field_expression
|
||||
(expression
|
||||
(identifier))
|
||||
(integer)))))
|
||||
(statement
|
||||
(for_statement
|
||||
(expression
|
||||
(identifier))
|
||||
(identifier)
|
||||
(block
|
||||
(statement
|
||||
(assignment_statement
|
||||
(expression
|
||||
(sink))
|
||||
(expression
|
||||
(identifier))))))))))
|
||||
|
||||
Reference in New Issue
Block a user