Skip to content

Commit

Permalink
fix(grit): allow parsing alternative engine/language names (#4937)
Browse files Browse the repository at this point in the history
  • Loading branch information
morgante authored Jan 22, 2025
1 parent 5d7c34a commit 0bb86c7
Show file tree
Hide file tree
Showing 34 changed files with 764 additions and 56 deletions.
26 changes: 21 additions & 5 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.

26 changes: 23 additions & 3 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.

101 changes: 101 additions & 0 deletions crates/biome_grit_formatter/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,44 @@ impl IntoFormat<GritFormatContext> for biome_grit_syntax::GritDoubleLiteral {
)
}
}
impl FormatRule<biome_grit_syntax::GritEngineName>
for crate::grit::auxiliary::engine_name::FormatGritEngineName
{
type Context = GritFormatContext;
#[inline(always)]
fn fmt(
&self,
node: &biome_grit_syntax::GritEngineName,
f: &mut GritFormatter,
) -> FormatResult<()> {
FormatNodeRule::<biome_grit_syntax::GritEngineName>::fmt(self, node, f)
}
}
impl AsFormat<GritFormatContext> for biome_grit_syntax::GritEngineName {
type Format<'a> = FormatRefWithRule<
'a,
biome_grit_syntax::GritEngineName,
crate::grit::auxiliary::engine_name::FormatGritEngineName,
>;
fn format(&self) -> Self::Format<'_> {
FormatRefWithRule::new(
self,
crate::grit::auxiliary::engine_name::FormatGritEngineName::default(),
)
}
}
impl IntoFormat<GritFormatContext> for biome_grit_syntax::GritEngineName {
type Format = FormatOwnedWithRule<
biome_grit_syntax::GritEngineName,
crate::grit::auxiliary::engine_name::FormatGritEngineName,
>;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule::new(
self,
crate::grit::auxiliary::engine_name::FormatGritEngineName::default(),
)
}
}
impl FormatRule<biome_grit_syntax::GritEvery> for crate::grit::auxiliary::every::FormatGritEvery {
type Context = GritFormatContext;
#[inline(always)]
Expand Down Expand Up @@ -3819,6 +3857,44 @@ impl IntoFormat<GritFormatContext> for biome_grit_syntax::GritBogusLanguageFlavo
FormatOwnedWithRule :: new (self , crate :: grit :: bogus :: bogus_language_flavor_kind :: FormatGritBogusLanguageFlavorKind :: default ())
}
}
impl FormatRule<biome_grit_syntax::GritBogusLanguageName>
for crate::grit::bogus::bogus_language_name::FormatGritBogusLanguageName
{
type Context = GritFormatContext;
#[inline(always)]
fn fmt(
&self,
node: &biome_grit_syntax::GritBogusLanguageName,
f: &mut GritFormatter,
) -> FormatResult<()> {
FormatBogusNodeRule::<biome_grit_syntax::GritBogusLanguageName>::fmt(self, node, f)
}
}
impl AsFormat<GritFormatContext> for biome_grit_syntax::GritBogusLanguageName {
type Format<'a> = FormatRefWithRule<
'a,
biome_grit_syntax::GritBogusLanguageName,
crate::grit::bogus::bogus_language_name::FormatGritBogusLanguageName,
>;
fn format(&self) -> Self::Format<'_> {
FormatRefWithRule::new(
self,
crate::grit::bogus::bogus_language_name::FormatGritBogusLanguageName::default(),
)
}
}
impl IntoFormat<GritFormatContext> for biome_grit_syntax::GritBogusLanguageName {
type Format = FormatOwnedWithRule<
biome_grit_syntax::GritBogusLanguageName,
crate::grit::bogus::bogus_language_name::FormatGritBogusLanguageName,
>;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule::new(
self,
crate::grit::bogus::bogus_language_name::FormatGritBogusLanguageName::default(),
)
}
}
impl FormatRule<biome_grit_syntax::GritBogusLiteral>
for crate::grit::bogus::bogus_literal::FormatGritBogusLiteral
{
Expand Down Expand Up @@ -4172,6 +4248,31 @@ impl IntoFormat<GritFormatContext> for biome_grit_syntax::AnyGritLanguageFlavorK
)
}
}
impl AsFormat<GritFormatContext> for biome_grit_syntax::AnyGritLanguageName {
type Format<'a> = FormatRefWithRule<
'a,
biome_grit_syntax::AnyGritLanguageName,
crate::grit::any::language_name::FormatAnyGritLanguageName,
>;
fn format(&self) -> Self::Format<'_> {
FormatRefWithRule::new(
self,
crate::grit::any::language_name::FormatAnyGritLanguageName::default(),
)
}
}
impl IntoFormat<GritFormatContext> for biome_grit_syntax::AnyGritLanguageName {
type Format = FormatOwnedWithRule<
biome_grit_syntax::AnyGritLanguageName,
crate::grit::any::language_name::FormatAnyGritLanguageName,
>;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule::new(
self,
crate::grit::any::language_name::FormatAnyGritLanguageName::default(),
)
}
}
impl AsFormat<GritFormatContext> for biome_grit_syntax::AnyGritListAccessorSubject {
type Format<'a> = FormatRefWithRule<
'a,
Expand Down
15 changes: 15 additions & 0 deletions crates/biome_grit_formatter/src/grit/any/language_name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file.
use crate::prelude::*;
use biome_grit_syntax::AnyGritLanguageName;
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatAnyGritLanguageName;
impl FormatRule<AnyGritLanguageName> for FormatAnyGritLanguageName {
type Context = GritFormatContext;
fn fmt(&self, node: &AnyGritLanguageName, f: &mut GritFormatter) -> FormatResult<()> {
match node {
AnyGritLanguageName::GritBogusLanguageName(node) => node.format().fmt(f),
AnyGritLanguageName::GritLanguageName(node) => node.format().fmt(f),
}
}
}
1 change: 1 addition & 0 deletions crates/biome_grit_formatter/src/grit/any/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub(crate) mod container;
pub(crate) mod definition;
pub(crate) mod language_declaration;
pub(crate) mod language_flavor_kind;
pub(crate) mod language_name;
pub(crate) mod list_accessor_subject;
pub(crate) mod list_index;
pub(crate) mod list_pattern;
Expand Down
10 changes: 10 additions & 0 deletions crates/biome_grit_formatter/src/grit/auxiliary/engine_name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use crate::prelude::*;
use biome_formatter::write;
use biome_grit_syntax::GritEngineName;
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritEngineName;
impl FormatNodeRule<GritEngineName> for FormatGritEngineName {
fn fmt_fields(&self, node: &GritEngineName, f: &mut GritFormatter) -> FormatResult<()> {
write!(f, [node.engine_kind().format()])
}
}
1 change: 1 addition & 0 deletions crates/biome_grit_formatter/src/grit/auxiliary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub(crate) mod bubble;
pub(crate) mod bubble_scope;
pub(crate) mod dot;
pub(crate) mod dotdotdot;
pub(crate) mod engine_name;
pub(crate) mod every;
pub(crate) mod files;
pub(crate) mod language_declaration;
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_grit_formatter/src/grit/auxiliary/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ impl FormatNodeRule<GritVersion> for FormatGritVersion {
fn fmt_fields(&self, node: &GritVersion, f: &mut GritFormatter) -> FormatResult<()> {
let GritVersionFields {
engine_token,
biome_token,
engine_name,
l_paren_token,
version,
r_paren_token,
Expand All @@ -18,7 +18,7 @@ impl FormatNodeRule<GritVersion> for FormatGritVersion {
[
engine_token.format(),
space(),
biome_token.format(),
engine_name.format(),
l_paren_token.format(),
version.format(),
r_paren_token.format()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use crate::FormatBogusNodeRule;
use biome_grit_syntax::GritBogusLanguageName;
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatGritBogusLanguageName;
impl FormatBogusNodeRule<GritBogusLanguageName> for FormatGritBogusLanguageName {}
1 change: 1 addition & 0 deletions crates/biome_grit_formatter/src/grit/bogus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub(crate) mod bogus_container;
pub(crate) mod bogus_definition;
pub(crate) mod bogus_language_declaration;
pub(crate) mod bogus_language_flavor_kind;
pub(crate) mod bogus_language_name;
pub(crate) mod bogus_literal;
pub(crate) mod bogus_map_element;
pub(crate) mod bogus_named_arg;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
engine marzano(0.1)

`console.log($var)` => `console.log($var)`
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
source: crates/biome_formatter_test/src/snapshot_builder.rs
info: grit/marzano/engine.grit
---
# Input

```grit
engine marzano(0.1)
`console.log($var)` => `console.log($var)`
```


=============================

# Outputs

## Output 1

-----
Indent style: Tab
Indent width: 2
Line ending: LF
Line width: 80
Attribute Position: Auto
-----

```grit
engine marzano(0.1)
`console.log($var)` => `console.log($var)`
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
engine biome(0.1)
language python

`$var in $dict.keys()` => `$var in $dict`
Loading

0 comments on commit 0bb86c7

Please sign in to comment.