spec: add grammar (ABNF)#578
Conversation
32049cf to
0a144bd
Compare
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
0a144bd to
6ca8acd
Compare
|
The ABNF is done according to latest spec, ready for review. possible followup: have a pipeline that checks the test-suite against that ABNF. |
ppkarwasz
left a comment
There was a problem hiding this comment.
@jkowalleck, thanks for submitting this!
I'll check it in detail later, right now these two problems show up:
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
There was a problem hiding this comment.
Thanks again for the PR! 🎉
I only spotted a couple of issues, the rest looks solid.
Random thought while reading: what if we defined a common set of productions for the basic character sequences, and then split things into two separate ABNF grammars: one for canonical PURLs and one for non-canonical PURLs?
The spec is very lenient about repeated slashes /: they’re allowed not just at the start, but also smack in the middle of a namespace or subpath. Basically, you could take a nap with your finger on the / key and still be fully PURL-compliant. 😴///😴///😴
If you fall asleep, you'll need a bigger screen to display the PURL, though. 😉
tha's not what the current spec says. purl-spec/PURL-SPECIFICATION.rst Line 149 in c53ba0e but not on the middle: purl-spec/PURL-SPECIFICATION.rst Lines 147 to 148 in c53ba0e |
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Co-authored-by: Piotr P. Karwasz <piotr@github.copernik.eu>
|
Hi @jkowalleck,
The spec doesn’t mention slashes in the middle explicitly, but the spec instructs parsers to ignore empty path segments, which are precisely what repeated slashes (///) represent. purl-spec/PURL-SPECIFICATION.rst Lines 390 to 398 in c53ba0e So in practice, multiple slashes are allowed anywhere (start, middle, or end), since they collapse during parsing. |
I understand, but this is not the right scope for your concerns. I've built the grammar based on the spec, and not on the parser-rules. |
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
|
@Scanteianu would you give this a review, since you opened package-url/community#24 |
I guess my first question is how one tests this? My proposal is to use Antlr, as then one can write a small test program in one of their 10 languages of choice (perhaps python?) to actually teat a large sample of strings against the grammar and validate output. |
Sure, you can translate the ABNF into anything and go from there. I was thinking of using something like https://pypi.org/project/abnf/ or https://sabnf.com/, or any tool that already understands ABNF. Mainly because I don’t want to introduce mistakes while translating ABNF into something else. |
ah, that pypi package might be the ticket. instead of working on porting it to antlr maybe I can use that package to generate a parser directly, and throw test cases at it that way. I can maybe fork this repo and make a branch in my fork where I do that on top of this branch. Antlr may be more flexible in terms of languages it supports, but I now understand your reasoning for wanting to use this format as the source of truth. Antlr can come later if/when needed. |
|
@jkowalleck I have opened jkowalleck#1 on your fork with the minimal implementation of a validator based on the parser. This seems to have found some issues somewhere in the last 2 rules in the grammar (ie: if i don't delete them it doesn't compile). I'd be super grateful if you fixed the grammar so it passes compilation (unfortunately I'm not an expert on abnf syntax or url encoding so i don't know exactly what's wrong). Once that's fixed I'm happy to run through all the other test cases and ensure the validator also passes. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
|
Could we move the discussion about the specific testing in jkowalleck#1 over to that PR’s own comment thread? To keep this PR (#578) focused and easier for everyone to follow, it would help if conversations about the POC, its test setup, or its implementation details continued in its own PR discussion instead of here. Thanks for helping keep the threads organized. |
|
I think it makes sense for one of the tests (arguably a python one since the existing scripts in this repo are python) to be merged along with the grammar, especially as it makes it easier for someone new coming along to see that the grammar is tested, and would help people in the future validate any changes to the grammar or validate that a pURL conforms to the grammar |
agree. eventually, we will have test scripts that automatically check the grammar against the test suites and vice-versa. But the things it've currently in preparation is noting planned for merging. it is done to see if the grammar is correct and adheres existing test suite. |
|
@prabhu crafted a purl parser that works directly from the ABNF .
need to review and triage them . below are soem remarks and notes for my future review and triage i need to prepare. main points seams to be about qualifier values and subpaths re: qualifier values
|
|
downstream implementations might use ABNF-based parser generators ... ooooor convert the ABNF to RegEx (once on build-time) and then use it for validation and parsing on run-time. ABNF to regex converters: |
|
with the latest comments in tickets and pull-requests here and there,
@mjherzog what do you think? PS: |
This PR defines the PackageURL grammar using ABNF.
ABNF is a standardized grammar notation defined in RFC 5234 and widely used across internet protocol specifications (HTTP, SIP, email, URI syntax, etc.). Unlike BNF, which exists in many incompatible variants, ABNF has a single, formal, and stable specification.
Because PackageURL is conceptually similar to URLs, using ABNF aligns the grammar with established internet standards. The IETF URL/URI specification (RFC 3986) also uses ABNF to define its syntax, so adopting the same notation keeps PackageURL consistent with the broader ecosystem of identifier formats.
ABNF is a notation for describing grammars, not a parser‑generator language like ANTLR or yacc. It is tool‑agnostic: various libraries can parse ABNF and generate validators or parsers from it, but the standard itself does not prescribe any specific generator. This makes ABNF a well‑recognized, interoperable choice for defining a grammar intended to be implemented across multiple languages and platforms.
Note
the state of the ABNF is not final - thats why it is in "draft" mode.
Especially the non-canonical form might be much too strict.
see #578 (comment) ff