Skip to content

Commit e451746

Browse files
Add support for let assert ... as (#107)
1 parent 2702fe8 commit e451746

File tree

2 files changed

+49
-15
lines changed

2 files changed

+49
-15
lines changed

grammar.js

+24-14
Original file line numberDiff line numberDiff line change
@@ -357,23 +357,27 @@ module.exports = grammar({
357357
optional(field("arguments", $.arguments))
358358
),
359359
todo: ($) =>
360-
seq(
361-
"todo",
362-
optional(
363-
choice(
364-
// DEPRECATED: The 'as' syntax was introduced in v0.30.
365-
seq("(", field("message", $.string), ")"),
366-
seq("as", field("message", $._expression))
360+
prec.left(
361+
seq(
362+
"todo",
363+
optional(
364+
choice(
365+
// DEPRECATED: The 'as' syntax was introduced in v0.30.
366+
seq("(", field("message", $.string), ")"),
367+
seq("as", field("message", $._expression))
368+
)
367369
)
368370
)
369371
),
370372
panic: ($) =>
371-
seq(
372-
"panic",
373-
optional(
374-
choice(
375-
seq("(", field("message", $.string), ")"),
376-
seq("as", field("message", $._expression))
373+
prec.left(
374+
seq(
375+
"panic",
376+
optional(
377+
choice(
378+
seq("(", field("message", $.string), ")"),
379+
seq("as", field("message", $._expression))
380+
)
377381
)
378382
)
379383
),
@@ -488,7 +492,13 @@ module.exports = grammar({
488492
),
489493
_case_clause_tuple_access: ($) =>
490494
seq(field("tuple", $.identifier), ".", field("index", $.integer)),
491-
let_assert: ($) => seq("let", "assert", $._assignment),
495+
let_assert: ($) =>
496+
seq(
497+
"let",
498+
"assert",
499+
$._assignment,
500+
optional(seq("as", field("message", $._expression)))
501+
),
492502
let: ($) => seq("let", $._assignment),
493503
use: ($) =>
494504
seq(

test/corpus/functions.txt

+25-1
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ fn assert_assignment() {
277277
}
278278
let assert y = x
279279
let assert #(x, _) = #(1, 2)
280+
let assert Ok(_) = Ok(10) as "This never fails"
281+
let assert 10 = 11 as { "message1" <> "message2" }
280282
}
281283
fn assignment() {
282284
let x = {
@@ -504,7 +506,29 @@ fn field_access(x) {
504506
(discard))
505507
value: (tuple
506508
(integer)
507-
(integer)))))
509+
(integer)))
510+
(let_assert
511+
pattern: (record_pattern
512+
name: (constructor_name)
513+
arguments: (record_pattern_arguments
514+
(record_pattern_argument
515+
pattern: (discard))))
516+
value: (record
517+
name: (constructor_name)
518+
arguments: (arguments
519+
(argument
520+
value: (integer))))
521+
message: (string
522+
(quoted_content)))
523+
(let_assert
524+
pattern: (integer)
525+
value: (integer)
526+
message: (block
527+
(binary_expression
528+
left: (string
529+
(quoted_content))
530+
right: (string
531+
(quoted_content)))))))
508532
(function
509533
name: (identifier)
510534
parameters: (function_parameters)

0 commit comments

Comments
 (0)