8000 docs(calculator_example): bumps `chumsky` crate from 0.9.0 to 0.10.0 by your-diary · Pull Request #474 · maciejhirsz/logos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

docs(calculator_example): bumps chumsky crate from 0.9.0 to 0.10.0 #474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

your-diary
Copy link
Contributor
@your-diary your-diary commented Mar 26, 2025

#439 added a simple calculator example to the book, and the example used chumsky crate as a parser combinator library.

Recently, chumsky v0.10.0 was released and it contains relatively many breaking changes. So I try to upgrade the dependency in this PR.

Please note the crate is only used in the example (I checked $ rg chumsky at the root of the repository).

References

Copy link
codspeed-hq bot commented Mar 26, 2025

CodSpeed Performance Report

Merging #474 will not alter performance

Comparing your-diary:docs/bump_dependency_of_simple_calculator_example (162dbea) with master (ea83d46)

Summary

✅ 6 untouched benchmarks

Copy link
codecov bot commented Mar 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 49.26%. Comparing base (ea83d46) to head (162dbea).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #474      +/-   ##
==========================================
- Coverage   49.31%   49.26%   -0.05%     
==========================================
  Files          33       33              
  Lines        2054     2054              
==========================================
- Hits         1013     1012       -1     
- Misses       1041     1042       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
10000

@@ -80,7 +80,9 @@ impl Expr {

#[allow(clippy::let_and_return)]
/* ANCHOR: parser */
fn parser() -> impl Parser<Token, Expr, Error = Simple<Token>> {
fn parser<'src>(
) -> impl Parser<'src, &'src [Token], Expr, chumsky::extra::Err<chumsky::error::Simple<'src, Token>>>
Copy link
Contributor Author
@your-diary your-diary Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref: migration guide

The Parser trait has now gained a lifetime parameter, representing the lifetime of the input. Most of the time you just want to have your parser function be generic over it, like fn my_parser<'src>() -> impl Parser<'src, I, O> { ... }.

The I parameter of Parser<'src, I, O> now refers to the entire input, not just the token type. For example, if your parser previously parsed Tokens, your input type will likely be &'src [Token].

The optional E parameter of Parser<'src, I, O, E>, which previously indicated the error type, has been renamed as the 'Extra' parameter, which continues to specify the error type, along with other features like state, context, etc. There is a convenient short-hand in the form of the the extra::Err type alias, which preserves the same behaviour.

.repeated(),
)
.foldl(|lhs, (op, rhs)| match op {
.foldr(atom, |_op, rhs| Expr::Neg(Box::new(rhs)));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then(X).foldr(Y) in v0.9.0 corresponds to foldr(X, Y) in v0.10.0: zesterer/chumsky#746

.foldr(atom, |_op, rhs| Expr::Neg(Box::new(rhs)));

let binary_1 = unary.clone().foldl(
just(Token::Multiply)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then(X).foldl(Y) in v0.9.0 corresponds to foldl(X, Y) in v0.10.0: zesterer/chumsky#746

8000
},
);

let binary_2 = binary_1.clone().foldl(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then(X).foldl(Y) in v0.9.0 corresponds to foldl(X, Y) in v0.10.0: zesterer/chumsky#746

@@ -156,7 +152,7 @@ fn main() {
}

//parses the tokens to construct an AST
let ast = match parser().parse(tokens) {
let ast = match parser().parse(&tokens).into_result() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8000

binary_2
})
.then_ignore(end())
Copy link
Contributor Author
@your-diary your-diary Mar 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ref: migration guide

Parsers are no longer lazy by default. Previously, one had to add .then_ignore(end()) to the top-level parser to 'force' it to keep consuming tokens until the end of the input. This is no longer the case, calling parser.parse(...) will produce an error if all input is not consumed.

@your-diary your-diary marked this pull request as ready for review March 26, 2025 15:23
@your-diary
Copy link
Contributor Author

The CI failed:

/Users/runner/.cargo/bin/cargo test --workspace --verbose --features forbid_unsafe

<snip>

error: package `half v2.5.0` cannot be built because it requires rustc 1.81 or newer, while the currently active rustc version is 1.74.0
Either upgrade to rustc 1.81 or newer, or use
cargo update half@2.5.0 --precise ver
where `ver` is the latest version of `half` supporting rustc 1.74.0
Error: The process '/Users/runner/.cargo/bin/cargo' failed with exit code 101

but I don't understand the reason...

A similar command

$ cargo +1.74.0 build --workspace --verbose --features forbid_unsafe

succeeded on my local environment.

@jeertmans
Copy link
Collaborator

Hi @your-diary! Thanks for your PR :-)

