Skip to content

Commit

Permalink
feat: re-export parol_runtime for improved usability
Browse files Browse the repository at this point in the history
  • Loading branch information
jsinger67 committed Feb 22, 2025
1 parent 99968d7 commit a3f4274
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 deletions.
38 changes: 36 additions & 2 deletions book/src/ParolVersion3.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ variants.
I expect that most applications that use `parol` v2 can upgrade to v3 without problems. The
changes listed above only affect applications that use the `parol` library for very specific tasks.

### New feature "User defined member names / Grammar labeling"
## New feature "User defined member names / Grammar labeling"

You can now easily define a user type to which each occurrence of a certain non-terminal should
be automatically converted to.
Expand Down Expand Up @@ -129,4 +129,38 @@ ScannerSwitch
| "%pop" '(' ')'
;
```
All terminals are automatically defined the be converted to `crate::parol_ls_grammar::OwnedToken`.
All terminals are automatically defined the be converted to `crate::parol_ls_grammar::OwnedToken`.

## parol re-exports parol_runtime

This simplifies the use and avoids version conflicts between both libraries.

The initial `Cargo.toml` will then simple be similar like this:

```toml
[package]
name = "re_export"
version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0"
env_logger = "0.11"
parol_runtime = "2.2"
thiserror = "2.0"

[build-dependencies]
parol = "3.0.0"
```

This makes a lot more sense, since you would expect to reference `parol_runtime` in your parser
crate and have `parol` as build dependency.

Anyway, as before, it is advisable to use `parol_runtime` in the version that `parol` in the build
dependencies. These two crates are precisely coordinated.

To check this you can use the following command:

```shell
cargo tree -i parol_runtime
```
17 changes: 0 additions & 17 deletions crates/parol/src/bin/parol/tools/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ const DEPENDENCIES: &[&[&str]] = &[
concat!("parol@", env!("CARGO_PKG_VERSION")),
"--build",
],
&["add", "[email protected]", "--build"],
];

const TREE_GEN_DEPENDENCY: &str = "add [email protected]";
Expand Down Expand Up @@ -160,22 +159,6 @@ fn apply_cargo(creation_data: &CreationData) -> Result<()> {
.map(|_| ())?
}

let mut cargo_toml = fs::OpenOptions::new()
.append(true)
.open(creation_data.path.join("Cargo.toml"))
.context("Error opening Cargo.toml file")?;
write!(
cargo_toml,
"
# For faster builds.
[profile.dev.build-override]
opt-level = 3
[profile.release.build-override]
opt-level = 3
"
)
.context("Error writing to Cargo.toml file")?;

Ok(())
}

Expand Down
3 changes: 1 addition & 2 deletions crates/parol/src/bin/parol/tools/new/build_rs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ impl std::fmt::Display for BuildRsData<'_> {
f,
r#"use std::process;
use parol::{{build::Builder, ParolErrorReporter}};
use parol_runtime::Report;
use parol::{{build::Builder, parol_runtime::Report, ParolErrorReporter}};
fn main() {{
// CLI equivalent is:
Expand Down
3 changes: 3 additions & 0 deletions crates/parol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,6 @@ pub use utils::{generate_tree_layout, obtain_grammar_config, obtain_grammar_conf
/// Grammar with a higher value will be rejected.
///
pub const MAX_K: usize = 10;

// re-export
pub use parol_runtime;

0 comments on commit a3f4274

Please sign in to comment.