On Mon, Jul 5, 2010 at 6:59 PM, Michael Lucy <michaelgl...@gmail.com> wrote: > On Mon, Jul 5, 2010 at 5:40 PM, Ludovic Courtès <l...@gnu.org> wrote: >> Hi! >> >> Thanks for the status report! >> >> Michael Lucy <michaelgl...@gmail.com> writes: >> >>> Files I've added so far: >>> guile/modules/ice-9/peg.scm (I assume this is the right place to put this?) >> >> No, it should rather go under ‘module/language/peg.scm’, for the sake of >> consistency with other compiler front-ends. But see below. > > I'm not quite sure how this qualifies as a compiler front-end. The > functionality is mostly done (if unoptimized), so it shouldn't be too > hard to turn it into one if that's what you want, but the original > thought was just to build a compiling parser. E.g.: > > (use-modules (ice-9 peg)) > (peg-find "'b'+" "aabbcc") > --> (2 4 "bb") > > It does this by compiling "'b'+" into a lambda expression that then > gets called on whatever the second argument is (the compilation is > done at read-time). So after macro-expansion, you have something > like: > ((lambda (...) ...) "aabbcc" ...) > > I was thinking of this as a sort of alternative to regular expressions > that also does parsing, and I noticed the regular expressions module > was in ice-9, so I put it there. > > Are you saying that the functionality that compiles "'b'+" to a lambda > expression should be broken out into a language module that instead > compiles it to TREE-IL code? Am I fundamentally misunderstanding > something? > >> >>> PEG compiler: Works for all the grammars I've tested, no known bugs. >>> Currently compiles to Scheme code rather than Tree-IL for debugging. >> >> It should rather compiler to tree-IL, like other front-ends, which is >> very close to Scheme anyway.
I think you are both misunderstanding eachother: - The PEG functions, useful in their own right, would be exposed as (ice-9 peg). - There is an additional syntax for expressing grammars, so it can be better used as a parser generator. That would go in as (language peg). That's just my take though. A personal whinge: I would like to be able to specify grammars in Scheme, using macros as the sugar instead of a different syntax. > > Alright, I'll fix that. > > Noob question: > The only way I can figure out to compile tree-il code is the rather ugly: > (compile (parse-tree-il '(code here)) #:from 'tree-il) > Is there a better way? I'm not sure if you mean generating tree-il code or just compiling the tree-il literals. If you want to generate it, use the record interface from (language tree-il), if you want to compile the literals, that's pretty much the way to do it. You can also do ,language tree-il at the REPL to experiment with it. Exciting stuff :) I can't wait to use this, maintaining my own hand-written recursive descent parser is like watching a trainwreck in slow motion.