Skip to content

Commit

Permalink
feat(grammar): add range"
Browse files Browse the repository at this point in the history
  • Loading branch information
0xLucqs committed Sep 19, 2024
1 parent d5733e0 commit 7a23666
Show file tree
Hide file tree
Showing 4 changed files with 42,160 additions and 40,431 deletions.
20 changes: 18 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const PREC = {
comparative: 4,
and: 3,
or: 2,
range: 1,
assign: 0,
closure: -1,
};
Expand Down Expand Up @@ -95,6 +96,7 @@ module.exports = grammar({
],
supertypes: ($) => [
$.expression,
$.expression_except_range,
$._type,
$._literal,
$._literal_pattern,
Expand Down Expand Up @@ -780,7 +782,13 @@ module.exports = grammar({
expression_statement: ($) =>
choice(seq($.expression, ';'), prec(1, $._expression_ending_with_block)),

expression: ($) =>

expression: $ => choice(
$.expression_except_range,
$.range_expression,
),

expression_except_range: ($) =>
choice(
prec.left($.identifier),
alias(choice(...primitiveTypes), $.identifier),
Expand Down Expand Up @@ -918,6 +926,14 @@ module.exports = grammar({
unary_expression: ($) =>
prec(PREC.unary, seq(choice('-', '*', '!', '~', '@'), $.expression)),

range_expression: $ => prec.left(PREC.range, choice(
seq($.expression, '..', $.expression),
seq($.expression, '..'),
seq('..', $.expression),
'..',
)),


// for example in let a = try_smth?; it would be `try_smth?`
try_expression: ($) => prec(PREC.try, seq($.expression, '?')),

Expand Down Expand Up @@ -1106,7 +1122,7 @@ module.exports = grammar({
call_expression: ($) =>
prec(
PREC.call,
seq(field('function', $.expression), field('arguments', $.arguments)),
seq(field('function', $.expression_except_range), field('arguments', $.arguments)),
),
// for example in foo(a, b, c) it would be `(a, b, c)`
arguments: ($) =>
Expand Down
84 changes: 71 additions & 13 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 86 additions & 1 deletion src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7a23666

Please sign in to comment.