Skip to content

Commit

Permalink
Reduce select statement states
Browse files Browse the repository at this point in the history
  • Loading branch information
Ce11an committed Aug 18, 2024
1 parent 1cac1d3 commit 487330a
Show file tree
Hide file tree
Showing 5 changed files with 54,763 additions and 76,622 deletions.
152 changes: 68 additions & 84 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -538,47 +538,48 @@ module.exports = grammar({

select_statement: $ =>
seq(
$.keyword_select,
choice(
seq($.keyword_value, $.predicate),
commaSeparated($.inclusive_predicate),
),
$.keyword_from,
optional($.keyword_only),
choice(
$.statement,
seq(
commaSeparated($.value),
optional($.with_clause),
optional($.where_clause),
optional($.split_clause),
optional($.group_clause),
optional($.order_clause),
optional($.limit_clause),
optional($.fetch_clause),
optional($.timeout_clause),
optional($.parallel_clause),
optional($.explain_clause),
),
),
$.select_clause,
optional($.omit_clause),
$.from_clause,
),

live_select_statement: $ =>
seq(
$.keyword_live,
$.keyword_select,
choice(
$.keyword_diff,
seq($.keyword_value, $.predicate),
commaSeparated($.inclusive_predicate),
),
$.keyword_from,
commaSeparated(choice($.identifier, $.record_id)),
optional($.where_clause),
optional($.fetch_clause),
$.select_statement,
),

// Clauses

select_clause: $ => seq(
$.keyword_select,
choice(
seq($.keyword_value, $.predicate),
commaSeparated($.inclusive_predicate),
),
),

from_clause: $ => seq(
$.keyword_from,
optional($.keyword_only),
choice(
$.statement,
seq(
commaSeparated($.value),
optional($.with_clause),
optional($.where_clause),
optional($.split_clause),
optional($.group_clause),
optional($.order_clause),
optional($.limit_clause),
optional($.fetch_clause),
optional($.timeout_clause),
optional($.parallel_clause),
optional($.explain_clause),
),
),
),

omit_clause: $ => seq($.keyword_omit, $.value),

with_clause: $ =>
Expand Down Expand Up @@ -876,8 +877,29 @@ module.exports = grammar({
$.point,
),

binary_expression: $ => prec.left(seq($.value, $.operator, $.value)),

binary_expression: $ => choice(
$.logical_expression,
$.comparison_expression,
$.arithmetic_expression
),

logical_expression: $ => prec.left(seq(
$.value,
choice('&&', '||', '??'),
$.value
)),

comparison_expression: $ => prec.left(seq(
$.value,
choice('==', '!=', '<', '>', '<=', '>=', 'CONTAINS', 'IN'),
$.value
)),

arithmetic_expression: $ => prec.left(seq(
$.value,
choice('+', '-', '*', '/', '**'),
$.value
)),
path: $ =>
choice(
seq($.base_value, repeat1($.path_element)),
Expand Down Expand Up @@ -977,55 +999,17 @@ module.exports = grammar({
duration_part: _ => /[0-9]+\s*(ns|us|µs|ms|s|m|h|d|w|y)/,
point: $ => seq("(", $.decimal, ",", $.decimal, ")"),

operator: $ =>
choice(
$.binary_operator,
"-",
"=",
">",
"<",
$.keyword_and,
$.keyword_or,
$.keyword_is,
seq($.keyword_is, $.keyword_not),
$.keyword_contains,
$.keyword_contains_not,
$.keyword_contains_all,
$.keyword_contains_any,
$.keyword_contains_none,
$.keyword_inside,
$.keyword_in,
$.keyword_not_inside,
seq($.keyword_not, $.keyword_in),
$.keyword_all_inside,
$.keyword_any_inside,
$.keyword_none_inside,
$.keyword_outside,
$.keyword_intersects,
seq("@", $.int, "@"),
seq(
"<|",
$.int,
optional(
seq(
",",
choice(
$.int,
$.keyword_chebyshev,
$.keyword_cosine,
$.keyword_euclidean,
$.keyword_hamming,
$.keyword_jaccard,
$.keyword_manhattan,
seq($.keyword_minkowski, $.number),
$.keyword_pearson,
),
),
),
"|>",
),
),

operator: $ => choice(
$.comparison_operator,
$.arithmetic_operator,
$.logical_operator,
$.special_operator
),

comparison_operator: _ => choice('=', '>', '<', '>=', '<=', '!='),
arithmetic_operator: _ => choice('+', '-', '*', '/', '**'),
logical_operator: _ => choice('AND', 'OR', 'NOT'),
special_operator: _ => choice('CONTAINS', 'IN', 'IS', 'IS NOT'),
binary_operator: _ =>
choice(
"&&",
Expand Down
Loading

0 comments on commit 487330a

Please sign in to comment.