Skip to content

Commit

Permalink
Simplify the syntax tree
Browse files Browse the repository at this point in the history
  • Loading branch information
belltoy committed Jul 28, 2024
1 parent 94370f1 commit 0e1d526
Show file tree
Hide file tree
Showing 45 changed files with 8,615 additions and 8,918 deletions.
31 changes: 18 additions & 13 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ module.exports = grammar({
_arithmetic: $ => choice(
$.binary_expression,
$.unary_expression,
alias($._term, $.term),
$._term,
// alias($._term, $.term),
),

binary_expression: $ => choice(
Expand Down Expand Up @@ -165,7 +166,7 @@ module.exports = grammar({
),

assign_target: $ => choice(
'_',
alias('_', $.noop),
$.query,
$.ident,
),
Expand Down Expand Up @@ -246,35 +247,39 @@ module.exports = grammar({
)),

_external_metadata: $ => prec.left(2, seq(
'%',
alias('%', $.metadata),
alias($._path_begin_without_dot, $.path),
)),

_path_begin_with_dot: $ => prec.left(seq(
choice(
field('field', seq($._immediate_dot, $.field)),
field('index', seq('[', $.integer, ']')),
seq($._immediate_dot, $._field),
seq('[', alias($.integer, $.index), ']'),
),
repeat($._path_segment),
)),

_path_begin_without_dot: $ => prec.left(seq(
choice(
field('field', $.field),
field('index', seq('[', $.integer, ']')),
$._field,
seq('[', alias($.integer, $.index), ']'),
),
repeat($._path_segment),
)),

_path_segment: $ => choice(
field('field', seq($._immediate_dot, $.field)),
field('index', seq('[', $.integer, ']')),
seq($._immediate_dot, $._field),
seq('[', alias($.integer, $.index), ']'),
),

_field: $ => choice(
$.field,
$.string,
),

field: $ => choice(
$._any_ident,
$._path_field,
$.string,
),

_path_field: _ => token.immediate(/[@_a-zA-Z][@_a-zA-Z0-9]*/),
Expand Down Expand Up @@ -302,12 +307,12 @@ module.exports = grammar({
seq(
'{',
repeat($._non_terminal_newline),
commaMultiline(seq($.object_key, ':', $._arithmetic), $),
commaMultiline(seq($.key, ':', alias($._arithmetic, $.value)), $),
'}',
),
),

object_key: $ => $.string,
key: $ => $.string,

array: $ => choice(
seq('[', repeat($._non_terminal_newline), ']'),
Expand Down Expand Up @@ -338,7 +343,7 @@ module.exports = grammar({
),

function_call: $ => seq(
$.ident,
field('function_name', $.ident),
optional(token.immediate('!')),
'(',
repeat($._non_terminal_newline),
Expand Down
5 changes: 2 additions & 3 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

[
(timestamp)
] @constant
] @string.special

(closure_variables
"|" @punctuation.bracket)

(integer) @number

(float) @number
(float) @number.float

[
(string)
Expand Down Expand Up @@ -88,7 +88,6 @@
"??"
"|"
"!"
"."
] @operator

[
Expand Down
Loading

0 comments on commit 0e1d526

Please sign in to comment.