errdefer and try/defer fix
This commit is contained in:
@@ -278,7 +278,17 @@ module.exports = grammar({
|
||||
break_statement: $ => seq('break', optional(seq(':', field('label', $.identifier)))),
|
||||
continue_statement: $ => seq('continue', optional(seq(':', field('label', $.identifier)))),
|
||||
|
||||
defer_statement: $ => seq('defer', repeat($._newline), field('body', $.statement)),
|
||||
defer_statement: $ => choice(
|
||||
seq('defer', repeat($._newline), field('body', $.statement)),
|
||||
seq(
|
||||
'errdefer',
|
||||
repeat($._newline),
|
||||
optional(seq(field('capture', $.error_capture), repeat($._newline))),
|
||||
field('body', $.statement),
|
||||
),
|
||||
),
|
||||
|
||||
error_capture: $ => seq('|', choice($.identifier, $.sink), '|'),
|
||||
|
||||
labeled_block: $ => seq(
|
||||
field('label', $.identifier),
|
||||
|
||||
@@ -23,6 +23,16 @@
|
||||
(builtin_type) @type.builtin
|
||||
(named_type) @type
|
||||
|
||||
(named_type
|
||||
(qualified_identifier
|
||||
(identifier) @function .)
|
||||
(argument_list))
|
||||
|
||||
(struct_literal
|
||||
type: (qualified_identifier
|
||||
(identifier) @function .)
|
||||
(argument_list))
|
||||
|
||||
(type_declaration name: (identifier) @type)
|
||||
(function_declaration name: (identifier) @function)
|
||||
(parameter name: (identifier) @variable.parameter)
|
||||
@@ -62,6 +72,7 @@
|
||||
"break"
|
||||
"continue"
|
||||
"defer"
|
||||
"errdefer"
|
||||
"yield"
|
||||
"match"
|
||||
"else"
|
||||
@@ -86,6 +97,7 @@
|
||||
"/"
|
||||
"!"
|
||||
"&"
|
||||
"@"
|
||||
"?"
|
||||
"^"
|
||||
".."
|
||||
|
||||
@@ -1855,26 +1855,109 @@
|
||||
]
|
||||
},
|
||||
"defer_statement": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "defer"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_newline"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "body",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "statement"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "errdefer"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_newline"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "capture",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "error_capture"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_newline"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "body",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "statement"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"error_capture": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "defer"
|
||||
"value": "|"
|
||||
},
|
||||
{
|
||||
"type": "REPEAT",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "_newline"
|
||||
}
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "identifier"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "sink"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "FIELD",
|
||||
"name": "body",
|
||||
"content": {
|
||||
"type": "SYMBOL",
|
||||
"name": "statement"
|
||||
}
|
||||
"type": "STRING",
|
||||
"value": "|"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -517,6 +517,16 @@
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"capture": {
|
||||
"multiple": false,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "error_capture",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -629,6 +639,25 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "error_capture",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": false,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "identifier",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "sink",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true,
|
||||
@@ -2471,6 +2500,10 @@
|
||||
"type": "enum",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "errdefer",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "escape_sequence",
|
||||
"named": true
|
||||
|
||||
+112536
-105418
File diff suppressed because it is too large
Load Diff
@@ -95,3 +95,62 @@ sum func(a, b i32) i32 ! Status {
|
||||
(expression
|
||||
(enum_literal
|
||||
(identifier))))))))))))
|
||||
|
||||
==================
|
||||
Errdefer
|
||||
==================
|
||||
|
||||
Failure :: enum { bad }
|
||||
|
||||
work func() i32 ! Failure {
|
||||
errdefer cleanup()
|
||||
errdefer |err| {
|
||||
_ = err
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(type_declaration
|
||||
(identifier)
|
||||
(enum_type
|
||||
(enum_body
|
||||
(enum_member
|
||||
(identifier)))))
|
||||
(function_declaration
|
||||
(identifier)
|
||||
(parameter_list)
|
||||
(type
|
||||
(builtin_type))
|
||||
(type
|
||||
(named_type
|
||||
(qualified_identifier
|
||||
(identifier))))
|
||||
(block
|
||||
(statement
|
||||
(defer_statement
|
||||
(statement
|
||||
(expression_statement
|
||||
(expression
|
||||
(call_expression
|
||||
(expression
|
||||
(identifier))
|
||||
(argument_list)))))))
|
||||
(statement
|
||||
(defer_statement
|
||||
(error_capture
|
||||
(identifier))
|
||||
(statement
|
||||
(block
|
||||
(statement
|
||||
(assignment_statement
|
||||
(expression
|
||||
(sink))
|
||||
(expression
|
||||
(identifier))))))))
|
||||
(statement
|
||||
(return_statement
|
||||
(expression
|
||||
(integer)))))))
|
||||
|
||||
Reference in New Issue
Block a user