The CI failed:

/Users/runner/.cargo/bin/cargo test --workspace --verbose --features forbid_unsafe

<snip>

error: package `half v2.5.0` cannot be built because it requires rustc 1.81 or newer, while the currently active rustc version is 1.74.0
Either upgrade to rustc 1.81 or newer, or use
cargo update half@2.5.0 --precise ver
where `ver` is the latest version of `half` supporting rustc 1.74.0
Error: The process '/Users/runner/.cargo/bin/cargo' failed with exit code 101

but I don't understand the reason...

A similar command

$ cargo +1.74.0 build --workspace --verbose --features forbid_unsafe

succeeded on my local environment.

You may need to update the lock file (Cargo.lock).

@your-diary
Copy link
Contributor Author

@jeertmans
Hi!

You may need to update the lock file (Cargo.lock).

Cargo.lock is listed in .gitignore, so when I execute git add -f Cargo.lock, it is staged as a new file.

Am I missing something?

@your-diary
Copy link
Contributor Author
your-diary commented Mar 27, 2025

@jeertmans

It seems the failure is reproducible in master branch:

$ docker run -it --rm alpine sh
$ apk add curl libgcc git
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
$ . "$HOME/.cargo/env"
$ rustup install 1.74.0
$ git clone 'https://github.com/maciejhirsz/logos.git'
$ cd logos
$ cargo +1.74.0 test --workspace --verbose --features forbid_unsafe

Possible cause: This repository doesn't have Cargo.lock, so latest compatible crates are fetched in CI. And v2.5.0 of half crate was recently released. The release note says "MSRV has been changed to 1.81".


A similar command

$ cargo +1.74.0 build --workspace --verbose --features forbid_unsafe

succeeded on my local environment.

I'm sorry this was incorrect. I should have executed cargo +1.74.0 TEST instead of cargo +1.74.0 BUILD. When I retried with cargo +1.74.0 test, it failed as in the CI.

@jeertmans
Copy link
Collaborator

@jeertmans

It seems the failure is reproducible in master branch:

$ docker run -it --rm alpine sh
$ apk add curl libgcc git
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
$ . "$HOME/.cargo/env"
$ rustup install 1.74.0
$ git clone 'https://github.com/maciejhirsz/logos.git'
$ cd logos
$ cargo +1.74.0 test --workspace --verbose --features forbid_unsafe

Possible cause: This repository doesn't have Cargo.lock, so latest compatible crates are fetched in CI. And v2.5.0 of half crate was recently released. The release note says "MSRV has been changed to 1.81".

A similar command

$ cargo +1.74.0 build --workspace --verbose --features forbid_unsafe

succeeded on my local environment.

I'm sorry this was incorrect. I should have executed cargo +1.74.0 TEST instead of cargo +1.74.0 BUILD. When I retried with cargo +1.74.0 test, it failed as in the CI.

Yes, you are right, and I totally forgot we didn’t include a lock file, which we should definitely do for better testing about versions. Could you include a lock file with your PR?

@your-diary
Copy link
Contributor Author

@jeertmans

Yes, you are right, and I totally forgot we didn’t include a lock file, which we should definitely do for better testing about versions. Could you include a lock file with your PR?

Of course!

I executed the following command.

$ cargo +1.74.0 clean
$ cargo +1.74.0 test --workspace --verbose --features forbid_unsafe
$ cargo +1.74.0 test --workspace --verbose
$ cargo +1.74.0 build --workspace --verbose --features forbid_unsafe
$ cargo +1.74.0 build --workspace --verbose
$ git add -f Cargo.lock

Now CI passed except for codecov/project :)
Should I do something else to make the check pass?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0