Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

veyndan
Copy link
Contributor

@veyndan veyndan commented Oct 24, 2022

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. Replacing ParamList with the built-in Group operator simplifies the ability to understand how a SPARQL query is being parsed.

In order to replace ParamList with Group, I just did a find and replace of ParamList(foo) with Group(Param(foo)). Perhaps replacing instances of ZeroOrMore(ParamList(foo)) should be replaced with Group(ZeroOrMore(Param(foo)) instead of ZeroOrMore(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

  • Checked that there aren't other open pull requests for the same change.
  • Checked that all tests and type checking passes.
  • Considered granting push permissions to the PR branch, so maintainers can fix minor issues and keep your PR up to date.

@coveralls
Copy link

coveralls commented Oct 24, 2022

Coverage Status

Coverage remained the same at 90.631% when pulling 65f5d4c on veyndan:rm-ParamList into 6eec3bd on RDFLib:main.

# res.update(t)
if isinstance(t, ParseResults):
for i in t:
if isinstance(i, ParamValue):
Copy link
Member

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?

Copy link
Contributor Author

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 ParamValues, but they should all be ParamValues. Fixed in latest commit.

Copy link

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.

Copy link
Contributor Author

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.

Copy link
Member

@aucampia aucampia left a 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.

@aucampia aucampia requested a review from a team November 14, 2022 22:48
@veyndan
Copy link
Contributor Author

veyndan commented Nov 20, 2022

@aucampia Is this okay to merge?

@ptmcg
Copy link

ptmcg commented Nov 20, 2022

I have a few more comments to make on the use of Group, which I'll try to write up this evening.

@ptmcg
Copy link

ptmcg commented Dec 12, 2022

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 Group. Please look it over (comments and suggestions welcome!), and if you like, we can discuss in more detail how this relates to ParamList in your parser.

@aucampia
Copy link
Member

Thanks @ptmcg , I will have a look.

@veyndan sorry I have been a bit busy, will try look again this week and process the inputs from @ptmcg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants