Skip to content

Commit

Permalink
Implement Grit built-ins
Browse files Browse the repository at this point in the history
  • Loading branch information
arendjr committed Sep 19, 2024
1 parent 00760d4 commit d5a75ba
Show file tree
Hide file tree
Showing 14 changed files with 534 additions and 55 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/biome_grit_patterns/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ grit-pattern-matcher = { version = "0.3" }
grit-util = { version = "0.3" }
im = { version = "15.1.0" }
path-absolutize = { version = "3.1.1", optional = false, features = ["use_unix_paths_on_wasm"] }
rand = { version = "0.8" }
regex = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true, features = ["derive"] }
Expand Down
11 changes: 11 additions & 0 deletions crates/biome_grit_patterns/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ pub enum CompileError {
/// Used for missing syntax nodes.
MissingSyntaxNode,

/// A built-in function call was discovered in an unexpected context.
UnexpectedBuiltinCall(String),

/// A metavariables was discovered in an unexpected context.
UnexpectedMetavariable,

Expand Down Expand Up @@ -95,6 +98,9 @@ impl Diagnostic for CompileError {
CompileError::MissingSyntaxNode => {
fmt.write_markup(markup! { "A syntax node was missing" })
}
CompileError::UnexpectedBuiltinCall(name) => {
fmt.write_markup(markup! { "Unexpected call to built-in: "{{name}}"()" })
}
CompileError::UnexpectedMetavariable => {
fmt.write_markup(markup! { "Unexpected metavariable" })
}
Expand Down Expand Up @@ -176,6 +182,11 @@ impl Diagnostic for CompileError {

fn advices(&self, visitor: &mut dyn biome_diagnostics::Visit) -> std::io::Result<()> {
match self {
CompileError::UnexpectedBuiltinCall(name) => visitor.record_log(
LogCategory::Info,
&markup! { "Built-in "{{name}}" can only be used on the right-hand side of a rewrite" }
.to_owned(),
),
CompileError::ReservedMetavariable(_) => visitor.record_log(
LogCategory::Info,
&markup! { "Try using a different variable name" }.to_owned(),
Expand Down
Loading

0 comments on commit d5a75ba

Please sign in to comment.