-
-
Notifications
You must be signed in to change notification settings - Fork 154
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
Chumsky: Getting a Book #442
Conversation
So, I am not exactly sure what you would prefer to have happen with the |
Thanks for the PR! I would say that I'm opposed to moving the guide in general. I considered mdbook prior to using creating it, but decided against it in favour of hosting on docs.rs since it has several distinct advantages:
|
The answer is that Chumsky's parsers are *lazy*: they will consume all of the input that they can and then stop. | ||
If there's any trailing input, it'll be ignored. | ||
|
||
This is obviously not always desirable. If the user places random nonsense at the end of the file, we want to be | ||
able to generate an error about it! Worse still, that 'nonsense' could be input the user intended to be part of | ||
the program, but that contained a syntax error and so was not properly parsed. How can we force the parser to consume | ||
all of the input? | ||
|
||
To do this, we can make use of two new parsers: the `then_ignore` combinator and the `end` primitive. |
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.
Note that this is no longer true: chumsky parsers are now forced to consume everything by default (as if they had an implicit .then_ignore(end())
). The old behaviour can be recovered with the .lazy()
combinator. I think this section can be removed from the tutorial entirely.
# Chumsky | ||
|
||
Chumsky is a parser combinator library designed by humans, for humans. | ||
|
||
The library consists of many smaller parsers, which are designed to be combined | ||
together to create a parser for a larger unit. For example, you can use the | ||
smaller combinators to parse a programming language like [Tao](https://github.com/zesterer/tao). | ||
|
||
## Design | ||
|
||
Chumsky is designed such that it should be: | ||
|
||
* easy to use | ||
* modular and extensible | ||
* fast enough while allowing for quality errors | ||
* type driven, pushing users away from anti-patterns at compile-time | ||
* a mature and "batteries included" solution for context-free parsing | ||
|
||
## Performance | ||
|
||
As pointed out in the last design point, Chumsky makes a focus to provide | ||
high-quality errors and easy-of-use over performance. This being said, Chumsky | ||
should be able to hold its own when compared to the rest of your program. Due to | ||
the nature of parsing, it is _extremely_ difficult to create a sensible benchmark | ||
of a parser, as it depends largely on what is being parsed. That said, benchmarks are | ||
available on [GitHub](https://github.com/zesterer/chumsky/blob/main/benches/). | ||
Here is the current benchmark between this library and another parser combinator | ||
library, [`pom`](https://github.com/J-F-Liu/pom): | ||
|
||
``` | ||
test chumsky ... bench: 4,782,390 ns/iter (+/- 997,208) | ||
test pom ... bench: 12,793,490 ns/iter (+/- 1,954,583) | ||
``` | ||
|
||
This is obviously slower than a handwritten parser, but that's okay. Chumsky's | ||
goal is not to be the fastest, and if you're far enough in development that | ||
parsing performance is the actual problem, it's likely time to be moving to a | ||
hand-written parser anyway. |
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.
This old README information is out of date, I'm currently in the process of writing a new one.
Sorry it took so long to get back to this. Anyhow, I can definitely understand the wanting to stay by the guide as written, so I will go ahead and close this. |
Heyyo,
I figured I would take the leap and go ahead and try and cobble together the various resources for Chumsky into a book using mdbook.
If there are pieces that are missing, or that you would like included in the book, please let me know! There is also probably a typo hiding somewhere in the book. It currently aligns with version 1.0.0-alpha.4 of Chumsky. Hopefully when it comes time for the official 1.0.0 release, it will just be a simple replacement of
1.0.0-alpha.4
withlatest
, but even if not, I'll fix the broken links.I tried to pay special attention to the links to make sure that every one of them works and sends to the right place. If one is broken, please let me know and I will get to it when I can.
Thanks for your time!