newLISP Fan Club

Forum => newLISP in the real world => Topic started by: newland on September 15, 2014, 01:20:42 PM

Title: PEG and template system?
Post by: newland on September 15, 2014, 01:20:42 PM
Hi,



I'm wondering, is there something like the PEG implementation of guile:



https://www.gnu.org/software/guile/docs/master/guile.html/PEG-Parsing.html



That would allow to define templates and to define parsing rules for e.g. the wiki, without using regular expressions.  Probably slower, but probably also easier to read.



thanks,



newland
Title: Re: PEG and template system?
Post by: TedWalther on September 15, 2014, 03:05:16 PM
Interesting.  Are PEG related to the Scheme Regular Expressions that the Scheme crowd created a few years ago as the superior alternative to regular expressions?



http://srfi.schemers.org/srfi-115/srfi-115.html#Abstract



Or the Structural Regular Expressions designed by Rob Pike?



http://doc.cat-v.org/bell_labs/structural_regexps/se.pdf
Title: Re: PEG and template system?
Post by: newland on September 16, 2014, 02:13:26 AM
Hi,



The scheme regex or Pike's system are not related to PEG's.  A PEG is a top down parsing language, and you can use it to parse data or (small) command languages.  A PEG often looks like a BNF , so making it quite easy to read and write.  In contrast, simple regexes are easy to write and work fast, but complicated regexes are difficult to write and nearly impossible to decipher.  Lua also has a quite nice PEG implementation.







https://en.wikipedia.org/wiki/Parsing_expression_grammar



https://en.wikipedia.org/wiki/Backus–Naur_Form
Title: Re: PEG and template system?
Post by: newland on September 16, 2014, 03:05:27 AM
Hi,



forgot to add this link: http://www.inf.puc-rio.br/~roberto/docs/ry10-01.pdf on how to write regex equivalent in PEG.  That article gives  some motivation why PEG's are sometimes easier.
Title: Re: PEG and template system?
Post by: cormullion on September 17, 2014, 08:16:22 AM
https://github.com/dahu/nlpeg ?