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

Feature: callback and event for comments #423

Merged
merged 14 commits into from
Aug 26, 2024

Conversation

pietercolpaert
Copy link
Member

For my project I need access to the comments in a turtle (etc.) file.

This pull request:

  1. extends the N3Parser.parse function with an optional commentCallback. If set, the lexer’s configuration will be overridden to also provide comment tokens.
  2. extends the N3StreamParser with a "comment" event in a separate commit

Copy link
Member

@RubenVerborgh RubenVerborgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Pieter!
Some quick highlights; should definitely check performance impact.
We can likely omit most of the code comments.

src/N3Parser.js Outdated
// ### `parse` parses the N3 input and emits each parsed quad through the callback
parse(input, quadCallback, prefixCallback) {
// ### `parse` parses the N3 input and emits each parsed quad through the callback. Optionally you can set a prefixCallback and a commentCallback
parse(input, quadCallback, prefixCallback, commentCallback) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're getting too many arguments here; let's support:

  • parse(input, onQuad)
  • parse(input, onQuad, onPrefix)
  • parse(input, { onQuad, onPrefix, onComment })

the first two of which are for legacy compatibility.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, will amend my PR accordingly

src/N3Parser.js Outdated Show resolved Hide resolved
src/N3Parser.js Outdated Show resolved Hide resolved
@RubenVerborgh
Copy link
Member

Note that the slightly weird suggestions here are because this parser is written quite close to the V8 engine; some functions execute 200,000+ times per second, so every if and === matter.

@pietercolpaert
Copy link
Member Author

All comments have been processed. At your own convenience, can you give this PR another review?

Copy link
Member

@RubenVerborgh RubenVerborgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CI is not kicking in, weird.

Mostly okay, but we'll need the result from the performance tests (they're in the repo). What is the difference? The streaming parser has unconditional comments currently, so there would be a penalty (but the perf tests aren't looking for them unfortunately).

src/N3Lexer.js Outdated Show resolved Hide resolved
src/N3Parser.js Outdated Show resolved Hide resolved
src/N3Parser.js Outdated Show resolved Hide resolved
src/N3StreamParser.js Outdated Show resolved Hide resolved
@pietercolpaert
Copy link
Member Author

I made emitting comments in the streamparser optional and not the default now.

Copy link
Member

@RubenVerborgh RubenVerborgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks—I think I'm happy, I'll just have another pair of eyes on this!

test/N3Parser-test.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@jeswr jeswr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI can be seen at https://github.com/pietercolpaert/N3.js/tree/feature-comments; please fix coverage issues.

Beyond that LGTM. When done please squash merge with commit message starting with feat: so semantic release runs correctly.

jeswr and others added 2 commits August 25, 2024 09:02
Co-authored-by: Ruben Verborgh <ruben@verborgh.org>
@pietercolpaert
Copy link
Member Author

Thanks @jeswr and @RubenVerborgh for the extremely fast and thorough review process!

I’ve added some tests just now that fix the coverage. It appeared locally the coverage didn’t trigger due to other experimental tests I was running that did cover the line.

Squashing is something @RubenVerborgh will do?

Should I also add documentation in the README.md on how to enable comments?

@jeswr
Copy link
Collaborator

jeswr commented Aug 25, 2024

Should I also add documentation in the README.md on how to enable comments?

Yes, that would be a good idea! Ruben and I both have permission to merge so can do that once the new documentation is added.

@pietercolpaert
Copy link
Member Author

Added the documentation in the README.md, finalizing this PR!

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@jeswr jeswr merged commit 881d0aa into rdfjs:main Aug 26, 2024
1 check passed
@jeswr
Copy link
Collaborator

jeswr commented Aug 26, 2024

Thanks for your work @pietercolpaert !

Copy link

🎉 This PR is included in version 1.21.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@RubenVerborgh
Copy link
Member

Limitation: timing of comment event in StreamParser is unreliable as it is unsynchronized. #440

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

Successfully merging this pull request may close these issues.

3 participants