-
-
Notifications
You must be signed in to change notification settings - Fork 276
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
locatedExpr naming doesn't work when it's alone #294
Comments
Ok, I think I've got this sorted out. There are some issues in your example code, but it also helped me find a bug in the to-be-released Located class. First off, you have locatedExpr used in too many places. For simplicity, I changed regex_to_find to just the Regex expression:
Then, to maintain the naming structure that is implied in your parse action, I defined r in the parse() method as:
If we don't Group the expressions when adding a second results name, then the names clash with each other. (And of course, added the parseWithTabs() call.) I think with those 2 changes, locatedExpr works as you would like. When I went to replace it with the new Located class, I did find a bug, so this was very helpful there, thanks! Finally, it looks like you are implementing your own flavor of transformString. You could implement most of this code with the following:
|
Closing due to inactivity, but go ahead and reopen if you have further comments or questions. |
Sorry for silence, and thank you for resolving this. I recall back when you posted the comment I tried to do some experimentation, but haven't finished it due to lack of time. Anyway, since I haven't posted any questions, I presume it is alright. Thank you again for looking into this! |
This was found while creating a minimal testcase for #293. The testcase is basically the same code except I removed the second empty
locatedExpr
.The problem is that, when you create a named
locatedExpr
as inlocatedExpr(Regex(r'some text'))('line1')
, it can only be called byline1
name if you add another expression to it. Otherwise referring byline1
will cause aKeyError: 'line1'
Steps to reproduce
Expected
There is no KeyError
Actual
There is KeyError
Additional information
pyparsing version: 2.4.7
The text was updated successfully, but these errors were encountered: