Skip to content

Commit

Permalink
Disentangle grammar resolution and related PG code (#1018)
Browse files Browse the repository at this point in the history
Ticks the box in #638 (_Keyword trie inclusion should be reworked to not
require synthetic rules over all keywords_)

This exposes the resolution step rather than treating it as an
implementation detail and doesn't try to shoehorn the DSL v2 items to
the old `Grammar` model as much that the PG was based on.

Moreover, this breaks up the existing grammar visitor and tries to
collect or calculate more properties upfront directly from DSL v2 in
order to be more explicit that they not need to depend on the collector
state that tracked everything.

I didn't submit it initially because I felt I could polish it slightly
further (see the `TODO` note) but since I'm focused on EDR now and this
cleans up the last important box in #638 (the other one is simply
reverting some rules for string literals), I think it's worth reviewing
in the current state.
  • Loading branch information
Xanewok authored Jun 21, 2024
1 parent 0a93a23 commit 83cfe98
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 214 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/codegen/runtime/generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ quote = { workspace = true }
semver = { workspace = true }
serde = { workspace = true }
strum = { workspace = true }
strum_macros = { workspace = true }

[lints]
workspace = true
5 changes: 3 additions & 2 deletions crates/codegen/runtime/generator/src/parser/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ use std::rc::Rc;

use codegen_language_definition::model::{self, Identifier};

pub mod constructor;
pub mod parser_definition;
pub mod precedence_parser_definition;
pub mod resolver;
pub mod scanner_definition;
pub mod visitor;

pub use parser_definition::*;
pub use precedence_parser_definition::*;
pub use resolver::ResolveCtx;
pub use scanner_definition::*;
pub use visitor::*;

Expand All @@ -35,7 +36,7 @@ impl Grammar {
}

#[allow(clippy::enum_variant_names)] // this will be removed soon
#[derive(Clone)]
#[derive(Clone, strum_macros::EnumTryAs)]
pub enum GrammarElement {
ScannerDefinition(ScannerDefinitionRef),
KeywordScannerDefinition(Rc<model::KeywordItem>),
Expand Down
Loading

0 comments on commit 83cfe98

Please sign in to comment.