Skip to content

Commit

Permalink
feat(parser): GritQL parser (#1998)
Browse files Browse the repository at this point in the history
  • Loading branch information
arendjr authored Mar 22, 2024
1 parent 1e81a8f commit a7ef325
Show file tree
Hide file tree
Showing 116 changed files with 11,017 additions and 110 deletions.
23 changes: 23 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ biome_diagnostics_categories = { version = "0.5.7", path = "./crates/biome_diagn
biome_diagnostics_macros = { version = "0.5.7", path = "./crates/biome_diagnostics_macros" }
biome_formatter = { version = "0.5.7", path = "./crates/biome_formatter" }
biome_fs = { version = "0.5.7", path = "./crates/biome_fs" }
biome_grit_factory = { version = "0.5.7", path = "./crates/biome_grit_factory" }
biome_grit_parser = { version = "0.1.0", path = "./crates/biome_grit_parser" }
biome_grit_syntax = { version = "0.5.7", path = "./crates/biome_grit_syntax" }
biome_html_syntax = { version = "0.5.7", path = "./crates/biome_html_syntax" }
biome_js_analyze = { version = "0.5.7", path = "./crates/biome_js_analyze" }
Expand Down
71 changes: 47 additions & 24 deletions crates/biome_grit_factory/src/generated/node_factory.rs

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

30 changes: 10 additions & 20 deletions crates/biome_grit_factory/src/generated/syntax_factory.rs

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

44 changes: 44 additions & 0 deletions crates/biome_grit_parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
authors.workspace = true
categories.workspace = true
description = "Biome's GritQL parser"
edition.workspace = true
homepage.workspace = true
keywords.workspace = true
license.workspace = true
name = "biome_grit_parser"
repository.workspace = true
version = "0.1.0"

[dependencies]
biome_console = { workspace = true }
biome_diagnostics = { workspace = true }
biome_grit_factory = { workspace = true }
biome_grit_syntax = { workspace = true }
biome_parser = { workspace = true }
biome_rowan = { workspace = true }
bitflags = { workspace = true }
schemars = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
smallvec = { workspace = true }
tracing = { workspace = true }
unicode-bom = { workspace = true }

[dev-dependencies]
insta = { workspace = true }
quickcheck = { workspace = true }
quickcheck_macros = { workspace = true }
tests_macros = { workspace = true }

[features]
schemars = ["dep:schemars"]
serde = ["biome_grit_syntax/serde"]
tests = []

# cargo-workspaces metadata
[package.metadata.workspaces]
independent = true

[lints]
workspace = true
61 changes: 61 additions & 0 deletions crates/biome_grit_parser/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use biome_grit_syntax::GritSyntaxKind::{self, *};
use biome_grit_syntax::T;
use biome_parser::{token_set, TokenSet};

// See the precedence rules defined in the Grit grammar:
// https://github.com/getgrit/tree-sitter-gritql/blob/main/grammar.js#L7
pub(crate) const PRECEDENCE_NOT: isize = 0;
pub(crate) const PRECEDENCE_PATTERN_AS: isize = 10;
pub(crate) const PRECEDENCE_MUL: isize = 8;
pub(crate) const PRECEDENCE_DIV: isize = 8;
pub(crate) const PRECEDENCE_MOD: isize = 8;
pub(crate) const PRECEDENCE_ADD: isize = 7;
pub(crate) const PRECEDENCE_SUB: isize = 7;
pub(crate) const PRECEDENCE_REWRITE: isize = 3;
pub(crate) const PRECEDENCE_ACCUMULATE: isize = 3;
pub(crate) const PRECEDENCE_PATTERN_LIMIT: isize = 1;
pub(crate) const PRECEDENCE_PATTERN_WHERE: isize = 1;
pub(crate) const PRECEDENCE_PATTERN: isize = -20;

// Recovery sets.
pub(crate) const ARG_LIST_RECOVERY_SET: TokenSet<GritSyntaxKind> = token_set!(T![,], T![')']);

pub(crate) const DEFINITION_LIST_RECOVERY_SET: TokenSet<GritSyntaxKind> = token_set!(EOF);

pub(crate) const ELEMENT_LIST_RECOVERY_SET: TokenSet<GritSyntaxKind> = token_set!(T![,], T!['}']);

pub(crate) const PATTERN_RECOVERY_SET: TokenSet<GritSyntaxKind> = token_set!(T![')'], T!['}'], EOF);

pub(crate) const PATTERN_ELSE_RECOVERY_SET: TokenSet<GritSyntaxKind> =
token_set!(T![')'], T!['}'], UNTIL_KW, EOF);

pub(crate) const PATTERN_LIST_RECOVERY_SET: TokenSet<GritSyntaxKind> = token_set!(T![,], T![']']);

pub(crate) const PATTERN_UNTIL_RECOVERY_SET: TokenSet<GritSyntaxKind> =
token_set!(T![')'], T!['}'], UNTIL_KW, EOF);

pub(crate) const PREDICATE_RECOVERY_SET: TokenSet<GritSyntaxKind> =
token_set!(T![')'], T!['}'], T![,], ELSE_KW);

// Other sets.
pub(crate) const BOOLEAN_VALUE_SET: TokenSet<GritSyntaxKind> = token_set![TRUE_KW, FALSE_KW];

pub(crate) const CODE_SNIPPET_SET: TokenSet<GritSyntaxKind> =
SUPPORTED_LANGUAGE_SET.union(token_set![GRIT_BACKTICK_SNIPPET, GRIT_RAW_BACKTICK_SNIPPET]);

pub(crate) const CONTAINER_SET: TokenSet<GritSyntaxKind> =
token_set![GRIT_VARIABLE, GRIT_MAP_ACCESSOR, GRIT_LIST_ACCESSOR];

pub(crate) const NOT_SET: TokenSet<GritSyntaxKind> = token_set![NOT_KW, T![!]];

pub(crate) const REGEX_SET: TokenSet<GritSyntaxKind> = token_set![GRIT_REGEX, GRIT_SNIPPET_REGEX];

pub(crate) const SUPPORTED_LANGUAGE_SET: TokenSet<GritSyntaxKind> =
token_set![T![js], T![json], T![css], T![grit], T![html]];

pub(crate) const SUPPORTED_LANGUAGE_SET_STR: &[&str] = &["js", "json", "css", "grit", "html"];

pub(crate) const SUPPORTED_LANGUAGE_FLAVOR_SET: TokenSet<GritSyntaxKind> =
token_set![T![typescript], T![jsx]];

pub(crate) const SUPPORTED_LANGUAGE_FLAVOR_SET_STR: &[&str] = &["typescript", "jsx"];
Loading

0 comments on commit a7ef325

Please sign in to comment.