Another possibility is to allow commit points in grammars. Imagine Prolog's 
cut operator, but used instead used as a way to say that once we're past 
some symbol 
in a phrase then if we fail to match the *production rule* then there has been 
a parse error.

Right now I'm working toward making a scanner generator to make scanners 
for my parser to use and I'm working on a grammar for regular expressions 
and this would be helpful. Consider the following example, where '!' is a 
commit point, and it is only seen as an error if then entire production rule 
fails (rather than one of the phrases failing):

CharacterClass
    : <open_bracket> ! <carrot> ^CharacterSet <close_bracket>
    ;

... this is another example, although more subtle as it would also involve 
more of my tree building routines as it will capture either a 'CharacterClass' 
or 'NegatedCharacterClass' as a root:

CharacterClass
    : <open_bracket> ! -NegatedCharacterClass <close_bracket>
    : <open_bracket> ! ^CharacterSet <close_bracket>
    ;

NegatedCharacterClass
    : <carrot> ^CharacterSet
    ;

Thoughts?



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

Reply via email to