favor return over return _ (void return); newline/closing terminates

This commit is contained in:
2026-07-14 19:07:37 +02:00
parent eac5b32738
commit 471896b48a
19 changed files with 92266 additions and 94923 deletions
+3 -5
View File
@@ -262,15 +262,13 @@ module.exports = grammar({
expression_statement: $ => $.expression,
return_statement: $ => seq(
return_statement: $ => prec.right(seq(
'return',
repeat($._newline),
field('value', $._value),
),
optional(field('value', $._value)),
)),
yield_statement: $ => seq(
'yield',
repeat($._newline),
optional(seq(':', field('label', $.identifier))),
field('value', $._value),
),
+26 -28
View File
@@ -1714,28 +1714,33 @@
"name": "expression"
},
"return_statement": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "return"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_newline"
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "return"
},
{
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "value",
"content": {
"type": "SYMBOL",
"name": "_value"
}
},
{
"type": "BLANK"
}
]
}
},
{
"type": "FIELD",
"name": "value",
"content": {
"type": "SYMBOL",
"name": "_value"
}
}
]
]
}
},
"yield_statement": {
"type": "SEQ",
@@ -1744,13 +1749,6 @@
"type": "STRING",
"value": "yield"
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_newline"
}
},
{
"type": "CHOICE",
"members": [
+1 -1
View File
@@ -1667,7 +1667,7 @@
"fields": {
"value": {
"multiple": false,
"required": true,
"required": false,
"types": [
{
"type": "block",
+92004 -94856
View File
File diff suppressed because it is too large Load Diff
@@ -154,3 +154,56 @@ work func() i32 ! Failure {
(return_statement
(expression
(integer)))))))
==================
Bare return and value yield
==================
done func() void {
return
}
inline func() void { return }
choose func() i32 {
result :: { yield 1 }
return result
}
---
(source_file
(function_declaration
(identifier)
(parameter_list)
(type
(builtin_type))
(block
(statement
(return_statement))))
(function_declaration
(identifier)
(parameter_list)
(type
(builtin_type))
(block
(statement
(return_statement))))
(function_declaration
(identifier)
(parameter_list)
(type
(builtin_type))
(block
(statement
(constant_declaration
(identifier)
(block
(statement
(yield_statement
(expression
(integer)))))))
(statement
(return_statement
(expression
(identifier)))))))