Skip to content

Commit

Permalink
refactor: Move grammar parser constructor to codegen_grammar
Browse files Browse the repository at this point in the history
This is an overdue cleanup; rather than shipping the constructor with
the language definition, it should be a part of the crate responsible
for the codegen/parser logic itself.
  • Loading branch information
Xanewok committed Jan 15, 2024
1 parent a7230b2 commit feca5ea
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 14 deletions.
5 changes: 2 additions & 3 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions crates/codegen/grammar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ edition.workspace = true
publish = false

[dependencies]
codegen_language_definition = { workspace = true }
indexmap = { workspace = true }
semver = { workspace = true }
strum_macros = { workspace = true }
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::ops::Deref;
use std::rc::Rc;

use codegen_grammar::{
use codegen_language_definition::model::{self, FieldsErrorRecovery, Identifier, Item};
use indexmap::IndexMap;

use crate::{
Grammar, GrammarElement, KeywordScannerDefinition, KeywordScannerDefinitionNode,
KeywordScannerDefinitionVersionedNode, Named, ParserDefinition, ParserDefinitionNode,
PrecedenceOperatorModel, PrecedenceParserDefinition, PrecedenceParserDefinitionNode,
ScannerDefinition, ScannerDefinitionNode, TriviaParserDefinition, VersionQuality,
VersionQualityRange,
};
use codegen_language_definition::model::{self, FieldsErrorRecovery, Identifier, Item};
use indexmap::IndexMap;

/// Materializes the DSL v2 model ([`model::Language`]) into [`Grammar`].
pub trait GrammarConstructorDslV2 {
Expand Down Expand Up @@ -143,7 +144,7 @@ impl KeywordScannerDefinition for NamedKeywordScanner {
self.name
}

fn definitions(&self) -> &[codegen_grammar::KeywordScannerDefinitionVersionedNode] {
fn definitions(&self) -> &[KeywordScannerDefinitionVersionedNode] {
&self.defs
}

Expand Down
2 changes: 2 additions & 0 deletions crates/codegen/grammar/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
mod constructor;
mod grammar;
mod parser_definition;
mod precedence_parser_definition;
mod scanner_definition;
mod version_quality;
mod visitor;

pub use constructor::GrammarConstructorDslV2;
pub use grammar::*;
pub use parser_definition::*;
pub use precedence_parser_definition::*;
Expand Down
3 changes: 0 additions & 3 deletions crates/solidity/inputs/language/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ infra_utils = { workspace = true }
[dependencies]
anyhow = { workspace = true }
bson = { workspace = true }
codegen_grammar = { workspace = true }
codegen_language_definition = { workspace = true }
codegen_language_macros = { workspace = true }
codegen_schema = { workspace = true }
indexmap = { workspace = true }
semver = { workspace = true }
strum_macros = { workspace = true }
2 changes: 0 additions & 2 deletions crates/solidity/inputs/language/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
//! Call the [`SolidityLanguageExtensions::load_solidity`] method to load the precompiled language definition.
mod definition;
mod grammar;

use anyhow::Result;
use codegen_schema::types::{LanguageDefinition, LanguageDefinitionRef};
pub use definition::SolidityDefinition;
pub use grammar::GrammarConstructorDslV2;

pub trait SolidityLanguageExtensions {
/// Loads the precompiled Solidity language definition.
Expand Down
4 changes: 2 additions & 2 deletions crates/solidity/outputs/cargo/crate/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
//! It is removed when publishing to crates.io.
use anyhow::Result;
use codegen_grammar::Grammar;
use codegen_grammar::{Grammar, GrammarConstructorDslV2};
use codegen_parser_generator::{AstModel, RustGenerator};
use infra_utils::cargo::CargoWorkspace;
use solidity_language::{GrammarConstructorDslV2, SolidityDefinition};
use solidity_language::SolidityDefinition;

fn main() -> Result<()> {
let language = SolidityDefinition::create();
Expand Down

0 comments on commit feca5ea

Please sign in to comment.