Closed dragostis closed 12 months ago
Any idea what grammar would be useful as example there?
I was thinking something simpler. Maybe YAML? Lua could also work, but that would be quite a bit involved.
YAML is not a simple grammar. 😢 http://yaml.org/spec/1.2/spec.html
It has different whitespace rules (meaningful vs ignored) depending on "styles" (block vs flow). Which can change multiple times in the same document. And that is just the tip of the iceberg... ðŸ˜
Python is considered a simple grammar as it is designed to be LL(1) but maybe a little big for a sample.
A calculator example is also useful as it demonstrates usage of binary operators and precedence.
@bd82 I wasn't aware of how complex it is. How about ABNF? Or PROLOG? Or TinyC?
TinyC looks like a good example as it has both statements and expressions with binary operators while being very "tiny" 😄 https://github.com/antlr/grammars-v4/blob/master/tinyc/tinyc.g4
@bd82 TinyC it is, then.
@bd82 Has anyone started tackling this yet? I've been thinking about making the TinyC the object of the tutorial, which would ultimately lead to its implementation.
@dragostis What? Who? How? Why? 😄
I'm just participating in the discussion here as an author of another parsing library(In JavaScript) because tracking other similar projects leads to good ideas...
I'm afraid I don't know Rust or currently have plans to implement the TinyC grammar in Pest. 😢
What I can recommend is that if you do make it part of the tutorial ensure there is also a pure code version that always runs as part of your CI/tests. This pure code version should also be linked from the tutorial in case APIs breaks overtime and the tutorial is not updated or if someone has difficulty assembling the tutorial snippets into a working version.
@dragostis I don't really have time to tackle it before next weekend, so if this is something that someone picks up in the meantime, well, there's no issue here.
@bd82 Rust has the concept of being able to compile and test the code samples that are in the documentation, so having a separate pure code version isn't even necessary and CI would ensure that all samples in the tutorial work. (Rust is awesome like that.) But yes, good advice.
Rust has the concept of being able to compile and test the code samples that are in the documentation
Nice! Maybe I should learn some Rust 😄
@bd82 Nice work with Chevotrain! I'm definitely considering that, but it's currently a bit complicated since the example requires quite a bit of work.
Definitely give Rust a chance if you have the time. The tooling is very well integrated and the ecosystem is blooming!
@passcod I'm going to try and go for the tutorial with the TinyC grammar, but feel free to add another grammar to the bunch, even something more involved. With time, it would be nice to have as many grammars as possible.
I'm taking a stab at writing an ANTLR grammar in pest, for the purpose of translating ANTLR grammars into pest ;)
@dchenbecker I've actually been thinking about tackling this particular issue for some time. I think that a two-way translation (if possible) would be greatly beneficial.
There are some semantic differences which could make the translation more difficult.
Antlr has a separate tokenizing as opposed to PEG which is lexerless. This means that issues such as distinguishing keywords vs identifiers or ignoring whitespace are handled differently.
@bd82 I agree on there being some big differences (ignoring whitespace in particular is a big change). I don't think I'll be able to translate it 1-to-1 without a lot of effort, but if I can get 90% there it will make generating a new grammar that much simpler.
but if I can get 90% there it will make generating a new grammar that much simpler.
Yeah it could certainly help, you may want to add some documentation on common pitfalls & edge cases in translating the last 10%.
Not sure if this would be helpful, but I'm almost done writing a pest parser for the wip FontoBene stroke font format: https://github.com/fontobene/fontobene-rs The advantage of the parser is that it's quite simple, on the other hand the format is not something well-known. But if you wanted, you could use it as an example once it's done.
You can find an example FontoBene file here: https://github.com/fontobene/fontobene-rs/blob/master/src/tests/fonts/standard.bene
I'm taking a stab at writing an ANTLR grammar in pest, for the purpose of translating ANTLR grammars into pest ;)
I recently did this with the HTML Antlr grammar. In case anyone finds it useful
I've created a C-ish grammar for one of my classes, could this work? https://github.com/jkarns275/mini-rust-parser/blob/master/parser/src/c.pest
@jkarns275, I'd rather have something simpler than C for now.
pest_grammars already has three grammars: https://github.com/pest-parser/pest/tree/master/grammars/src/grammars so closing this issue, but anyone is welcome to contribute more for sure!
It would be nice to have an extra grammar in
pest_grammars
before launching 1.0.