Tips on how to learn to use Chumsky? #879
Replies: 1 comment 1 reply
-
|
The best advice I can give is to work incrementally. Start off with a simple base (maybe one of the examples!) and iterate toward your goal. Regularly check that the thing continues to compile. Make use of the doc examples too: they might be contrived, but they give you a flavour of how you might combine parsers together to achieve your goal. Once you have a parser you're happy with, name it! There's no reason to bundle parsers together into one nameless mass. You can use a The guide has some useful information. In particular, the 'Getting Started' page has a section about strategies for dealing with compilation errors. In terms of building up a parser, you'll want to start with a rough description of your language that splits things up into parts. Chumsky parsers will often look at lot like their equivalent BNF grammars and it's often useful to start with such a description and translate it incrementally, starting with the smallest elements. You might also find the tutorial a nice introduction: it walks through the process of creating a parser 'from the bottom up'. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
(Apologies in advance for the vague nature of my question, but I'm not sure how else to word it...)
I'm trying to learn Chumsky by implementing a toy programming language, and I'm having a lot of trouble making progress. I've read the guide, a lot of the API docs, and a lot of the examples, but I still encounter frequent indecipherable error messages from the compiler. Short of having a mentor that knows the library better than I do to work alongside me, I'm not sure what to do, as brute force doesn't seem to be getting me far enough.
The debugging chapter of the guide is currently empty. There's a small section in the getting started chapter on compiler errors, but not enough to get me over the roadblocks I hit. In particular, the third bullet point talks about the dreaded "type doesn't implement Parser" error, but I don't really understand what to do to "fulfill the obligations that come with implementing the trait" in most cases. It would be helpful to show specific code examples that trigger this error, explain why that particular case triggered it, and then how to fix it.
I've also tried using the
simplifymethod, but all that seems to do is make the type name shorter by using impl Trait—it doesn't provide any additional information (as far as I can tell) about how to resolve the problem.I've been looking a lot at the "nano_rust" example program, as it's the most similar to my toy language of the examples. My experience so far has been that when I stick to basically copying the example, things work, but as soon as I deviate to account for places where my language is different from the example, I get an indecipherable compiler error. It would be helpful if there were more comments in the example code explaining why it's organized the way it is. For example, an explanation of how an "expression" is different from an "inline expression" and why certain sub-parsers are part of one rather than the other. In my language I'm building it up slowly by having only one recursive parser for expressions, but I've ended up with an infinite recursion compiler error and I don't understand why. I'm trying to avoid blindly copying example code if I don't understand why it's there, but haven't had much luck when I try to simplify things.
Beta Was this translation helpful? Give feedback.
All reactions