Skip to content
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

Closed
wants to merge 4 commits into from
Closed

Chumsky: Getting a Book #442

wants to merge 4 commits into from

Conversation

Zij-IT
Copy link
Contributor

@Zij-IT Zij-IT commented Jun 8, 2023

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 with latest, 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!

@Zij-IT Zij-IT changed the title Feature/book Chumsky: Getting a Book Jun 8, 2023
@Zij-IT
Copy link
Contributor Author

Zij-IT commented Jun 8, 2023

So, I am not exactly sure what you would prefer to have happen with the guide, but given that the book ate it, I figured it was correct to remove guide.rs, and allow the tests to pass.

@zesterer
Copy link
Owner

zesterer commented Jun 12, 2023

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:

  • Examples can be checked with CI easily as regular doc tests
  • The guide can link directly to items in the crate itself, making navigation simpler
  • Documentation on crate items can link directly to relevant sections in the guide
  • Links between items in the guide and the crate can be checked automatically by CI.
  • Simpler CI: no need to host everything externally, have a dedicated static site, etc.
  • The guide automatically supports versioning and is tied to the implementation of the crate that it references

Comment on lines +53 to +61
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.
Copy link
Owner

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.

Comment on lines +1 to +38
# 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.
Copy link
Owner

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.

@Zij-IT
Copy link
Contributor Author

Zij-IT commented Jul 27, 2023

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.

@Zij-IT Zij-IT closed this Jul 27, 2023
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