pest-parser / pest

The Elegant Parser
https://pest.rs
Apache License 2.0
4.6k stars 258 forks source link

Add third grammar #125

Closed dragostis closed 10 months ago

dragostis commented 7 years ago

It would be nice to have an extra grammar in pest_grammars before launching 1.0.

passcod commented 7 years ago

Any idea what grammar would be useful as example there?

dragostis commented 7 years ago

I was thinking something simpler. Maybe YAML? Lua could also work, but that would be quite a bit involved.

bd82 commented 7 years ago

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.

dragostis commented 7 years ago

@bd82 I wasn't aware of how complex it is. How about ABNF? Or PROLOG? Or TinyC?

bd82 commented 7 years ago

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

dragostis commented 7 years ago

@bd82 TinyC it is, then.

dragostis commented 7 years ago

@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.

bd82 commented 7 years ago

@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.

passcod commented 7 years ago

@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.

bd82 commented 7 years ago

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 😄

dragostis commented 7 years ago

@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!

dragostis commented 7 years ago

@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.

dchenbecker commented 6 years ago

I'm taking a stab at writing an ANTLR grammar in pest, for the purpose of translating ANTLR grammars into pest ;)

https://github.com/antlr/grammars-v4/tree/master/antlr4

dragostis commented 6 years ago

@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.

bd82 commented 6 years ago

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.

dchenbecker commented 6 years ago

@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.

bd82 commented 6 years ago

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%.

dbrgn commented 6 years ago

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

nishtahir commented 6 years ago

I'm taking a stab at writing an ANTLR grammar in pest, for the purpose of translating ANTLR grammars into pest ;)

https://github.com/antlr/grammars-v4/tree/master/antlr4

I recently did this with the HTML Antlr grammar. In case anyone finds it useful

jkarns275 commented 5 years ago

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

dragostis commented 5 years ago

@jkarns275, I'd rather have something simpler than C for now.

tomtau commented 10 months ago

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!