Re: parsing, PEG parsers, and backtracking HTML templating: toward a bright parsing future (examples in OCaml, C++, and Ruby)

Dave Long <[email protected]> Mon, 16 Apr 2012 16:01:37 +0200
Newsgroups gmane.culture.people.kragen.discuss
Message-ID <[email protected]>
> One tricky part is backtracking: ... semantic actions must be  =

> prepared for the possibility that their results will be  =

> discarded. ... A straightforward [solution] is to limit your  =

> semantic actions to building ...an AST node, and [ensuring] the  =

> nodes get cleaned up if they=92re not needed.  In many cases, it  =

> would be nicer to be able to, say, emit bytecode into a buffer, but  =

> I=92m not sure what the interface to that would look like.

Hmmm.  I'd thought you were already in the (abstract) process of  =

building a quasiquoter  with alternative, potentially unused,  =

expansions: so I think you know what an interface might look like,  =

you just don't know if it's more trouble than it's worth to bootstrap...

-Dave

(emitting HTML or bytecode into a buffer is the monoidal string case;  =

building an AST is the monadic (monoidal endofunctor) case)
cf http://okmij.org/ftp/tagless-final/course/index.html
(semantic actions are popular because they're normally an effective  =

deforestation of the text -unfold-> AST -fold-> effects hylomorphism;  =

if you hooked up a pattern matcher in front of the semantic actions  =

it might be possible to come up with a tree-awk to decouple the  =

actions from the parsing, at the risk of reinventing xslt)

-- =

To unsubscribe: http://lists.canonical.org/mailman/listinfo/kragen-discuss