Cover five missing language constructs identified from comparison with
the existing tree-sitter-rune crate by zhuhaow:
- impl_item: impl blocks with optional name and visibility
- const_item: const declarations with visibility support
- try_expression: postfix ? operator at precedence 13
- loop_label/label: 'name: labels on loop/while/for, referenced in
break/continue
- object_pattern/object_pattern_entry: #{ key: pat } destructuring in
match with shorthand, string keys, and rest patterns
All 55 tests pass (28 existing + 27 new).
147 lines
3.1 KiB
Plaintext
147 lines
3.1 KiB
Plaintext
==================
|
|
Simple object pattern
|
|
==================
|
|
|
|
fn main() {
|
|
match value {
|
|
#{ name, age } => true,
|
|
}
|
|
}
|
|
|
|
---
|
|
|
|
(source_file
|
|
(function_item
|
|
name: (identifier)
|
|
parameters: (parameters)
|
|
body: (block
|
|
(expression_statement
|
|
(match_expression
|
|
value: (identifier)
|
|
body: (match_block
|
|
(match_arm
|
|
pattern: (match_pattern
|
|
(object_pattern
|
|
(object_pattern_entry
|
|
name: (shorthand_field_identifier))
|
|
(object_pattern_entry
|
|
name: (shorthand_field_identifier))))
|
|
value: (boolean_literal))))))))
|
|
|
|
==================
|
|
Object pattern with binding
|
|
==================
|
|
|
|
fn main() {
|
|
match value {
|
|
#{ name: n, age: a } => true,
|
|
}
|
|
}
|
|
|
|
---
|
|
|
|
(source_file
|
|
(function_item
|
|
name: (identifier)
|
|
parameters: (parameters)
|
|
body: (block
|
|
(expression_statement
|
|
(match_expression
|
|
value: (identifier)
|
|
body: (match_block
|
|
(match_arm
|
|
pattern: (match_pattern
|
|
(object_pattern
|
|
(object_pattern_entry
|
|
key: (field_identifier)
|
|
pattern: (identifier))
|
|
(object_pattern_entry
|
|
key: (field_identifier)
|
|
pattern: (identifier))))
|
|
value: (boolean_literal))))))))
|
|
|
|
==================
|
|
Object pattern with rest
|
|
==================
|
|
|
|
fn main() {
|
|
match value {
|
|
#{ name, .. } => true,
|
|
}
|
|
}
|
|
|
|
---
|
|
|
|
(source_file
|
|
(function_item
|
|
name: (identifier)
|
|
parameters: (parameters)
|
|
body: (block
|
|
(expression_statement
|
|
(match_expression
|
|
value: (identifier)
|
|
body: (match_block
|
|
(match_arm
|
|
pattern: (match_pattern
|
|
(object_pattern
|
|
(object_pattern_entry
|
|
name: (shorthand_field_identifier))
|
|
(remaining_field_pattern)))
|
|
value: (boolean_literal))))))))
|
|
|
|
==================
|
|
Empty object pattern
|
|
==================
|
|
|
|
fn main() {
|
|
match value {
|
|
#{ } => true,
|
|
}
|
|
}
|
|
|
|
---
|
|
|
|
(source_file
|
|
(function_item
|
|
name: (identifier)
|
|
parameters: (parameters)
|
|
body: (block
|
|
(expression_statement
|
|
(match_expression
|
|
value: (identifier)
|
|
body: (match_block
|
|
(match_arm
|
|
pattern: (match_pattern
|
|
(object_pattern))
|
|
value: (boolean_literal))))))))
|
|
|
|
==================
|
|
Object pattern with string key
|
|
==================
|
|
|
|
fn main() {
|
|
match value {
|
|
#{ "content-type": ct } => ct,
|
|
}
|
|
}
|
|
|
|
---
|
|
|
|
(source_file
|
|
(function_item
|
|
name: (identifier)
|
|
parameters: (parameters)
|
|
body: (block
|
|
(expression_statement
|
|
(match_expression
|
|
value: (identifier)
|
|
body: (match_block
|
|
(match_arm
|
|
pattern: (match_pattern
|
|
(object_pattern
|
|
(object_pattern_entry
|
|
key: (string_literal
|
|
(string_content))
|
|
pattern: (identifier))))
|
|
value: (identifier))))))))
|