-
-
Notifications
You must be signed in to change notification settings - Fork 183
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
Panic when stateful lexer's non-Root rule has optional group but captures nothing #324
Comments
I think this is probably occurring because Participle allows you to use references like |
Mm actually sorry, I misread. That might not be it. Try using a non-capturing group and see if that fixes it: |
Yes, change pattern to non-capture will fix this, actually, it is the workaround I'm using in my real project. |
Above example shows a common design: assume we have some keyword (
x
in this example), so it can not be parsed as aIdent
in whole program, we want use a special symbol%
to remove this limit: if prefix with%
, allow use a keyword asident
.When testing it,
aa + bb
is parsed succefully,x + y
will failed becausex
is a keyword, not aident
, as excepted.Next it parse
%x + y
, and panic.If we change pattern of
ident
to[[:alpha:]][[:alnum:]]*
(Just remove the inner group, or add?:
make it non-capture), it will works fine.Test code
Maybe caused by here, the pattern of
Ident
callFindStringSubmatchIndex
with datax + y
will return a[0, 1, -1, -1]
, the last two-1
means the inner group([[:alnum:]])
never captures:The simplest way to fixes this may be add a guard:
But I'm not sure how this group intergrate with Action interface, may be it needs some type to indicate the empty capture? So I just open this issue, not a PR.
The text was updated successfully, but these errors were encountered: