Skip to content

feat(go): the Go port - #32

Merged
4matic merged 60 commits into
mainfrom
feat/go-port
Nov 14, 2026
Merged

4matic merged 60 commits into
mainfrom
feat/go-port

Conversation

@4matic

@4matic 4matic commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Adds github.com/4matic/trackparse/go, the fourth port: package trackparse, Go 1.22+, no dependencies, no unsafe or cgo.

Behaviour

  • Passes 13,130 / 13,130 shared fixtures, with empty skip lists.
  • compare-ports reports 0 differences across JS, Python, Rust and Go.
  • A JS vs Go differential run (scripts/fuzz-ports.mjs) found 0 differences in 1,080,000 calls: 500,000 single tracks, and 290,000 tracklists each parsed and edited.
  • The private corpus gives the same output in JS and Go.
  • Unicode tables (L, Lu, JS lowercase, NFC/NFD) are generated from Node, so output does not depend on the Go toolchain. x/text would use Unicode 15 below Go 1.27 and 17 from 1.27.
  • Invalid UTF-8 is replaced by the WHATWG rule, the same as Rust.

API

  • Parse, ParseWith, ParseArtists(With), Format(With), Normalize, AllArtists, Parser, ParseTracklist(With), ApplyEdits(With), the Edit constructors, and Ptr.
  • Typed-string enums.
  • Nullable fields are pointers.
  • MarshalJSON writes JSON.stringify bytes, and UnmarshalJSON round-trips.
  • 14 Example functions for pkg.go.dev.

Tests and CI

  • Tests: fixtures with schema validation, seeded property tests for the SPEC invariants and R13.11, fuzz targets (also run weekly in CI), time ceilings, benchmarks, a 16-goroutine -race test, and exhaustive Unicode checks against Node.
  • go.yml: codegen drift, gofmt, vet, staticcheck, go test -race on 1.22 and stable, a test of the module as downloaded (git archive), and a compare job against JS.

Release

  • go is a linked release-please component, tagged go/vX.Y.Z.
  • publish-go checks the versions, warms the module proxy and runs go get from a clean module.
  • spec.yml checks five versions.
  • A local dry run of the pinned release-please gave go/v0.6.0 with all components at 0.6.0. The first real release PR is the final confirmation.

Docs

  • go/README.md, the root and package READMEs, a Go tab on every site example (all compiled and checked), Go in the install switch and the playground's code panels, and AGENTS.md (repo map, commands, hazards, release).

Found along the way, recorded in AGENTS.md as known gaps (spec decisions, not Go bugs):

  • format with featMarker: null: Python differs from the other three.
  • insert next to a bare CR.

Merging opens a release PR for 0.6.0.

…R4 prefixes, R6 separator, R8 title side and the engine (run, runArtists, probe)

The artist side (R5, R7, R9) is a temporary stand-in in go/zz_artist_stub.go until that
port is merged.
…redits, R9 assembly with near-linear dedup, R11 format

Ports rust/src/{classify,artists,credits,assemble,format}.rs. zz_title_stub.go holds
temporary scanner and positionedJunk definitions (a port of rust/src/scanner.rs) until the
title side lands; delete it at merge.
…ons, format, allArtists, R9.2 dedup vs the quadratic reference
… emphasis, kinds, bare positions, warnings with the suggestion search, parseTracklist and applyEdits

The single-track pipeline is reached through engine.probe and engine.run; zz_probe_stub.go is a
temporary probe until the pipeline port lands.
…t and ApplyEdits, seeded with the fixture inputs
…cks and tracklists with edits through all four ports
…the WHATWG rule like input strings, with tests against from_utf8_lossy
…s, 10,000-line tracklists and 2,000 edits, and benchmarks
…ngs, and two spec gaps found by the differential run
…t express every JS value

The Go module github.com/4matic/trackparse/go implements the spec like the JavaScript, Python
and Rust packages: Parse, ParseArtists, Format, Normalize, AllArtists, Parser, ParseTracklist and
ApplyEdits, with output identical to JavaScript on every fixture.

Its options can now say every value the JavaScript options can:

- FormatOptions.FeatMarker is a *string: nil keeps the input's marker, a pointer to "" writes an
  empty marker (JS featMarker: "").
- TracklistOptions.AudioSeconds is a *float64: nil is unknown, a pointer to 0 is an audio of
  length 0 (JS audioSeconds: 0).
- ModeAuto is "auto", and "" means the function's default (auto for a parse, tracklist for a
  tracklist), so TracklistOptions{Mode: ModeAuto} parses each line in auto mode.
- Ptr[T] returns a pointer to a copy of its argument, for the pointer fields.

A new test maps the JSON options of every fixture to the typed structs and requires the same
output bytes as the JSON door. Docs, the playground's Go code and AGENTS.md follow.
… the warning order is a switch

AllWarningCodes was an exported var, and the tracklist warnings were ordered by its index, so a
caller could reorder the output or race with it. warningRank is now a switch over the constants,
and every exported All var (AllModes, AllRoles, AllVersionTypes, AllWarningCodes, ...) is a
function that returns a new slice on each call.
It is a test tool, not something to install: under internal/ it is no longer importable from
outside the module or listed as one of its commands. compare-ports and fuzz-ports run
go run ./internal/cmd/dump.
…o user binaries have no init

