Skip to content

Commit

Permalink
fix #15: reexport deps for generated parsers
Browse files Browse the repository at this point in the history
Now, only rustemo crate is a required dependency for the project using it.
  • Loading branch information
igordejanovic committed Nov 6, 2024
1 parent b71fa3e commit 4cf0907
Show file tree
Hide file tree
Showing 27 changed files with 60 additions and 128 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- attempt to subtract causes overflow in GLR default builder. See [16]. Thanks
andrewbaxter@GitHub for the bug report and regression test.
- reexported dependencies for generated parsers. Now, the only dependency
required by the client code is `rustemo`. See [15]. Thanks andrewbaxter@GitHub
for the idea

[16]: https://github.com/igordejanovic/rustemo/issues/16
[15]: https://github.com/igordejanovic/rustemo/issues/15


# [0.6.2] - 2024-10-11
Expand Down
36 changes: 3 additions & 33 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions check-update-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ cargo clippy --all --all-targets -- -D warnings
cargo nextest run -p rustemo-compiler
cargo install --path rustemo-compiler --debug

# README Examples
rcomp docs/src/readme_example/src/textlr/calclr.rustemo
rcomp --parser-algo glr docs/src/readme_example/src/textglr/calc.rustemo

cd docs/src/tutorials/calculator/
for i in {1..5}; do
rcomp calculator$i/src/calculator.rustemo;
Expand Down
5 changes: 0 additions & 5 deletions docs/src/parsing/expressions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,5 @@ workspace = "../../../.."
[dependencies]
rustemo = { path = "../../../../rustemo" }

# Default string lexer uses regexes and once_cell to init regexes only once.
regex = { version = "1", default-features = false, features = ["std", "unicode-perl"] }
once_cell = "1"
colored = "2"

