Ports
| Language | Package | Status |
|---|---|---|
| JavaScript / TypeScript | trackparse on npm |
Reference implementation. 13,565 / 13,565 fixtures. Tracklists in trackparse/tracklist |
| Python | trackparse on PyPI |
13,565 / 13,565 fixtures, output identical to JS on every fixture input. Tracklists in trackparse.tracklist |
| Rust | trackparse on crates.io, API docs on docs.rs |
13,565 / 13,565 fixtures, output identical to JS on every fixture input. Tracklists in trackparse::tracklist |
| Go | github.com/4matic/trackparse/go, API docs on pkg.go.dev |
13,565 / 13,565 fixtures, output identical to JS on every fixture input. Tracklists in the same package (trackparse.ParseTracklist) |
| C | Source tarball and amalgamation on each GitHub Release from 0.7.1; the API is trackparse.h |
13,565 / 13,565 fixtures, output identical to JS on every fixture input. Tracklists in the same library (trackparse_parse_tracklist) |
| What | JavaScript |
|---|---|
| Install | npm install trackparse |
| Needs | Node 18 or newer, or any ES2020 runtime |
| Dependencies | none |
| Types | TypeScript types included |
| Names | parseArtists, fullTitle |
| Options | one object |
| On bad input | never throws on a string |
| JSON | JSON.stringify(track) |
| What | Python |
|---|---|
| Install | pip install trackparse |
| Needs | Python 3.9 or newer |
| Dependencies | none |
| Types | py.typed, passes mypy --strict |
| Names | parse_artists, full_title |
| Options | keyword arguments |
| On bad input | TypeError if the input isn't a str |
| JSON | track.to_dict() |
| What | Rust |
|---|---|
| Install | cargo add trackparse |
| Needs | Rust 1.74 or newer |
| Dependencies | unicode-normalization; serde is optional |
| Types | structs and enums, no unsafe |
| Names | parse_artists, full_title |
| Options | _with functions and option builders |
| On bad input | never panics, no Result |
| JSON | track.to_json(), or serde |
| What | Go |
|---|---|
| Install | go get github.com/4matic/trackparse/go@latest |
| Needs | Go 1.22 or newer |
| Dependencies | none |
| Types | structs and typed string constants, no unsafe, no cgo |
| Names | ParseArtists, FullTitle |
| Options | With functions and option structs |
| On bad input | never panics, no error |
| JSON | json.Marshal(track) |
| What | C |
|---|---|
| Install | CMake FetchContent from the release tarball, or copy the amalgamation (both from 0.7.1) |
| Needs | a C11 compiler (GCC, Clang or MSVC), C++17 for trackparse.hpp; CMake 3.16 or newer for the CMake build |
| Dependencies | none beyond libc, libm and threads |
| Types | read-only structs, C enums with _name() functions, opaque option handles |
| Names | trackparse_parse_artists, full_title |
| Options | _with functions and option handles with setters |
| On bad input | never crashes; NULL only when memory runs out |
| JSON | trackparse_track_to_json(track) |
Getting started has the install steps, and Other functions has the full table of names.
All of them share one version number. The spec, the JavaScript package, the Python package, the
Rust crate, the Go module and the C library are released together, from one release PR, and CI
fails if their versions drift apart. The crate has been on crates.io since 0.4.0. A Go release is
the tag go/vX.Y.Z, which the Go module proxy reads
(published versions). C has no
registry either: a C release is the tag c-vX.Y.Z, with the source tarball
(trackparse-c-X.Y.Z.tar.gz), the amalgamation (trackparse-c-X.Y.Z-amalgamation.zip) and
SHA256SUMS attached to its GitHub Release, starting with 0.7.1 (0.7.0 was tagged without
files). The changelog lists what each release brought.
Adding a language
Section titled “Adding a language”A port is done when it passes every fixture and every invariant. There's no partial credit and no port-specific behaviour. The Python, Rust and Go ports map one to one onto the JavaScript source files, and the C port onto the Go files, so they work as second references. How it works describes the pipeline a port has to build.
The checklist, in short:
- Generate source from
spec/dataandspec/VERSION, with a check mode for CI. - Implement the R0 primitives: the whitespace set, word keys, dedup keys, code-point iteration.
- Build the pipeline in the order of
js/src/parser.ts, then tracklists as a separate module. - Write the fixture matcher (about 40 lines) and a runner over both fixture folders, with schema validation and a skip list that can only shrink.
- Add property tests for the spec invariants.
- Expose an API that's idiomatic for the language but returns the same JSON.
- Extend the cross-port diff so every fixture's complete output is compared with JavaScript.
The full version is in AGENTS.md.
What the Python port taught
Section titled “What the Python port taught”The fixtures passed before the output was identical. The cross-port diff found the rest:
- UTF-16 positions. A few internal positions are counted in UTF-16 units in JavaScript. A port has to count astral characters as two there, or ties are ordered differently on emoji.
- JavaScript's
trim(). Keyword options are trimmed with JavaScript's whitespace set, which is not the spec's set (U+FEFF and U+0085 differ). - Object key order. In a JavaScript object, integer-like keys come first, in ascending order. A plain dict keeps insertion order, so keyword maps need the same reordering.
- Rounding. Rewritten times round half up. Python's
round()rounds half to even.
What the Rust port taught
Section titled “What the Rust port taught”Passing the fixtures was not enough here either. The differences below only showed up in the cross-port diff and in random differential runs against JavaScript:
- Letters and uppercase letters need their own tables. The spec means general category L and
Lu. Rust's
char::is_alphabeticandchar::is_uppercasetest wider properties (they also accept letter numbers and some marks), so the crate generates L and Lu range tables instead. - Lowercasing follows the compiler.
str::to_lowercaseuses the Unicode version of the Rust toolchain that built the crate, which need not be the one in Node or CPython. The crate generates the lowercase mapping from the same source as its letter tables. - Normalization follows the crate.
unicode-normalizationships Unicode 18 while Node 24 has Unicode 17, so 32 new combining marks are ordered differently in NFC. - Keyword values are arbitrary strings. JavaScript passes any string given as a version type or
junk kind in
keywordsthrough to the output. A port with enums needs a string form inside the pipeline to produce the same JSON. - JavaScript's number formatting is part of the output. Edit warnings echo the
lineof an edit, so a large or fractional number has to be written the way JavaScript's number-to-string does (1e+21, not twenty-two digits).
What the Go port taught
Section titled “What the Go port taught”The Go port started from the lists above and from the Rust crate, which had already settled most typing questions. What was new:
- Unicode comes from Node, not from the Go toolchain. Go's
unicodepackage andgolang.org/x/textfollow the Unicode version of the toolchain that builds the program, and x/text even picks its normalization tables by Go version. Two users of the same trackparse version would get different output. The module generates its letter, uppercase, lowercase and NFC/NFD tables from Node instead, so its Unicode version is the reference engine's and it has no dependency. This is also why the Go output has no Unicode difference with JavaScript on Node 24, whose Unicode 17 the tables come from. A Node release with a newer Unicode version can differ until the tables are regenerated with it. - Typed strings instead of enums. Roles, version types, junk kinds and warning codes are typed
strings (
type Role string,trackparse.RolePrimary). A keyword option can bring in any version type or junk kind, and a typed string carries it to the output unchanged, so the Go port needs no separate string form inside the pipeline. - Ordered slices for keyword maps. Go maps have no insertion order to reproduce JavaScript's
Object.entriesorder.Keywords.VersionHeadsandKeywords.Junkare slices: a repeated key keeps its first place and takes the last value, and integer-like keys come first in ascending order, as in JavaScript. - Stable sorts. JavaScript's
sortis stable and the tracklist code relies on that for ties. Go'ssort.Sliceis not, so the module usesslices.SortStableFunc, and CI rejectssort.Slice(. - Invalid UTF-8. A Go string can hold any bytes. The module replaces each maximal ill-formed
subpart with one U+FFFD before parsing, the WHATWG rule that Rust's
from_utf8_lossyandTextDecoderfollow, so the Go and Rust ports read the same bytes as the same text. Go's own decoding would give one U+FFFD per bad byte. - Zero-value options. The option structs mean the defaults when left empty. A field whose
zero value is also a real setting must be a pointer, or that setting cannot be written: an
audio length of 0 seconds (
AudioSeconds *float64) and an empty feat marker (FeatMarker *string), both set withtrackparse.Ptr.ModeAutois"auto", not the empty string, soTracklistOptions{Mode: ModeAuto}means auto while an emptyModekeeps the tracklist default. A test maps the options of every fixture to the typed structs and checks that the output equals the JSON door's. - NUL is real input. A scanner that reads past the end of a string must not see a character. The Go helpers return -1 out of range, not 0, because U+0000 can appear in the input.
What the C port taught
Section titled “What the C port taught”The C library is a file-by-file translation of the Go port, because Go has the closest shape:
explicit types, a code point lookup that returns -1 out of range, and no generics in the hot
paths. Every c/src file is a Go file with the same rule IDs in its comments, and one internal
header declared every type and prototype, in Go file order, before any pipeline code was written.
The JSON reader lives in a separate test library that is never installed, so the library writes
JSON but does not read it. The Go lessons above carried over (Unicode tables, final sigma,
JavaScript's trim(), WHATWG UTF-8, key order, stable sorts). What C added:
- Memory without checks in the pipeline. Each public call opens an arena with a
jmp_buf. Inside the pipeline, allocation never returnsNULL: whenmallocfails, the allocator jumps back to the public function withlongjmp, which frees the arena and returnsNULL. So the pipeline has noNULLchecks and nofreecalls, and each result is one block that its_freefunction releases. Running out of memory is the only way a call can fail. - Numbers without the C library.
strtodandprintf("%g")follow the process locale, and noprintfformat writes JavaScript's shortest round-trip digits.num.cparses decimal strings to the correctly rounded double and writes numbers as JavaScript'sNumber#toStringdoes, with exact big-integer arithmetic.src/has nostrtod, no floatprintfand no<ctype.h>, so a German locale can't write3167,5and a Turkish one can't lowercaseItoı. - Fused multiply-add. GCC in GNU mode contracts
floor(v * 10^d + 0.5)into one fused instruction on ARM64, or on x86 with FMA enabled, and that rounds differently. CMake passes-ffp-contract=off(/fp:preciseon MSVC),num.csets the standard pragma where the compiler honors it, and the product goes through avolatile, so the amalgamation is safe under other flags too. On 32-bit x86, x87 registers compute with extra precision, sonum.crefuses to compile unlessFLT_EVAL_METHODis 0 (-msse2 -mfpmath=sse). - Unicode tables from Node, as in Go. The C library can't take letters, lowercasing or
normalization from the C library or the platform. Its generator shares the derivation with the
Go generator, so both ports carry the same tables: categories L and Lu, JavaScript's
toLowerCasewith the final-sigma rule, combining class ranks, compositions and decompositions. - One translation unit. The installed library is built from the amalgamation, where every
internal function and table is
static, so only thetrackparse_*API leaves the object file, even in a static library. Since all files share one scope there, the amalgamation script fails when two files define the samestaticname. - Unset is not zero. Options are opaque handles with setters, so an option that was never set and one set to its zero value stay different (an audio length of 0 seconds, an empty feat marker) without the pointers Go needed, and a new option doesn't change the ABI.
- Enums and names. Roles, version types and junk kinds are C enums, but a keyword option can
bring in a version type or junk kind that the enum doesn't have. So each version carries
type_nameand each junk itemkind_name, the string that goes into the JSON, and the enum falls back toTRACKPARSE_VERSION_VERSIONorTRACKPARSE_JUNK_OTHER, as the Rust crate does. - Small portability traps.
qsortis not stable, so there is a merge sort.charis signed on x86 and unsigned on ARM, so every byte the pipeline inspects is anunsigned char. Generated tables and non-ASCII literals are\xNNescapes, because MSVC reads source files in the system code page.
See also
Section titled “See also”- How it's tested for the fixtures and the cross-port diff.
- The spec: rule R0 is the portability contract.
- Contributing for the commands of each port.