Skip to content

Commit

Permalink
fix: Make sure to always include even unused keywords in the scanner …
Browse files Browse the repository at this point in the history
…trie
  • Loading branch information
Xanewok committed Nov 10, 2023
1 parent ec31334 commit 21de3e8
Show file tree
Hide file tree
Showing 5 changed files with 17,513 additions and 14,615 deletions.
40 changes: 40 additions & 0 deletions crates/solidity/inputs/language/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,46 @@ impl GrammarConstructorDslV2 for codegen_grammar::Grammar {
for (_lex_ctx, item) in items.values() {
resolve_grammar_element(item.name(), &mut ctx);
}

// HACK: To make sure the unused (not referred to) keywords are included in the scanner literal trie,
// we replicate the DSL v1 behaviour of introducing a synthetic parser that is only meant to group
// keywords by their lexical context.
let mut keywords_per_ctxt = HashMap::new();
for (ident, (lex_ctx, item)) in &items {
let lex_ctx = lex_ctx.clone().unwrap_or(Identifier::from("Default"));
if let Item::Keyword { .. } = item.as_ref() {
keywords_per_ctxt
.entry(lex_ctx)
.or_insert_with(Vec::new)
.push(ident);
}
}
for (lex_ctx, keywords) in keywords_per_ctxt {
let parser_name = Identifier::from(format!("{lex_ctx}AllKeywords"));
let all_keywords = model::EnumItem {
name: parser_name.clone(),
enabled: None,
variants: keywords
.iter()
.map(|&ident| model::EnumVariant {
name: Identifier::from("unused"),
enabled: None,
reference: ident.clone(),
})
.collect(),
};

let def = resolve_choice(all_keywords, &mut ctx);
ctx.resolved.insert(
parser_name.clone(),
GrammarElement::ParserDefinition(Rc::new(NamedParserThunk(
parser_name.to_string().leak(),
lex_ctx.to_string().leak(),
OnceCell::from(def),
))),
);
}

let resolved_items = ctx
.resolved
.into_iter()
Expand Down
105 changes: 105 additions & 0 deletions crates/solidity/outputs/cargo/crate/src/generated/kinds.rs

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

Loading

0 comments on commit 21de3e8

Please sign in to comment.