wire.go set internal/wire's hook in an init(), which kept the whole JSON door (loose-option
resolution, the JSON edit reader, wireLine) reachable from every program that imports the
module: a hello-world that calls Parse grew from 2.82 MB to 3.20 MB. internal/cmd/dump cannot
reach unexported code any other way, and the typed API cannot carry every loose edit (fractional
or boolean line numbers echo back in edit warnings), so the init moves to wire_hook.go behind
the build tag trackparse_wire. compare-ports and fuzz-ports build the dump command with the tag;
without it the command stops with a message. The fixture tests call wireCall directly and need
no tag. CI vets and staticchecks both builds.
…sample, artist cases on demand

Everything under go/ ships to every user of the module. The committed Unicode sample shrinks
from 1.3 MB to 280 KB (every table range boundary, every eighth entry of the per-code-point
lists, fewer random strings); CI now also runs the full sweep against Node on stable, which
takes about 20 s, so no coverage is lost. testdata/artist_cases.json (2.3 MB) is no longer
committed: dump_artist_cases.mjs writes it from js/dist into a git-ignored path, the artist-side
tests skip without it, and go.yml writes it before go test and sets
TRACKPARSE_REQUIRE_ARTIST_CASES=1 so a missing file fails there.
…or Track.UnmarshalJSON

TestConcurrentUse calls a Parser with known artists and keywords, the zero Parser, Parse,
ParseArtists, FormatWith, ParseTracklistWith and ApplyEdits from 16 goroutines, each starting at
another input, and compares every result with the sequential one; go test -race runs it in CI.
FuzzUnmarshalTrack decodes arbitrary bytes, seeded with the JSON of parsed fixture inputs, and
requires the marshal/unmarshal round trip to be stable and Format, FormatWith and AllArtists not
to panic on whatever decodes. The weekly fuzz job runs it for 3 minutes.
…id UTF-8 is replaced, and EditWarning.Line rounds beyond 2^53

Typed edits keep int line numbers but pass them through float64 like JavaScript numbers, so a
line beyond 2^53 in magnitude is reported rounded (Delete(1<<53 + 1) gives line
9007199254740992). The doc comments now say both.
…der that keeps & < > as written

json.MarshalIndent escapes & as \u0026, unlike JSON.stringify. The generated program now uses an
Encoder with SetEscapeHTML(false) and SetIndent, checked by compiling snippets with
Chase & Status in an artist name.
…nd the timings re-measured

BenchmarkParse10k covers the blocks the docs quote (a &, feat. X, (Remix), [HD], -). Measured
with go test -bench . -run '^$' -benchtime 2s on an i7-4770S, Go 1.24, and Node 24 on the same
inputs (other jobs were running, so two runs each): 10,000 code points take 3 to 7 ms in Go and 4
to 18 ms in JS, a 10,000-line tracklist 0.33 to 0.38 s in Go and 0.8 to 0.9 s in JS. AGENTS.md
and the site say "at most tens of milliseconds" for JS, Rust and Go.
…sions and its own Types cell

The release follows the merge and the package READMEs ship in it, so the "first version comes
with the next release, until then go get finds nothing" notes go from every README, the install
switch and the site; go/README.md links go/CHANGELOG.md. The ports page gets Rust's Types cell
back and a Go cell of its own, and says the Go output matches JavaScript on Node 24 (Unicode 17).
go/README.md states what the toolchain would give instead: unicode.Version is 15.0.0 in Go 1.24,
x/text/unicode/norm uses Unicode 15 below Go 1.27 and 17 from 1.27; and its Performance table
has the new Go and JavaScript timings side by side.
… links the spec changelog and adds format position
…k, and SPEC_VERSION and the pin no longer name 0.5
…ize and Layered comments, the dump command and changelog links in the README
…fuzz jobs, the Go time ceilings and the current site components
…racters in every language; site works with storage blocked

The Rust snippets follow rustfmt's width rules (long use lists, builder chains over 60 columns,
wide parse_with arguments, short line arrays, one space before a trailing comment). JavaScript
and Python literals write invisible and bidi characters as \uXXXX, like the Rust and Go ones,
and U+2060 to U+2064, U+00AD and other format characters are now escaped too. Shift with an
empty box shifts by 0, as the generated code says. A head script gives Starlight an in-memory
store when localStorage or sessionStorage throws, so its theme and tab scripts no longer stop.
The landing page says labeled, and links in the feature list use the site's link style.
…the Go CI jobs, timings and links checked against the repo

Modes, artists and versions show the printed values in JavaScript, Python and Rust, as the Go
tabs already did. The tracklist guide no longer reuses list/tl for later examples, so the
Checks section shows the first list's warnings in every language. Testing lists the module-zip
job and the weekly fuzz run, the internal-pipeline fuzz target, the JS 10,000-line time (about
0.8 s) and the five linked versions.
…rential run, the Go time ceilings and the Go module's first release
@4matic
4matic merged commit 6c03a51 into main Nov 14, 2026
23 checks passed
@4matic
4matic deleted the feat/go-port branch November 14, 2026 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant