Annex C (informative) ABNF Grammar

This Annex documents the Augmented Backus-Naur Form (ABNF) grammar for PURL strings.

A valid PURL string adheres to the following grammar with the syntax defined according to RFC 5234: Augmented BNF for Syntax Specifications: ABNF.

PURL = scheme ":" type
       [ "/" namespace ] "/" name
       [ "@" version ] [ "?" qualifiers ] [ "#" subpath ]

; --- structure ---

scheme = %x70.6B.67 ; constant with the value "pkg" (lowercase only)

type = alpha-lc *( alpha-lc / DIGIT / "." / "-" )

namespace = namespace-segment *( "/" namespace-segment )
namespace-segment = 1*pchar-ns

name = 1*pchar

version = 1*pchar

qualifiers = qualifier *( "&" qualifier )
qualifier = qualifier-key "=" qualifier-value
qualifier-key = alpha-lc *( alpha-lc / DIGIT / "." / "-" / "_" )
qualifier-value = 1*pchar

subpath = subpath-segment *( "/" subpath-segment )
subpath-segment = subpath-segment-sc *pchar-ns ; no leading "."
                / "." subpath-segment-sc *pchar-ns ; forbid segment "."
                / ".." 1*pchar-ns ; forbid segment ".."
                       ; excludes the exact segments "." and ".."
subpath-segment-sc = ( alphanumeric
                     / "-" / "_" / "~"
                     / colon ) ; = `unreserved` without "."
                   / pct-encoded-ns
                          ; safe characters

; --- character classes ---

alpha-lc = %x61-7A ; lowercase a-z
alphanumeric = ALPHA / DIGIT
punctuation = "." / "-" / "_" / "~"
separator = ":" / "/" / "@" / "?" / "=" / "&" / "#"
colon = ":"
percent = "%"

unreserved = alphanumeric / punctuation / colon
reserved = "/" / "@" / "?" / "=" / "&" / "#"

; `reserved` and `separator` are not referenced directly;
; listed to document characters that require percent-encoding

pchar = unreserved / pct-encoded
pchar-ns = unreserved / pct-encoded-ns
; `-ns` suffix = variant that forbids the percent-encoded slash ("%2F")

; --- percent-encoding ---

pct-encoded = pct-encoded-ns / percent "2" "F"
pct-encoded-ns = percent (
                      ( "0" / "1" ) HEXDIG
                         ; %00-1F
                    / "2" ( DIGIT / "A" / "B" / "C" )
                         ; %20-2F except %2D ("-") and %2E (".") and %2F ("/")
                    / "3" ( "B" / "C" / "D" / "E" / "F" )
                         ; %30-3F except %30-39 (0-9) and %3A (":")
                    / "4" "0"
                         ; %40-4F except %41-4F (A-O)
                    / "5" ( "B" / "C" / "D" / "E" )
                         ; %50-5F except %50-5A (P-Z) and %5F ("_")
                    / "6" "0"
                         ; %60-6F except %61-6F (a-o)
                    / "7" ( "B" / "C" / "D" / "F" )
                         ; %70-7F except %70-7A (p-z) and %7E ("~")
                    / ( "8" / "9" / "A" / "B" / "C" / "D" / "E" / "F" ) HEXDIG
                         ; %80-FF
                    )

Conformance to this grammar for valid PURL strings is necessary but not sufficient because the following constraints of this Standard are not expressible in ABNF. These constraints apply in addition to the grammar.