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

trig Parser now raises SyntaxError, when finding nested graphs #2468

Merged
merged 3 commits into from Jul 5, 2023

Conversation

WhiteGobo
Copy link
Contributor

@WhiteGobo WhiteGobo commented Jul 4, 2023

Summary of changes

When loading trig-graph-bad-07.trig an exception should be raised.
I implemented a normal SyntaxError for this occasion.

The xfail for the corresponding test was removed.

Checklist

  • Checked that there aren't other open pull requests for
    the same change.
  • Checked that all tests and type checking passes.
  • If the change has a potential impact on users of this project:
    • Updated relevant documentation to avoid inaccuracies.
    • Considered adding additional documentation.
  • Considered granting push permissions to the PR branch,
    so maintainers can fix minor issues and keep your PR up to date.

@WhiteGobo
Copy link
Contributor Author

I havent checked if the Syntaxerror should be subclassed.

@coveralls
Copy link

coveralls commented Jul 4, 2023

Coverage Status

coverage: 90.901% (+0.01%) from 90.891% when pulling a6ca291 on WhiteGobo:trig-xfail-no-nested-graphs into 8582691 on RDFLib:main.

@aucampia
Copy link
Member

aucampia commented Jul 4, 2023

pre-commit.ci autofix

@aucampia
Copy link
Member

aucampia commented Jul 4, 2023

Thanks for the PR @WhiteGobo - I will check it in a bit more detail a bit later tonight but it looks good at a glance.

One concern may be that people prefer more lax parsers, but that can go too far [ref], and in this case, I definitely would much rather have the default be compliant with the spec and if someone wants it more lax we can consider adding an option to control parser behaviour to make it more lax; however, it is hard to see who would want it in this case.

@aucampia
Copy link
Member

aucampia commented Jul 4, 2023

For reference, this is the test file in question:

# GRAPH tests
PREFIX : <http://example/>
# GRAPH and a triples block.
GRAPH :g {
:s :p :o .
GRAPH :g1 { :s1 :p1 :o1 }
}

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.

I'm going to fix the two issues I noted in comments on your branch.

Raise exception earlier and use `self.BadSyntax` for raising it.
@aucampia
Copy link
Member

aucampia commented Jul 4, 2023

I'm going to fix the two issues I noted in comments on your branch.

done now.

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.

Thanks for the fix, I'm not sure what was happening with the triples when nested graphs were encountered, but it could not have been good.

I will merge later this week if there is no more feedback.

@aucampia aucampia added review wanted This indicates that the PR is ready for review ready to merge The PR will be merged soon if no further feedback is provided. labels Jul 4, 2023
@aucampia aucampia requested a review from a team July 4, 2023 19:59
@WhiteGobo
Copy link
Contributor Author

Thx for the review. Ive felt really lost, when working on the Trig- and Notation3-Parser. I worked more with trial and error, than thinking:) Im much more confident with the parsers, that are written with pyparsing.

@aucampia
Copy link
Member

aucampia commented Jul 4, 2023

Thx for the review. Ive felt really lost, when working on the Trig- and Notation3-Parser. I worked more with trial and error, than thinking:) Im much more confident with the parsers, that are written with pyparsing.

We really should get rid of the hand-written parsers, I don't like working on it either. I think using https://github.com/lark-parser/lark would be best, as that allows generating parsers that don't need any runtime dependencies, but PyParsing is already a lot easier.

@aucampia aucampia merged commit afea615 into RDFLib:main Jul 5, 2023
22 checks passed
aucampia added a commit to aucampia/rdflib that referenced this pull request Aug 17, 2023
Raise an error when nested graphs occur in TriG.

With this change, the <http://www.w3.org/2013/TriGTests/#trig-graph-bad-07> test passes.

---------

Co-authored-by: WhiteGobo <richardfechner@posteo.net>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Iwan Aucamp <aucampia@gmail.com>
@WhiteGobo WhiteGobo deleted the trig-xfail-no-nested-graphs branch September 24, 2023 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to merge The PR will be merged soon if no further feedback is provided. review wanted This indicates that the PR is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants