Skip to content

Commit

Permalink
refactor: Accept Grammar by ref during codegen
Browse files Browse the repository at this point in the history
It's more idiomatic to use implicit Deref and accept arguments by-ref
if we do not need to know about the specific container/wrapper they're in.
  • Loading branch information
Xanewok committed Nov 15, 2023
1 parent 7f9215b commit d059486
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions crates/codegen/parser/generator/src/code_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::{
collections::{BTreeMap, BTreeSet},
mem,
path::PathBuf,
rc::Rc,
};

use anyhow::Result;
Expand Down Expand Up @@ -58,7 +57,7 @@ struct ScannerContext {
}

impl CodeGenerator {
pub fn write_source(output_dir: &PathBuf, grammar: Rc<Grammar>) -> Result<()> {
pub fn write_source(output_dir: &PathBuf, grammar: &Grammar) -> Result<()> {
let mut code = Self::default();
grammar.accept_visitor(&mut code);
let code = &code;
Expand Down
2 changes: 1 addition & 1 deletion crates/solidity/outputs/cargo/build/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn main() -> Result<()> {
let grammar = Grammar::from_dsl_v1();
let crate_dir = CargoWorkspace::locate_source_crate("slang_solidity")?;

CodeGenerator::write_source(&crate_dir.join("src/generated"), grammar)?;
CodeGenerator::write_source(&crate_dir.join("src/generated"), &grammar)?;
}

// This build script is not directly depended on by the caller source crate, so we need to manually
Expand Down
2 changes: 1 addition & 1 deletion crates/solidity/outputs/npm/build/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn main() -> Result<()> {
let grammar = Grammar::from_dsl_v1();
let crate_dir = CargoWorkspace::locate_source_crate("solidity_npm_crate")?;

CodeGenerator::write_source(&crate_dir.join("src/generated"), grammar)?;
CodeGenerator::write_source(&crate_dir.join("src/generated"), &grammar)?;
}

// This build script is not directly depended on by the caller source crate, so we need to manually
Expand Down

0 comments on commit d059486

Please sign in to comment.