-
-
Notifications
You must be signed in to change notification settings - Fork 275
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
setParseAction not returning expected exception #251
Comments
I tried to reproduce this with the following code:
And got this output:
Can you post some code that illustrates this issue for you? |
Took some time to find out where the problem is.
|
I looked a little further at this, and tried to simplify your grammar just down to the expression you are passing to infixNotation, and I think this is more an issue with MatchFirst ('|' operator):
Prints:
I tracked this change down to a fix made in August 2019, but was not rolled into the 2.4.7 release. The issue the fix was for was releated to the Each class, but I replicated it to the MatchFirst and Or classes also. Now rethinking this... |
U R right. Took some time looking into the source code and got a few thoughts. Now the MatchFirst behave as treating "post-parse action" as part of a parser, which will not handle FatalException raised in action (though already matched) until all the possibility are exausted. Problem is, if the latter pattern of a "MatchFirst" is a superset of a part of a before pattern, the expected Fatal message will not be raised. Because the latter pattern will return successfully with only matching a part of the string, bypassing the original expected info, while rest of the string produce a "Expected end of text ...." error.
Maybe just use the old fashion and raise Fatal immediately? Otherwise the Fatal Exception and Normal Exception do not have any difference. |
Released in 3.0.0rc2 |
pyparsing verison: 3.0.0b1
python version: 3.8.2
I am using setParseAction to do some validation and changing to the parsed result.
In validation, I might
raise ParseSyntaxException('some customized info')
and expect to catch the exception in parsing outside withcustomized info
It worked as expected when I was using
pyparsing==2.4.5
.But in 3.0.0b1, the exception I catch is constantly
ParseException
with my customized info being replaced by normalloc,ori_sql,msg
info. Is that a expected feature or a bug?The text was updated successfully, but these errors were encountered: