Support some, ok and err wrappers and untyped function inputs

This commit is contained in:
paul committed 2026-10-18 18:18:31 -04:00
1 parent 6e4f9cd65a
commit 79533e9537
20 files changed
+36187 -35406

No files matched your search

+19 -15
View File
@@ -19,8 +19,8 @@ const PREC = {
const RESERVED_WORDS = [
"and", "as", "bits", "break", "continue", "default", "distinct", "else",
"false", "for", "if", "in", "loop", "match", "nil", "not", "or", "pub",
"return", "true", "use",
"err", "false", "for", "if", "in", "loop", "match", "nil", "not", "ok", "or",
"pub", "return", "some", "true", "use",
"bit", "chr", "f32", "f64", "i8", "i16", "i32", "i64", "nvr", "str",
"u8", "u16", "u32", "u64",
];
@@ -55,6 +55,7 @@ module.exports = grammar({
],
conflicts: $ => [
[$.binding_pattern, $.pattern_atom],
[$.product_pattern_field, $.primary_expression],
[$.pattern_atom, $.literal],
[$.pattern_atom, $.primary_expression],
@@ -312,18 +313,16 @@ module.exports = grammar({
prec(1, seq("@", field("body", $.block))),
),
typed_tuple_pattern: $ => seq("(", optional(listBodyAtLeastTwo($, $.typed_tuple_component)), ")"),
typed_tuple_pattern: $ => seq("(", listBodyAtLeastTwo($, $.typed_tuple_component), ")"),
typed_parameter: $ => seq(
typed_parameter: $ => prec.dynamic(1, seq(
field("pattern", $.binding_pattern),
":",
field("type", $._result_type),
),
optional(seq(":", field("type", $._result_type))),
)),
typed_tuple_component: $ => seq(
field("pattern", $.binding_pattern),
":",
field("type", $.type_expression),
optional(seq(":", field("type", $.type_expression))),
),
return_expression: $ => prec.right(seq("return", optional($.expression))),
@@ -385,6 +384,7 @@ module.exports = grammar({
$.character_literal,
$.boolean_literal,
$.nil_literal,
$.wrapper_pattern,
$.sum_pattern,
$.bits_pattern,
$.unit_pattern,
@@ -407,6 +407,11 @@ module.exports = grammar({
optional($.pattern_atom),
),
wrapper_pattern: $ => seq(
field("wrapper", choice("some", "ok", "err")),
field("value", $.pattern_atom),
),
bits_pattern: $ => seq(
"|",
optional($.type_name),
@@ -430,27 +435,27 @@ module.exports = grammar({
seq(
$._direct_pipeline_continuation,
field("callable", $.pipeline_callable),
repeat(choice("?", "!")),
repeat("?"),
),
seq(
$._aggregate_pipeline_continuation,
field("callable", $.aggregate_pipeline_callable),
field("arguments", $.aggregate_tail),
repeat(choice("?", "!")),
repeat("?"),
),
),
direct_pipeline_stage: $ => seq(
"->",
field("callable", $.pipeline_callable),
repeat(choice("?", "!")),
repeat("?"),
),
aggregate_pipeline_stage: $ => seq(
"|>",
field("callable", $.aggregate_pipeline_callable),
field("arguments", $.aggregate_tail),
repeat(choice("?", "!")),
repeat("?"),
),
aggregate_tail: $ => choice(
@@ -524,7 +529,7 @@ module.exports = grammar({
),
unary_expression: $ => prec.right(PREC.PREFIX, seq(
field("operator", choice("not", "!", "-", "~")),
field("operator", choice("not", "-", "~", "some", "ok", "err")),
field("operand", $._prefix_expression),
)),
@@ -534,7 +539,6 @@ module.exports = grammar({
seq(".", field("member", $.identifier)),
seq("[", field("index", $.expression), "]"),
"?",
"!",
))),
)),