Skip to content

Instantly share code, notes, and snippets.

@ingydotnet
Created September 26, 2011 23:44
Show Gist options
  • Save ingydotnet/1243786 to your computer and use it in GitHub Desktop.
Save ingydotnet/1243786 to your computer and use it in GitHub Desktop.
Pegex rules are of the form:
name: /foo/ [ <bar> | `baz` ]
/foo/ - is a pcre regex.
<bar> - is a named subrule.
`baz` - is an error msg
[ ] - is a sub group
Some of the above can have prefixes and suffixes:
name: <a>? <b>* <c>+ !<d> =<e> .<f> +<g> -<h> .<i>*
[ <j> <k>]?
?*+ - are obvious
! - negative lookahead
= - positive lookahead
. - ignore if no action
+ - force wrap action
- - force no wrap action
I currently have a separator operator:
name: <a> ** <b>
and I can do zero or more with:
name: [ <a> | <b> ]? ** <c>
Since the ?*+ of the two sides are not very important in this use case, I just
special cased that. Note I used a gratutitous group in the last example to
show I can do that too.
Given my setup, I am now inclined to not allow suffixes on the left or right operands and to do all the use cases with the infix operator.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment