-
Notifications
You must be signed in to change notification settings - Fork 560
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
Replace ParamList with Group #2142
base: main
Are you sure you want to change the base?
Conversation
# res.update(t) | ||
if isinstance(t, ParseResults): | ||
for i in t: | ||
if isinstance(i, ParamValue): |
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.
Could it make sense to raise an exception if this condition does not match?
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 I think that's a lot clearer, as otherwise it looks like we're filtering our for ParamValue
s, but they should all be ParamValue
s. Fixed in latest commit.
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.
Raising a TypeError here conflicts with this line in the docstring: "Any sub-tokens that are not Params will be ignored." So raising TypeError here may start breaking some existing code.
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.
I completely missed that! I'm not sure how true that line in the docstring is, but I think it's worth an investigation in a separate PR.
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.
@veyndan thanks for the PR and apologies for the late review. It looks correct to me but I'm going to try get someone with some knowledge of pyparsing
to also weigh in and do another review after thinking about it a bit, but I think this approach is significantly better than using a custom class.
03c2ae7
to
c79ecc2
Compare
@aucampia Is this okay to merge? |
I have a few more comments to make on the use of Group, which I'll try to write up this evening. |
It has been a hairy few weeks, I'm sorry this took so long. I've started a new page in the pyparsing wiki for pyparsing design topics, with the first topic about using |
Summary of changes
No functional changes. I've wanted to better understand the parsing of SPARQL, and have found that
ParamList
makes the parsing unnecessarily more complex. ReplacingParamList
with the built-inGroup
operator simplifies the ability to understand how a SPARQL query is being parsed.In order to replace
ParamList
withGroup
, I just did a find and replace ofParamList(foo)
withGroup(Param(foo))
. Perhaps replacing instances ofZeroOrMore(ParamList(foo))
should be replaced withGroup(ZeroOrMore(Param(foo))
instead ofZeroOrMore(Group(Param(foo))
, but I'm not too sure of the benefits of one over the other, so I instead opted for what semantically matches what we had prior to this change.Checklist