Skip to content

Commit

Permalink
Correct grammar for DEFINE ANALYZER (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ce11an authored Aug 25, 2024
1 parent 8e6ee67 commit 6424331
Show file tree
Hide file tree
Showing 6 changed files with 54,877 additions and 54,286 deletions.
58 changes: 58 additions & 0 deletions examples/define_analzer.surql
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
-- Tokenizers

-- blank
DEFINE ANALYZER example_blank TOKENIZERS blank;

-- camel
DEFINE ANALYZER example_camel TOKENIZERS camel;

-- class
DEFINE ANALYZER example_class TOKENIZERS class;

-- punct
DEFINE ANALYZER example_punct TOKENIZERS punct;

-- Filters

-- ascii
DEFINE ANALYZER example_ascii TOKENIZERS class FILTERS ascii;

-- ngram
DEFINE ANALYZER example_ngram TOKENIZERS class FILTERS ngram(1,3);

-- edgengram
DEFINE ANALYZER example_edgengram TOKENIZERS class FILTERS edgengram(1,3);

-- lowercase
DEFINE ANALYZER example_lowercase TOKENIZERS class FILTERS lowercase;

-- snowball
DEFINE ANALYZER example_snowball TOKENIZERS class FILTERS snowball(english);

-- uppercase
DEFINE ANALYZER example_uppercase TOKENIZERS class FILTERS uppercase;

-- Using `IF NOT EXISTS` clause

-- Create an `ANALYZER` if it does not already exist
DEFINE ANALYZER IF NOT EXISTS example TOKENIZERS blank;

-- Using `OVERWRITE` clause

-- Create an ANALYZER and overwrite if it already exists
DEFINE ANALYZER OVERWRITE example TOKENIZERS blank;

-- More examples

-- Creates a simple analyzer removing diacritics marks
DEFINE ANALYZER ascii TOKENIZERS class FILTERS lowercase,ascii;

-- Creates an analyzer suitable for English text
DEFINE ANALYZER english TOKENIZERS class FILTERS snowball(english);

-- Creates an analyzer suitable for auto-completion.
DEFINE ANALYZER autocomplete FILTERS lowercase,edgengram(2,10);

-- Creates an analyzer suitable for source code analysis.
DEFINE ANALYZER code TOKENIZERS class,camel FILTERS lowercase,ascii;

70 changes: 33 additions & 37 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ module.exports = grammar({
),
),
semi_colon: _ => token(";"),
keyword_if: _ => token("IF"),
keyword_exists: _ => token("EXISTS"),
keyword_tokenizers: _ => token("TOKENIZERS"),
keyword_overwrite: _ => token("OVERWRITE"),
keyword_on: _ => token("ON"),
keyword_let: _ => token("LET"),
keyword_return: _ => token("RETURN"),
Expand Down Expand Up @@ -146,7 +150,6 @@ module.exports = grammar({
keyword_update: _ => token("UPDATE"),
keyword_insert: _ => token("INSERT"),
keyword_into: _ => token("INTO"),
keyword_tokenizers: _ => token("TOKENIZERS"),
keyword_filters: _ => token("FILTERS"),
keyword_when: _ => token("WHEN"),
keyword_then: _ => token("THEN"),
Expand All @@ -166,8 +169,6 @@ module.exports = grammar({
keyword_session: _ => token("SESSION"),
keyword_signin: _ => token("SIGNIN"),
keyword_signup: _ => token("SIGNUP"),
keyword_if: _ => token("IF"),
keyword_exists: _ => token("EXISTS"),
keyword_database: _ => token("DATABASE"),
keyword_password: _ => token("PASSWORD"),
keyword_password_hash: _ => token("PASSHASH"),
Expand Down Expand Up @@ -229,6 +230,7 @@ module.exports = grammar({
seq(
$.keyword_define,
$.keyword_analyzer,
optional(choice($.if_not_exists_clause, $.keyword_overwrite)),
$.identifier,
repeat(
choice(
Expand Down Expand Up @@ -538,48 +540,42 @@ module.exports = grammar({
),

select_statement: $ =>
seq(
$.select_clause,
optional($.omit_clause),
$.from_clause,
),
seq($.select_clause, optional($.omit_clause), $.from_clause),

live_select_statement: $ =>
seq(
$.keyword_live,
$.select_statement,
),
live_select_statement: $ => seq($.keyword_live, $.select_statement),

// Clauses

select_clause: $ => seq(
$.keyword_select,
choice(
seq($.keyword_value, $.predicate),
commaSeparated($.inclusive_predicate),
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),
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),

Expand Down
70 changes: 49 additions & 21 deletions src/grammar.json

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

12 changes: 12 additions & 0 deletions 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 6424331

Please sign in to comment.