Skip to content

Commit

Permalink
fix: Inline precedence operators in DSL parser codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
Xanewok committed Nov 15, 2023
1 parent f78143e commit 8f0cc2d
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 977 deletions.
23 changes: 8 additions & 15 deletions crates/solidity/inputs/language/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ impl GrammarConstructorDslV2 for Grammar {
GrammarElement::ParserDefinition(Rc::new(NamedParserThunk {
name: parser_name.to_string().leak(),
context: lex_ctx.to_string().leak(),
// Must be outlined for the codegen to include referred by it keywords in the trie.
is_inline: false,
def: OnceCell::from(def),
})),
);
Expand Down Expand Up @@ -214,6 +216,7 @@ impl TriviaParserDefinition for NamedTriviaParser {
struct NamedParserThunk {
name: &'static str,
context: &'static str,
is_inline: bool,
def: OnceCell<ParserDefinitionNode>,
}

Expand All @@ -227,21 +230,7 @@ impl ParserDefinition for NamedParserThunk {
}

fn is_inline(&self) -> bool {
// HACK(#638): Make sure all keywords are referred to by a parser, so that codegen includes them in the trie.
if self.name().ends_with("AllKeywords") {
return false;
}

// The DSL v2 definition already inlines the elements, however `Enum`s
// are not but should be, since they only have a single reference per variant.
match self.node() {
ParserDefinitionNode::Versioned(node, _) => match **node {
ParserDefinitionNode::Choice(_) => true,
_ => false,
},
ParserDefinitionNode::Choice(_) => true,
_ => false,
}
self.is_inline
}

fn node(&self) -> &ParserDefinitionNode {
Expand Down Expand Up @@ -346,6 +335,8 @@ fn resolve_grammar_element(ident: &Identifier, ctx: &mut ResolveCtx) -> GrammarE
let thunk = Rc::new(NamedParserThunk {
name: ident.to_string().leak(),
context: lex_ctx,
// Enums have a single reference per variant, so they should be inlined.
is_inline: matches!(elem.as_ref(), Item::Enum { .. }),
def: OnceCell::new(),
});
ctx.resolved.insert(
Expand Down Expand Up @@ -798,6 +789,8 @@ fn resolve_precedence(
let thunk = Rc::new(NamedParserThunk {
name: name.to_string().leak(),
context: lex_ctx,
// The operators are inlined but should be exposed under grouping `rule_name` below
is_inline: true,
def: OnceCell::new(),
});

Expand Down
36 changes: 0 additions & 36 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 8f0cc2d

Please sign in to comment.