[build-dependencies]
rustemo-compiler = { path = "../../../../rustemo-compiler" }
3 changes: 0 additions & 3 deletions docs/src/readme_example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,4 @@ rust-version.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
once_cell = "1"
regex = { version = "1.7.1", default-features = false, features = ["std", "unicode-perl"] }
colored = "2"
rustemo = { path = "../../../rustemo" }
12 changes: 6 additions & 6 deletions docs/src/readme_example/src/testglr/calc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use rustemo::{
Result, Input as InputT, Lexer, Token, TokenRecognizer as TokenRecognizerT, Parser,
ParserDefinition, State as StateT, Builder,
};
use regex::Regex;
use once_cell::sync::Lazy;
use rustemo::regex::Regex;
use rustemo::once_cell::sync::Lazy;
use rustemo::StringLexer;
use rustemo::LRBuilder;
use super::calc_actions;
Expand All @@ -16,7 +16,7 @@ use rustemo::Action::{self, Shift, Reduce, Accept};
use rustemo::debug::{log, logn};
#[allow(unused_imports)]
#[cfg(debug_assertions)]
use colored::*;
use rustemo::colored::*;
pub type Input = str;
const STATE_COUNT: usize = 7usize;
const MAX_RECOGNIZERS: usize = 3usize;
Expand Down Expand Up @@ -354,7 +354,7 @@ impl<'i> TokenRecognizerT<'i> for TokenRecognizer {
log!("{} '{}'", "recognized".bold().green(), x_str);
Some(x_str)
}
None => {
_ => {
log!("{}", "not recognized".red());
None
}
Expand All @@ -378,7 +378,7 @@ pub(crate) static RECOGNIZERS: [TokenRecognizer; TERMINAL_COUNT] = [
TokenRecognizer(
TokenKind::Number,
Recognizer::RegexMatch(
Lazy::new(|| { Regex::new(concat!("^(", "\\d+", ")")).unwrap() }),
Lazy::new(|| { Regex::new(concat!("^", "\\d+")).unwrap() }),
),
),
TokenRecognizer(TokenKind::Add, Recognizer::StrMatch("+")),
Expand Down Expand Up @@ -422,7 +422,7 @@ for DefaultBuilder {
&mut self,
context: &mut Context<'i, Input>,
prod: ProdKind,
_prod_len: usize,
prod_len: usize,
) {
let prod = match prod {
ProdKind::EP1 => {
Expand Down
12 changes: 6 additions & 6 deletions docs/src/readme_example/src/testlr/calclr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use rustemo::{
Result, Input as InputT, Lexer, Token, TokenRecognizer as TokenRecognizerT, Parser,
ParserDefinition, State as StateT, Builder,
};
use regex::Regex;
use once_cell::sync::Lazy;
use rustemo::regex::Regex;
use rustemo::once_cell::sync::Lazy;
use rustemo::StringLexer;
use rustemo::LRBuilder;
use super::calclr_actions;
Expand All @@ -16,7 +16,7 @@ use rustemo::Action::{self, Shift, Reduce, Accept};
use rustemo::debug::{log, logn};
#[allow(unused_imports)]
#[cfg(debug_assertions)]
use colored::*;
use rustemo::colored::*;
pub type Input = str;
const STATE_COUNT: usize = 7usize;
const MAX_RECOGNIZERS: usize = 3usize;
Expand Down Expand Up @@ -368,7 +368,7 @@ impl<'i> TokenRecognizerT<'i> for TokenRecognizer {
log!("{} '{}'", "recognized".bold().green(), x_str);
Some(x_str)
}
None => {
_ => {
log!("{}", "not recognized".red());
None
}
Expand All @@ -392,7 +392,7 @@ pub(crate) static RECOGNIZERS: [TokenRecognizer; TERMINAL_COUNT] = [
TokenRecognizer(
TokenKind::Number,
Recognizer::RegexMatch(
Lazy::new(|| { Regex::new(concat!("^(", "\\d+", ")")).unwrap() }),
Lazy::new(|| { Regex::new(concat!("^", "\\d+")).unwrap() }),
),
),
TokenRecognizer(TokenKind::Add, Recognizer::StrMatch("+")),
Expand Down Expand Up @@ -438,7 +438,7 @@ for DefaultBuilder {
&mut self,
context: &mut Context<'i, Input>,
prod: ProdKind,
_prod_len: usize,
prod_len: usize,
) {
let prod = match prod {
ProdKind::EP1 => {
Expand Down
14 changes: 0 additions & 14 deletions docs/src/tutorials/calculator/calculator.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,6 @@ dependency:
cargo add rustemo
```

Since we are using regular expressions in our grammar we also need `regex` and
`once_cell`:

```sh
cargo add regex --no-default-features --features std,unicode-perl
cargo add once_cell
```

We use `colored` for coloring the CLI log output.

```sh
cargo add colored
```

Your `Cargo.toml` should look like this:
```toml
{{#include ./calculator1/Cargo.toml:tutorial }}
Expand Down
3 changes: 0 additions & 3 deletions docs/src/tutorials/calculator/calculator1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
once_cell = "1"
regex = { version = "1.7.1", default-features = false, features = ["std", "unicode-perl"] }
colored = "2"
# A relative path to rustemo crate is used here for usage in the rustemo project tree.
# In your projects you should just specify the version.
rustemo = { version = "0.6", path = "../../../../../rustemo" }
Expand Down
6 changes: 3 additions & 3 deletions docs/src/tutorials/calculator/calculator1/src/calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use rustemo::{
Result, Input as InputT, Lexer, Token, TokenRecognizer as TokenRecognizerT, Parser,
ParserDefinition, State as StateT, Builder,
};
use regex::Regex;
use once_cell::sync::Lazy;
use rustemo::regex::Regex;
use rustemo::once_cell::sync::Lazy;
use rustemo::StringLexer;
use rustemo::LRBuilder;
use super::calculator_actions;
Expand All @@ -16,7 +16,7 @@ use rustemo::Action::{self, Shift, Reduce, Accept};
use rustemo::debug::{log, logn};
#[allow(unused_imports)]
#[cfg(debug_assertions)]
use colored::*;
use rustemo::colored::*;
pub type Input = str;
const STATE_COUNT: usize = 5usize;
const MAX_RECOGNIZERS: usize = 1usize;
Expand Down
3 changes: 0 additions & 3 deletions docs/src/tutorials/calculator/calculator2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
once_cell = { workspace = true }
regex = { workspace = true }
colored = { workspace = true }
rustemo = { workspace = true }

[dev-dependencies]
Expand Down
6 changes: 3 additions & 3 deletions docs/src/tutorials/calculator/calculator2/src/calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use rustemo::{
Result, Input as InputT, Lexer, Token, TokenRecognizer as TokenRecognizerT, Parser,
ParserDefinition, State as StateT, Builder,
};
use regex::Regex;
use once_cell::sync::Lazy;
use rustemo::regex::Regex;
use rustemo::once_cell::sync::Lazy;
use rustemo::StringLexer;
use rustemo::LRBuilder;
use super::calculator_actions;
Expand All @@ -16,7 +16,7 @@ use rustemo::Action::{self, Shift, Reduce, Accept};
use rustemo::debug::{log, logn};
#[allow(unused_imports)]
#[cfg(debug_assertions)]
use colored::*;
use rustemo::colored::*;
pub type Input = str;
const STATE_COUNT: usize = 11usize;
const MAX_RECOGNIZERS: usize = 5usize;
Expand Down
3 changes: 0 additions & 3 deletions docs/src/tutorials/calculator/calculator3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
once_cell = { workspace = true }
regex = { workspace = true }
colored = { workspace = true }
rustemo = { workspace = true }

[dev-dependencies]
Expand Down
6 changes: 3 additions & 3 deletions docs/src/tutorials/calculator/calculator3/src/calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use rustemo::{
Result, Input as InputT, Lexer, Token, TokenRecognizer as TokenRecognizerT, Parser,
ParserDefinition, State as StateT, Builder,
};
use regex::Regex;
use once_cell::sync::Lazy;
use rustemo::regex::Regex;
use rustemo::once_cell::sync::Lazy;
use rustemo::StringLexer;
use rustemo::LRBuilder;
use super::calculator_actions;
Expand All @@ -16,7 +16,7 @@ use rustemo::Action::{self, Shift, Reduce, Accept};
use rustemo::debug::{log, logn};
#[allow(unused_imports)]
#[cfg(debug_assertions)]
use colored::*;
use rustemo::colored::*;
pub type Input = str;
const STATE_COUNT: usize = 11usize;
const MAX_RECOGNIZERS: usize = 5usize;
Expand Down
3 changes: 0 additions & 3 deletions docs/src/tutorials/calculator/calculator4/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
once_cell = { workspace = true }
regex = { workspace = true }
colored = { workspace = true }
rustemo = { workspace = true }

[dev-dependencies]
Expand Down
Loading

0 comments on commit 4cf0907

Please sign in to comment.