I'm working on my PEG parser, in particular the interface between
the parse tree and the code one can attach to productions that
are executed on a successful parse.

I've arranged for the two predicate operations, & and !, to not add
any output to the parse tree.  That means that the following
production:

  rule <- &a !b "c"

Produces the same parse tree as:

  rule <- "c"

Internally, this means that I recognize that the sequence operator
(which contains the productions '&a', '!b', and '"c"' in this
example) is being called with predicates in every position but one,
and rather than returning a list containing that single element,
I return just the single element.

As I've been doing this, I've found that I want a new operator similar
to '&'.  '&' matches the production it is attached to, but it does not
advance the position of the input buffer.

I'd like an operator that matches the production it is attached to,
advances the input buffer, but doesn't add anything to the parse
tree.

Here's an example:

  mulexp <- digit '*' digit EOF -> {(lambda (x y) (* x y))}

the mulexp production is a sequence of four other rules, but only
two of them are needed by the associated code.  It would be nice
if I could write the code rule like it is above, rather than say
this:

  (lambda (x op y EOF) (* x y))

Having to account for all the rules in the sequence, but really 
only caring about two of them.  Here is the example rewritten
with '^' expressing "match the rule, advance the input, but don't
modify the parse tree":

  mulexp <- digit ^'*' digit ^EOF -> {(lambda (x y) (* x y))}

Before I go inventing syntax for this use case, will you tell me if
this is already being done with other parsers?  Have any of you had
this problem and already solved it, and if so, what approach did you
take?

-Alan
-- 
.i ko djuno fi le do sevzi

_______________________________________________
PEG mailing list
PEG@lists.csail.mit.edu
https://lists.csail.mit.edu/mailman/listinfo/peg

Reply via email to