## digitalmars.D.announce - Pegged v0.4: longest-match, left-recursion, and expandable parse trees

- Philippe Sigaud (57/57) Mar 02 Hi,
- mogu (2/8) Mar 02 Excellent! I love pegged. Thanks for your brilliant works.
- lobo (2/7) Mar 02 Thanks! This is my all time favourite D library.
- Moritz Maxeiner (4/10) Mar 03 Thank you very much for Pegged, if I end up choosing D for the
- Philippe Sigaud (1/1) Mar 03 Thank you all for the positive comments!
- Bastiaan Veelo (3/4) Mar 03 Indeed, I subscribe to that! (Literally, I am subscribed to this

Hi, Pegged is a parser generator based on Parsing Expression Grammars (PEG) written in D, that aims to be both simple to use and work at compile-time. See: https://github.com/PhilippeSigaud/Pegged To use Pegged, just call the grammar function with a PEG and mix it in your module. For example: import pegged.grammar; mixin(grammar(` Arithmetic: Term < Factor (Add / Sub)* Add < "+" Factor Sub < "-" Factor Factor < Primary (Mul / Div)* Mul < "*" Primary Div < "/" Primary Primary < Parens / Neg / Pos / Number / Variable Parens < "(" Term ")" Neg < "-" Primary Pos < "+" Primary Number < ~([0-9]+) Variable <- identifier `)); This will create the `Arithmetic` parser, that can parse your usual arithmetic expresion at runtime or compile-time. // Parsing at compile-time: enum parseTree1 = Arithmetic("1 + 2 - (3*x-5)*6"); // Runtime: auto parseTree2 = Arithmetic("1 + 2 - (3*x-5)*6"); ----- This minor release v0.4 (v0.4.1 right now) is on dub (code.dlang.org) right now and introduces the following new features: * A longest-match alternation operator, |, which will always choose the longest match during a parse. See [https://github.com/PhilippeSigaud/Pegged/wiki/Extended-PEG-Syntax] for more details and the interest of this operator for grammar writers. * The left-recursion engine, introduced in version v0.3.0 is now fully documented in the wiki at [https://github.com/PhilippeSigaud/Pegged/wiki/Left-Recursion]. Pegged can deal with left recursion, hidden left recursion and indirect left recursion. Try it! * These improvements allow Pegged to generate a parser that fully parses Extended Pascal files, based on the official ISO 10206:1990 grammar. Have a look at it in the [https://github.com/PhilippeSigaud/Pegged/tree/master/pegged/examp es/extended_pascal] directory. * The new toHTML function can be used to generate an HTML file containing an expandable tree view that can be manipulated with an HTML5-compliant browser. See [https://github.com/PhilippeSigaud/Pegged/wiki/Parse-Result] for more details on this new fun way to explore parse results (and parse failures!). Pegged documentation can be found on the wiki [https://github.com/PhilippeSigaud/Pegged/wiki], along with a tutorial [https://github.com/PhilippeSigaud/Pegged/wiki/Pegged-Tutorial]. Thanks a lot for Bastiaan Veelo for these wonderful improvements to Pegged!

Mar 02

On Thursday, 2 March 2017 at 20:42:56 UTC, Philippe Sigaud wrote:Hi, Pegged is a parser generator based on Parsing Expression Grammars (PEG) written in D, that aims to be both simple to use and work at compile-time. See: https://github.com/PhilippeSigaud/Pegged ...Excellent! I love pegged. Thanks for your brilliant works.

Mar 02

On Thursday, 2 March 2017 at 20:42:56 UTC, Philippe Sigaud wrote:Hi, Pegged is a parser generator based on Parsing Expression Grammars (PEG) written in D, that aims to be both simple to use and work at compile-time. [...]Thanks! This is my all time favourite D library.

Mar 02

On Thursday, 2 March 2017 at 20:42:56 UTC, Philippe Sigaud wrote:Hi, Pegged is a parser generator based on Parsing Expression Grammars (PEG) written in D, that aims to be both simple to use and work at compile-time. See: https://github.com/PhilippeSigaud/Pegged [...]Thank you very much for Pegged, if I end up choosing D for the implementation part of my master thesis, Pegged will be very helpful to me.

Mar 03

On Friday, 3 March 2017 at 20:37:33 UTC, Philippe Sigaud wrote:Thank you all for the positive comments!Indeed, I subscribe to that! (Literally, I am subscribed to this thread :-))

Mar 03