neogeny / TatSu

竜 TatSu generates Python parsers from grammars in a variation of EBNF
https://tatsu.readthedocs.io/
Other
408 stars 48 forks source link

Make TatSu also accept PEG syntax #126

Open apalala opened 5 years ago

apalala commented 5 years ago

The TatSu grammar syntax is the result of the experience with parsing several major programming languages. Common constructs have shortcuts that help in building ASTs.

For people coming from other parser generators or wanting to experiment with different ones, it would be good if their grammar in standard PEG syntax was understood by TatSu.

Another syntax that TatSu could accept is standard EBNF.

Victorious3 commented 5 years ago

I've come to like Tatsu's syntax. I think its just close enough to EBNF, the only real difference I see is that it allows having spaces in non terminals, which sounds like an awful idea considering python identifiers don't. To quote Wikipedia:

The International Organization for Standardization adopted an EBNF standard (ISO/IEC 14977) in 1996. However, according to Zaytsev this standard "only ended up adding yet another three dialects to the chaos" and, after noting its lack of success, also notes that the ISO EBNF is not even used in all ISO standards. Wheeler argues against using the ISO standard when using an EBNF, and recommends considering alternative EBNF notations such as the one from the W3C Extensible Markup Language (XML) 1.0 (Fifth Edition).

It does look a lot like Wirth's EBNF: https://en.wikipedia.org/wiki/Wirth_syntax_notation ... except for the semicolon. Buggers.

As for PEG, is there even a standard around for that? There's / for ordered choice but so far I've seen every parser generator make some additions (https://github.com/PhilippeSigaud/Pegged/wiki/Extended-PEG-Syntax for reference) and the rest looks close enough to Tatsu again.

In short, I don't think it's worth it.