Skip to content

Commit

Permalink
Merge pull request #13 from Riley-Kilgore/main
Browse files Browse the repository at this point in the history
Added backpassing and multiple assignment
  • Loading branch information
rvcas authored Jul 26, 2024
2 parents d6465dc + 56f5345 commit aa7ebdd
Show file tree
Hide file tree
Showing 5 changed files with 39,205 additions and 24,366 deletions.
43 changes: 39 additions & 4 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = grammar({
repeat(
choice($._definition, $.module_comment, $.definition_comment, $.comment)
),
extras: ($) => choice($.type_struct_inner),
extras: ($) => choice($.type_struct_inner, $.any_comment),
_definition: ($) =>
choice(
$.import,
Expand Down Expand Up @@ -200,7 +200,8 @@ module.exports = grammar({
$.error_term,
prec(2, $.unary_op),
$.unary_expect,
$.logical_op_chain
$.logical_op_chain,
$.todo
),
optional(seq("as ", $.identifier))
)
Expand All @@ -226,7 +227,18 @@ module.exports = grammar({
if: ($) =>
seq(
"if",
$.expression,
choice($.expression, $.soft_cast),
block(repeat($.expression)),
optional(seq("else", choice($.if, block(repeat($.expression)))))
),
// Soft-Casting
// if identifier is type_definition { ... } else { ...}
soft_cast: ($) =>
seq(
"if",
$.identifier,
"is",
$.type_definition,
block(repeat($.expression)),
optional(seq("else", choice($.if, block(repeat($.expression)))))
),
Expand Down Expand Up @@ -273,12 +285,33 @@ module.exports = grammar({
),

unary_expect: ($) => prec.right(seq("expect", $.expression)),
assignment: ($) => choice($.let_assignment, $.expect_assignment),
assignment: ($) =>
choice($.let_assignment, $.expect_assignment, $.backpass_assignment),

backpass_assignment: ($) =>
prec.right(
seq(
choice("let", "expect"),
choice(
repeat_separated_by(choice($.identifier, $.discard), ","),
$.match_pattern,
$.list,
$.tuple,
$.pair,
$.identifier,
$.discard
),
"<-",
$.expression
)
),

let_assignment: ($) =>
prec.right(
seq(
"let",
choice(
repeat_separated_by(choice($.identifier, $.discard), ","),
$.match_pattern,
$.list,
$.tuple,
Expand All @@ -296,6 +329,7 @@ module.exports = grammar({
seq(
"expect",
choice(
repeat_separated_by(choice($.identifier, $.discard), ","),
$.match_pattern,
$.list,
$.tuple,
Expand Down Expand Up @@ -388,6 +422,7 @@ module.exports = grammar({
$.int,
$.string,
$.bytes,
$.bytearray_literal,
$.bool,
$.list,
$.tuple,
Expand Down
31 changes: 31 additions & 0 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
(function) @function
(type_alias) @type
(type_enum) @type
(type_struct) @type
(constant) @constant
(validator) @function.special
(test) @function.test
(identifier) @variable
(type_identifier) @type
(string) @string
(int) @number
(bytes) @string.special
(any_comment) @comment
(comment) @comment
"use" @keyword
"pub" @keyword
"opaque" @keyword
"type" @keyword
"fn" @keyword
"validator" @keyword
"test" @keyword
"let" @keyword
"expect" @keyword
"when" @keyword
"is" @keyword
"if" @keyword
"else" @keyword
"trace" @keyword
"fail" @keyword
"as" @keyword
["!" "-" "+" "*" "/" "%" "==" "!=" "<" "<=" ">" ">=" "&&" "||" "|>" "->"] @operator
Loading

0 comments on commit aa7ebdd

Please sign in to comment.