Skip to main content

Grammar and comparison

Version: V2
View Markdown

Every IID has the form int:<scheme>:<value>. This page lists the syntax, the parsing rule that implementations most often get wrong and the three checks that make an identifier valid. The grammar is frozen permanently: it will never change within this specification. IID spec §1.5.1

Syntax​

iid     = "int" ":" scheme ":" value

scheme = 1*32 scheme-char
scheme-char = %x61-7A / DIGIT / "-" ; a-z, 0-9, hyphen

value = 1*220 value-char
value-char = %x21-7E ; visible ASCII, no space

IID spec §2.1

RuleRequirement
PrefixExactly int:, case-sensitive. INT: and Int: are not IIDs.
Scheme1–32 lowercase ASCII letters, digits or hyphens, and registered in the scheme catalog.
Value1–220 visible ASCII characters (0x21–0x7E). No spaces.
Total lengthAt most 256 bytes. This is the binding limit. The per-part maxima cannot both be reached in one IID.
Non-ASCII textNever appears raw. It enters only through a gen1 hash or a scheme-specific encoding, such as percent-encoding in a URL.

IID spec §2.2

Parse on the first two colons​

A parser splits on the first two colons only. Everything after the second colon is the value, including any further colons. Splitting on every colon is the most common implementation error. A generic parser also does not interpret structure inside the value. Only the scheme's own rules do that. IID spec §2.3

IIDSchemeValue
int:isbn:9780684832722isbn9780684832722
int:caip10:eip155:1:0xd8da6bf26964af9d7eed9e03e53415d37aa96045caip10eip155:1:0xd8da6bf26964af9d7eed9e03e53415d37aa96045
int:gen1:movie:r4:fb681afe7d438cad73ae90a70f1cc55agen1movie:r4:fb681afe7d438cad73ae90a70f1cc55a
int:hash:sha256:…hashsha256:…

Validate in three steps​

A string is a valid IID only when all three checks pass, in this order. IID spec §2.7

  1. Shape. Match the non-normative reference expression ^int:([a-z0-9-]{1,32}):([\x21-\x7E]{1,220})$ and check the 256-byte limit.
  2. Registered scheme. Reject the IID if its scheme is not in the registry, even when the string is otherwise well-formed. The registry is closed. Validators never pass unknown schemes through. IID spec §9.1
  3. Canonical value. Run the scheme's canonicalization and reject the IID if the value changes. A canonical value satisfies canonicalize(value) = value.

For example, int:isbn:0-684-83272-0 is well-formed but invalid, because the canonical ISBN form is the 13-digit 9780684832722. Canonicalize the raw ISBN first, then build int:isbn:9780684832722. IID spec §2.5

Compare byte for byte​

Two IIDs are equal if and only if their byte sequences are identical. Comparison ignores no case, Unicode form or whitespace differences. Canonicalize before comparing, never during the comparison. Lowercasing a whole IID can change its meaning, because some schemes preserve case in their values. IID spec §2.4

This makes a canonical IID a safe key for a unique database index or a cache. Two importers that canonicalize the same source value produce identical text. IID spec §8.2

Relationship to URNs​

The grammar follows URN discipline without claiming RFC 8141 conformance. RFC 8141 treats some parts of a URN as case-insensitive, which conflicts with byte-exact comparison. Where a URN is required, map int:<scheme>:<value> to urn:int:<scheme>:<value> and back without changing the value. IID spec §2.6

Applies to V2 · @0xintuition/iid 0.1.1