-
-
Notifications
You must be signed in to change notification settings - Fork 134
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
base: master
Are you sure you want to change the base?
docs(calculator_example): bumps chumsky
crate from 0.9.0 to 0.10.0
#474
Conversation
… which is only used in the example
CodSpeed Performance ReportMerging #474 will not alter performanceComparing Summary
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. 🚀 New features to boost your workflow:
|
@@ -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>>> |
There was a problem hiding this comment.
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))); |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
}, | ||
); | ||
|
||
let binary_2 = binary_1.clone().foldl( |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parser::parse()
now returns ParseResult
instead of std::result::Result
so I added .into_result()
to preserve the old behavior.
|
||
binary_2 | ||
}) | ||
.then_ignore(end()) |
There was a problem hiding this comment.
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.
The CI failed:
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. |
Hi @your-diary! Thanks for your PR :-)
You may need to update the lock file ( |
@jeertmans
Am I missing something? |
It seems the failure is reproducible in $ docker run -it --rm alpine sh
Possible cause: This repository doesn't have
I'm sorry this was incorrect. I should have executed |
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.
Now CI passed except for |
#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
release note of v0.10.0
Migration guide from v0.9.0 to v0.10.0? zesterer/chumsky#745
How to port
then().foldr()
in v0.9.0 to v0.10.0? zesterer/chumsky#746