Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up precedence parser codegen since DSL v2 #699

Merged
merged 18 commits into from
Dec 9, 2023
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: Move disambiguating_name_suffix to precedence-related code
Since it's the only place it's used and it's a small helper.
  • Loading branch information
Xanewok committed Dec 8, 2023
commit b3e7c169e1acb7b41f1e2e07638939691fb9e40f
12 changes: 0 additions & 12 deletions crates/codegen/parser/generator/src/parser_definition.rs
Original file line number Diff line number Diff line change
@@ -260,7 +260,6 @@ impl ParserDefinitionNodeExtensions for ParserDefinitionNode {

pub trait VersionQualityRangeVecExtensions {
fn wrap_code(&self, if_true: TokenStream, if_false: Option<TokenStream>) -> TokenStream;
fn disambiguating_name_suffix(&self) -> String;
}

impl VersionQualityRangeVecExtensions for Vec<VersionQualityRange> {
@@ -283,15 +282,4 @@ impl VersionQualityRangeVecExtensions for Vec<VersionQualityRange> {
quote! { if #(#flags)&&* { #if_true } #else_part }
}
}

fn disambiguating_name_suffix(&self) -> String {
let mut suffix = String::new();
for vqr in self {
suffix.push('_');
suffix.push_str(&vqr.quality.to_string().to_lowercase());
suffix.push_str("_from_");
suffix.push_str(&vqr.from.to_string().replace('.', "_"));
}
suffix
}
}
Original file line number Diff line number Diff line change
@@ -95,7 +95,7 @@ impl PrecedenceParserDefinitionNodeExtensions for PrecedenceParserDefinitionNode
let closure_name = format_ident!(
// Make a name that won't conflict with the parsers we define below
"parse_{name}{version_tag}",
version_tag = version_quality_ranges.disambiguating_name_suffix(),
version_tag = disambiguating_name_suffix(version_quality_ranges),
name = operator_definition.name().to_snake_case()
);

@@ -256,3 +256,14 @@ impl PrecedenceParserDefinitionNodeExtensions for PrecedenceParserDefinitionNode
}
}
}

fn disambiguating_name_suffix(ranges: &[VersionQualityRange]) -> String {
let mut suffix = String::new();
for vqr in ranges {
suffix.push('_');
suffix.push_str(&vqr.quality.to_string().to_lowercase());
suffix.push_str("_from_");
suffix.push_str(&vqr.from.to_string().replace('.', "_"));
}
suffix
}