-
-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lookahead groups #145
Lookahead groups #145
Conversation
Tests kept to be used for the replacement syntax
Also adds test coverage for syntax errors in groups
Oh and I also found some bugs where wrong grammar syntax in negation or captures could lead to the grammar building successfully but then failing during runtime with a nil dereference error. |
Probably review by commits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really nice, and super useful, thanks for doing this.
@@ -155,7 +155,8 @@ The grammar format is: | |||
- `<expr> <expr> ...` Match expressions. | |||
- `<expr> | <expr> | ...` Match one of the alternatives. Each alternative is tried in order, with backtracking. | |||
- `!<expr>` Match any token that is _not_ the start of the expression (eg: `@!";"` matches anything but the `;` character into the field). | |||
- `!?<expr>` Negative lookahead - the sequence will not match if this expression matches (lookahead won't be consumed) | |||
- `(?= ... )` Positive lookahead group - requires the contents to match further input, without consuming it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe move these up under group, though not a big deal.
@@ -0,0 +1,40 @@ | |||
package participle_test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Int int `| @Int` | ||
} | ||
type op struct { | ||
Op string `@('+' | '*' (?= @Int))` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, this will be super useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, I couldn't actually find a good example of what to use positive lookahead for, the best I could quickly come up with was this rather silly test. But it was easy to have positive lookahead supported when I was refactoring negative lookahead anyway, so I thought why not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah good point, with Participle's backtracking it's not super useful...
Partially reverts my changes from #144 to change the negative lookahead syntax from
!? <expr>
to(?! <expr> ...)
, in order to have syntax consistent with PERL-like regular expressions. Also adds support for positive lookahead groups, because why not.Relates to #134