From b87d22da744683dac370fc75f1cdbb6283b8c687 Mon Sep 17 00:00:00 2001 From: 4matic Date: Sun, 15 Nov 2026 04:35:38 +0200 Subject: [PATCH 1/5] docs(c): the numbered hazards move into c/src/PORTING.md (they ship with the tarball); README fixes for 0.7.0, test build folders, splitAnd and the C++ string types --- c/CMakeLists.txt | 8 ++++---- c/README.md | 39 ++++++++++++++++++++++---------------- c/cmake/hardening.cmake | 2 +- c/cmake/package.cmake | 2 +- c/scripts/dump_numbers.mjs | 2 +- c/src/PORTING.md | 23 ++++++++++++++++++++++ c/src/num.c | 6 +++--- c/src/rt.h | 2 +- c/tests/hardening.h | 2 +- c/tests/test_locale.c | 2 +- c/tests/test_oom.c | 2 +- c/wire/json_read.h | 2 +- 12 files changed, 61 insertions(+), 31 deletions(-) diff --git a/c/CMakeLists.txt b/c/CMakeLists.txt index a01d5a8..7743897 100644 --- a/c/CMakeLists.txt +++ b/c/CMakeLists.txt @@ -1,4 +1,4 @@ -# The C port of trackparse. See PLAN.md (repo root) and AGENTS.md. +# The C port of trackparse. See AGENTS.md and src/PORTING.md. # # cmake -S c -B c/build -DCMAKE_BUILD_TYPE=Release # cmake --build c/build @@ -56,7 +56,7 @@ set(TRACKPARSE_SPEC_DIR "${TRACKPARSE_REPO_DIR}/spec") add_library(trackparse_flags INTERFACE) if(MSVC) - # /fp:precise: no contraction into FMA (PLAN.md hazard 1). /utf-8: hazard 12. + # /fp:precise: no contraction into FMA (PORTING.md hazard 1). /utf-8: hazard 12. target_compile_options(trackparse_flags INTERFACE /W4 /fp:precise /utf-8) target_compile_definitions(trackparse_flags INTERFACE _CRT_SECURE_NO_WARNINGS) if(TRACKPARSE_WERROR) @@ -64,7 +64,7 @@ if(MSVC) endif() else() # -ffp-contract=off: GCC's GNU-mode default is fast, which can fuse floor(v * p + 0.5) into an - # FMA and change the rounding (PLAN.md hazard 1). + # FMA and change the rounding (PORTING.md hazard 1). target_compile_options(trackparse_flags INTERFACE -ffp-contract=off -Wall -Wextra -Wpedantic -Wshadow @@ -77,7 +77,7 @@ else() -fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer) target_link_options(trackparse_flags INTERFACE -fsanitize=address,undefined) endif() - # 32-bit x86 without SSE2 computes in 80-bit x87 registers (PLAN.md hazard 5). + # 32-bit x86 without SSE2 computes in 80-bit x87 registers (PORTING.md hazard 5). if(CMAKE_SIZEOF_VOID_P EQUAL 4 AND CMAKE_SYSTEM_PROCESSOR MATCHES "^(i.86|x86|X86|AMD64|x86_64)$") target_compile_options(trackparse_flags INTERFACE -msse2 -mfpmath=sse) endif() diff --git a/c/README.md b/c/README.md index f6bb3f8..2b7fed1 100644 --- a/c/README.md +++ b/c/README.md @@ -49,6 +49,10 @@ There is no package registry for C. Each release attaches two files to its Release files are never replaced: a fix is a new version, so a pinned hash keeps working. +The first release with the C library is 0.7.0. Until the releases page lists `c-v0.7.0`, the +download URLs below do not exist yet: build [from source](#from-source) instead, and leave the +version out of `find_package` (a checkout from before that release still says 0.6.1). + ### CMake FetchContent ```cmake @@ -78,7 +82,7 @@ c++ -std=c++17 -O2 -I. app.cpp trackparse.o -lm -pthread -o app # with trackpa `-ffp-contract=off` (MSVC: `/fp:precise`) keeps the compiler from fusing a multiply and an add, which would round some edited tracklist times differently. The file also sets -`#pragma STDC FP_CONTRACT OFF` for the compilers that honour it (GCC ignores it) and rounds that +`#pragma STDC FP_CONTRACT OFF` for the compilers that honor it (GCC ignores it) and rounds that product through a `volatile`, so a build without the flag gives the same times. On Windows, define `TRACKPARSE_STATIC` in the files that include the header, or it declares DLL imports. On 32-bit x86, compile with `-msse2 -mfpmath=sse`: the library refuses to build with x87 arithmetic. @@ -223,7 +227,7 @@ are all defaults. | [`_set_mode`](https://4matic.github.io/trackparse/guides/modes/) | `TRACKPARSE_MODE_AUTO` | `_CLEAN`, `_YOUTUBE`, `_FILENAME`, `_TRACKLIST`, or `_AUTO` to detect from the string. See [Modes](#modes) | | [`_set_uploader`](https://4matic.github.io/trackparse/guides/modes/#the-uploader-fallback) | none | YouTube channel name, used as the artist when there's no separator (`- Topic` and `VEVO` are dropped) | | [`_add_known_artist`](https://4matic.github.io/trackparse/guides/artists/#knownartists) | none | A name that is never split; call it once per name. There is no built-in list | -| [`_set_split_and`](https://4matic.github.io/trackparse/guides/artists/#and-is-special) | `TRACKPARSE_SPLIT_AND_AUTO` | `_AUTO` splits on `and` only after a comma (`A, B and C`), so `Simon and Garfunkel` stays whole. Also `_ALWAYS`, `_NEVER` | +| [`_set_split_and`](https://4matic.github.io/trackparse/guides/artists/#and-is-special) | `TRACKPARSE_SPLIT_AND_AUTO` | `_AUTO` splits on `and` only after a comma or semicolon (`A, B and C`), so `Simon and Garfunkel` stays whole. Also `_ALWAYS`, `_NEVER` | | [`_add_version_head`](https://4matic.github.io/trackparse/guides/versions/#your-own-words), `_add_descriptor`, `_add_genre`, `_add_junk`, `_add_feat_marker` | none | Extra vocabulary ([`keywords`](https://4matic.github.io/trackparse/reference/options/#keywords)), added to the built-in lists | Each setter's full name starts with `trackparse_parse_options`. Setters copy what they are given, @@ -587,7 +591,7 @@ trackparse_tracklist_free(list); ``` The [suggestion](https://4matic.github.io/trackparse/reference/warnings/#suggestions) exists -because exactly one time, one digit away from `00:11:02`, fits between its neighbours. With +because exactly one time, one digit away from `00:11:02`, fits between its neighbors. With several candidates or none, `suggestion` is `NULL`. [Open this list in the playground](https://4matic.github.io/trackparse/playground/#list=Hour%202%0A48%3A20%20Noisia%20-%20Stigma%0A52%3A47%20Mefjus%20%26%20Kasra%20-%20Bandwagon%20%28Phace%20Remix%29%0A56%3A05%20Black%20Sun%20Empire%20-%20ID%0A59%3A31%20Alix%20Perez%20-%20Fade%20Away%0A01%3A03%3A10%20Interview%20with%20Hybris%0A01%3A07%3A44%20Imanu%20-%20Sacrifice%0A00%3A11%3A02%20Current%20Value%20feat.%20Teddy%20Killerz%20-%20Payload%0A01%3A15%3A36%20Hybris%20-%20Spinning%20Top). @@ -636,7 +640,8 @@ gets hours, with a `style-upgraded` warning. A time pushed below zero stops at z ([edit warnings](https://4matic.github.io/trackparse/reference/warnings/#edit-warnings)). `trackparse_tracklist_options` ([options](https://4matic.github.io/trackparse/reference/options/#tracklist-options)) -has the parse options' setters (`_set_mode` defaults to `TRACKPARSE_MODE_TRACKLIST` here), plus +has the parse options' setters except `_set_uploader` (`_set_mode` defaults to +`TRACKPARSE_MODE_TRACKLIST` here), plus `_set_audio_seconds` (the length of the mix; it enables `time-after-audio-end`, and 0 is a valid length) and `_add_marker_word`: @@ -676,8 +681,9 @@ the same output. It is installed and shipped next to `trackparse.h`, and links a - Results (`track`, `artists`, `tracklist`, `edit_result`), `parser` and the option builders are move-only owners that free their C object in the destructor. -- Strings are `std::string_view`, nullable fields `std::optional`, arrays ranges with `begin`, - `end`, `size` and `operator[]`. Views borrow from their owner and are valid while it lives. +- Strings read from results are `std::string_view` (`format`, `normalize` and `to_json` return + `std::string`), nullable fields `std::optional`, arrays ranges with `begin`, `end`, `size` and + `operator[]`. Views borrow from their owner and are valid while it lives. - Option builders chain: `parse_options{}.mode(mode::youtube).known_artist("Chase & Status")`. - The enums are `enum class` (`trackparse::role::featured`), and `trackparse::name(value)` gives the spec name. @@ -736,13 +742,14 @@ MSVC in C++17 and C++20. **Docs:** [How it's tested](https://4matic.github.io/trackparse/project/testing/) · [Ports](https://4matic.github.io/trackparse/project/ports/) From `c/` in the [repository](https://github.com/4matic/trackparse) (CMake 3.16 or later; Node -for the codegen scripts, the amalgamation and the schema check): +for the codegen scripts, the amalgamation and the schema check). Use a build directory other than +`c/build`: `scripts/compare-ports.mjs` configures that one with the tests off. ```sh -cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -cmake --build build -ctest --test-dir build --output-on-failure -TRACKPARSE_REPORT=1 ./build/trackparse-fixtures ../spec/fixtures/*/*.json # pass rate per file and rule +cmake -S . -B build-test -DCMAKE_BUILD_TYPE=RelWithDebInfo +cmake --build build-test +ctest --test-dir build-test --output-on-failure +TRACKPARSE_REPORT=1 ./build-test/trackparse-fixtures ../spec/fixtures/*/*.json # pass rate per file and rule node scripts/gen_data.mjs --check # spec/data codegen is up to date node scripts/gen_unicode.mjs --check # Unicode tables are up to date ``` @@ -775,7 +782,7 @@ Sanitizers and fuzzing are CMake options: cmake -S . -B build-asan -DTRACKPARSE_SANITIZE=ON # AddressSanitizer + UBSan cmake -S . -B build-tsan -DTRACKPARSE_SANITIZE_THREAD=ON # ThreadSanitizer CC=clang CXX=clang++ cmake -S . -B build-msan -DTRACKPARSE_SANITIZE_MEMORY=ON -cmake --build build-msan --target trackparse-fixtures test_api test_properties test_oom +cmake --build build-msan --target trackparse-fixtures test_api test_properties test_oom test_rt test_num CC=clang CXX=clang++ cmake -S . -B build-fuzz -DTRACKPARSE_FUZZ=ON -DTRACKPARSE_BUILD_TESTS=OFF cmake --build build-fuzz # libFuzzer targets fuzz_* node scripts/fuzz_corpus.mjs corpus # seed corpus from the fixture inputs @@ -785,8 +792,8 @@ node scripts/fuzz_corpus.mjs corpus # seed corpus from t Under a sanitizer the property tests run a quarter of their cases and the time ceilings are ten times wider. MemorySanitizer builds only the C programs: the C++ tests would need an instrumented libc++. There is a libFuzzer target for each of `parse`, `parse_artists`, `format`, -`parse_tracklist` and `apply_edits` (`fuzz_parse` and so on) and one for the JSON reader the tests -use (`fuzz_wire`). +`parse_tracklist` and `apply_edits` (`fuzz_parse` and so on) and one for the JSON door the fixture +runner and compare-ports use (`fuzz_wire`: a JSON call line through the reader and `tp_wire_line`). CI ([`c.yml`](https://github.com/4matic/trackparse/blob/main/.github/workflows/c.yml)) builds and tests with GCC and Clang on Linux x86-64, GCC on ARM64 and on 32-bit x86, GCC 9 with CMake 3.16, a @@ -807,7 +814,7 @@ the spec, not here: see [AGENTS.md](https://github.com/4matic/trackparse/blob/ma There are no regular expressions, so there is no regex backtracking. On an Intel i7-4770S with GCC 9 (a CMake Release build, `-O3`), with other programs running: 1 to 6 ms for 10,000 code points of one repeated block (the blocks of the other ports' time ceilings), and 0.34 to 0.39 s for a -10,000-line tracklist (`build/test_bench` prints these). The Go port takes 3 to 7 ms and 0.33 to 0.38 s for the same +10,000-line tracklist (`test_bench` in a Release build prints these). The Go port takes 3 to 7 ms and 0.33 to 0.38 s for the same kinds of input on the same machine. ## Unicode version @@ -821,7 +828,7 @@ combining marks can come out in another order there ## Versioning -**Changelog:** [c/CHANGELOG.md](https://github.com/4matic/trackparse/blob/main/c/CHANGELOG.md) +**Changelog:** [c/CHANGELOG.md](https://github.com/4matic/trackparse/blob/main/c/CHANGELOG.md) (written by the release that first ships the C library, 0.7.0) The library version is the spec version. All five ports and the spec are released together and share one version number; C releases are tagged `c-vX.Y.Z`. While it is 0.x, a release that diff --git a/c/cmake/hardening.cmake b/c/cmake/hardening.cmake index cb13c33..74a66b3 100644 --- a/c/cmake/hardening.cmake +++ b/c/cmake/hardening.cmake @@ -1,4 +1,4 @@ -# hardening.cmake: the hardening tests and the fuzz targets (PLAN.md step 8). Included from +# hardening.cmake: the hardening tests and the fuzz targets (AGENTS.md, C hazards). Included from # CMakeLists.txt when TRACKPARSE_BUILD_TESTS or TRACKPARSE_FUZZ is on. # # properties SPEC invariants and R13.11 on seeded inputs, and the time ceilings diff --git a/c/cmake/package.cmake b/c/cmake/package.cmake index 13cd530..76495ec 100644 --- a/c/cmake/package.cmake +++ b/c/cmake/package.cmake @@ -88,7 +88,7 @@ target_include_directories(trackparse PUBLIC target_compile_definitions(trackparse PRIVATE TRACKPARSE_BUILDING) target_compile_features(trackparse PUBLIC c_std_11) -# The flags the results depend on (PLAN.md hazards 1, 5 and 12), always. The warning flags of +# The flags the results depend on (PORTING.md hazards 1, 5 and 12), always. The warning flags of # trackparse_flags (and -Werror under CI) only when trackparse is the top-level project, so a # consumer's newer compiler cannot break its build. if(trackparse_is_top_level) diff --git a/c/scripts/dump_numbers.mjs b/c/scripts/dump_numbers.mjs index 151fd04..3d1dae9 100644 --- a/c/scripts/dump_numbers.mjs +++ b/c/scripts/dump_numbers.mjs @@ -10,7 +10,7 @@ // patterns, subnormals, powers of ten and their neighbours, integers, exact halfway points between // neighbouring doubles (and one unit above and below in a far digit), long digit strings, short // decimals like the R13.2 times, and exponent forms. -// The committed sample c/tests/data/numbers_sample.jsonl is --n 2000 --seed 1. +// The committed sample c/tests/data/numbers_sample.jsonl is --n 1400 --seed 1. import { createWriteStream } from "node:fs"; diff --git a/c/src/PORTING.md b/c/src/PORTING.md index bc25eec..4604f9a 100644 --- a/c/src/PORTING.md +++ b/c/src/PORTING.md @@ -210,3 +210,26 @@ the array's elements, and the typed API passes `tp_edit_json` of each edit. The The only recursive function is `tp_json_write`. Its depth is bounded by the reader's `TP_JSON_MAX_DEPTH` (200) and, for `tp_edit_json` values, by 2. + +## Hazards (numbered; the code cites them) + +The Go hazards carry over: Unicode tables from Node, final sigma, JS `trim()`, WHATWG UTF-8, +UTF-16 positions, stable sorts, `Object.entries` order, JSON bytes, half-up rounding, JS number +rules for edits, lone surrogates. C adds these: + +| # | Hazard | What goes wrong | Fix | +|---|---|---|---| +| 1 | FMA contraction | GCC in GNU mode defaults to `-ffp-contract=fast`, so `floor(v * 10^d + 0.5)` can become a fused multiply-add on ARM64 (or x86 with `-mfma`), and rounding changes | `-ffp-contract=off` (MSVC `/fp:precise`) set by CMake and by `#pragma STDC FP_CONTRACT OFF` in `num.c`, so the amalgamation is safe too; a test with the values that differ; ARM64 CI | +| 2 | Locale | `strtod`, `printf("%g")`, `isalpha`, `tolower` follow `LC_NUMERIC` / `LC_CTYPE`: a German locale writes `3167,5`, a Turkish one lowercases `I` to dotless `ı` | No ``, no `strtod`, no float `printf` in `src/` (a CI grep bans them). `tests/test_locale.c` calls `setlocale(LC_ALL, "")` and CI runs the suite under `de_DE.UTF-8` and `tr_TR.UTF-8` | +| 3 | Number formatting | JS writes the shortest digits that round trip; `%.17g` does not | Own shortest-digits writer (exact big-integer digit generation, about 250 lines; speed does not matter for a few numbers per result), then JS's exponent rules. `tests/test_num.c` checks it against Node on the committed sample (`tests/data/numbers_sample.jsonl`, 700 doubles: random bit patterns, subnormals, `1e21`, `-0`, `5e-324`); `scripts/dump_numbers.mjs` writes larger sets (1 million cases by default) to run by hand | +| 4 | Number parsing | `Number("3167.12345678901234567")` is correctly rounded | Fast path when the digits fit in 2^53 and the power of ten is exact (one correctly rounded division), big-integer fallback otherwise. `tests/test_num.c` checks it against Node on the same sample's 700 digit strings, and larger sets from `scripts/dump_numbers.mjs` by hand | +| 5 | x87 excess precision | 32-bit x86 without SSE2 computes in 80 bits (`FLT_EVAL_METHOD == 2`) | Require SSE2 there (`-msse2 -mfpmath=sse`), `#error` when `FLT_EVAL_METHOD` is not 0, a 32-bit CI job | +| 6 | `char` signedness | `char` is signed on x86 and unsigned on ARM | Bytes are `unsigned char` / `uint8_t` inside `src/`; ARM64 CI | +| 7 | `qsort` is not stable | ties reorder, unlike JS `sort` | `sort.c` (merge sort); a CI grep bans `qsort(` | +| 8 | Hash table order | an iteration order can reach the output | Ordered arrays for the keyword maps (JS `Object.entries` order, as in Go); hash or sorted indexes only for lookup, never iterated for output | +| 9 | Memory safety and totality (R0.8) | out-of-bounds reads, leaks, use after free, size overflow | `at()` returning -1 out of range, as in Go; checked size arithmetic; ASan + UBSan on every test run, MSan, Valgrind, libFuzzer; `-Wall -Wextra -Wpedantic -Wconversion -Wshadow -Werror` | +| 10 | Out of memory | C cannot pretend allocation never fails | Two arenas per call (scratch, freed at the end, and the result's own block). An arena that fails once stays failed, the pipeline finishes on empty data without crashing, and the call returns `NULL`. `tests/test_oom.c` fails allocation n for every n | +| 11 | Recursion and stack | deep nesting could overflow the stack | Bracket depth is a counter. The one recursive function, `tp_json_write`, has a bounded depth (see [Recursion](#recursion)) | +| 12 | Source charset | MSVC reads string literals in the system code page | Generated tables and every non-ASCII literal are `\xNN` escapes; `/utf-8` anyway | +| 13 | Thread safety | lazy global init needs locks | Default tables are `static const` generated data: nothing to initialize. `tests/test_threads.c` runs 16 threads against sequential results under ThreadSanitizer | +| 14 | Numbers echoed in edit warnings | `-0`, NaN, huge line numbers | The wire layer applies JS number semantics; the typed API takes `double` seconds and `long long` lines; `num.c` prints JS's form | diff --git a/c/src/num.c b/c/src/num.c index 180f0cf..a3166f4 100644 --- a/c/src/num.c +++ b/c/src/num.c @@ -1,7 +1,7 @@ /* num.c: exact, locale-independent numbers (rt.h "Numbers"). * * - tp_parse_number: decimal string to the correctly rounded double, for any digit count, without - * strtod (locale, PLAN.md hazard 2 and 4). + * strtod (locale, PORTING.md hazards 2 and 4). * - tp_buf_number: JS Number#toString (shortest round-trip digits, closest of those, ties to an * even digit, as V8's bignum-dtoa), without printf (hazard 3). * - tp_half_up_units / tp_round_half_up: floor(v * scale + 0.5) as Go formatTime and JS @@ -25,7 +25,7 @@ #include "rt.h" -/* FMA contraction would fuse v * scale + 0.5 (PLAN.md hazard 1). The pragma is standard C, but +/* FMA contraction would fuse v * scale + 0.5 (PORTING.md hazard 1). The pragma is standard C, but * GCC ignores it (and defaults to -ffp-contract=fast in GNU mode), so the build also passes * -ffp-contract=off (MSVC: /fp:precise), and tp_half_up_units rounds the product through a * volatile so even a build without the flag cannot fuse it. */ @@ -35,7 +35,7 @@ #pragma fp_contract(off) #endif -/* x87 excess precision would make the fast path double-round (PLAN.md hazard 5). */ +/* x87 excess precision would make the fast path double-round (PORTING.md hazard 5). */ #if !defined(FLT_EVAL_METHOD) || FLT_EVAL_METHOD != 0 #error "trackparse needs FLT_EVAL_METHOD == 0 (on 32-bit x86: -msse2 -mfpmath=sse)" #endif diff --git a/c/src/rt.h b/c/src/rt.h index 5e99f86..859d5d8 100644 --- a/c/src/rt.h +++ b/c/src/rt.h @@ -23,7 +23,7 @@ * is ever visible to users, even in a static library. Tests and wire/ use the separate-files * build, where TP_PRIVATE is empty. * - * Determinism rules (AGENTS.md, PLAN.md hazards) + * Determinism rules (AGENTS.md, PORTING.md hazards) * ----------------------------------------------- * - No , no strtod/atof/strtol, no printf-family on floats, no locale-dependent call. * - No qsort: use tp_sort_stable. diff --git a/c/tests/hardening.h b/c/tests/hardening.h index 9a2b426..0b4e23e 100644 --- a/c/tests/hardening.h +++ b/c/tests/hardening.h @@ -1,4 +1,4 @@ -/* hardening.h: what the hardening tests and the fuzz targets share (PLAN.md step 8). +/* hardening.h: what the hardening tests and the fuzz targets share (AGENTS.md, C hazards). * * - The seeded input generator of go/properties_test.go (mulberry32 over the same fragments), * so a failure is reproducible from its seed and case number. diff --git a/c/tests/test_locale.c b/c/tests/test_locale.c index a989e2a..a0f0db0 100644 --- a/c/tests/test_locale.c +++ b/c/tests/test_locale.c @@ -1,4 +1,4 @@ -/* test_locale.c: the output does not depend on the process locale (PLAN.md hazard 2). +/* test_locale.c: the output does not depend on the process locale (PORTING.md hazard 2). * * The library never calls a locale-dependent function (no , strtod or float printf in * src/), so a program that calls setlocale() must still get the bytes the "C" locale gives. This diff --git a/c/tests/test_oom.c b/c/tests/test_oom.c index 19f304d..48f234a 100644 --- a/c/tests/test_oom.c +++ b/c/tests/test_oom.c @@ -1,4 +1,4 @@ -/* test_oom.c: allocation failure at every n (PLAN.md hazard 10). +/* test_oom.c: allocation failure at every n (PORTING.md hazard 10). * * A counting allocator (trackparse_set_allocator) fails the n-th allocation. For a set of about * 50 fixture inputs and every public function (and the JSON door, which reports out of memory by diff --git a/c/wire/json_read.h b/c/wire/json_read.h index 4716121..cb2a689 100644 --- a/c/wire/json_read.h +++ b/c/wire/json_read.h @@ -1,7 +1,7 @@ /* json_read.h: the JSON reader of the wire door (go/json.go parseJSON). * * Never part of the installed library: only the wire library, the fixture runner, the dump tool - * and the fuzzers read JSON (PLAN.md decision 5). + * and the fuzzers read JSON (the installed library writes JSON but never reads it). */ #ifndef TP_JSON_READ_H #define TP_JSON_READ_H From 6b75703f89ee50a64fae63fd28766da9facc6371 Mon Sep 17 00:00:00 2001 From: 4matic Date: Sun, 15 Nov 2026 04:35:38 +0200 Subject: [PATCH 2/5] docs: five ports in every README: C install before 0.7.0, splitAnd after a comma or semicolon, test build folders, ceilings, American spelling --- README.md | 80 +++++++++++++++++++++++++++++++--------- go/README.md | 10 ++--- go/doc.go | 9 +++-- js/README.md | 6 +-- python/README.md | 10 ++--- rust/README.md | 6 +-- spec/fixtures/README.md | 12 +++--- spec/generator/README.md | 3 +- 8 files changed, 91 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index ef540e4..030c1a5 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ track.position; // { raw: '01', number: 1 } Every key is always present ([field reference](https://4matic.github.io/trackparse/reference/parse/#parsedtrack), [JSON Schema](spec/schema/parsed-track.schema.json)). When a guess was involved, `warnings` says which one. Python's [`to_dict()`](https://4matic.github.io/trackparse/reference/parse/#serializing-to-json), -Rust's [`to_json()`](https://docs.rs/trackparse/latest/trackparse/struct.ParsedTrack.html#method.to_json) +Rust's [`to_json()`](https://docs.rs/trackparse/latest/trackparse/struct.ParsedTrack.html#method.to_json), Go's [`MarshalJSON`](https://pkg.go.dev/github.com/4matic/trackparse/go#Track.MarshalJSON) and C's [`trackparse_track_to_json`](c/README.md#json) give this same JSON. @@ -130,7 +130,7 @@ and C's [`trackparse_track_to_json`](c/README.md#json) give this same JSON. | **Python 3.9+** | 1,342 pytest tests on 3.9 to 3.14, plus every fixture against the built wheel. Output is byte-identical to JS | | **Rust 1.74+** | Every fixture, the tracklist invariants and the typed API tests on stable and on 1.74. Output is byte-identical to JS on every fixture and on about 790,000 random inputs | | **Go 1.22+** | Every fixture, the spec invariants and the examples with `go test -race` on 1.22 and on the latest stable. Output is byte-identical to JS on every fixture and on about 790,000 random inputs | -| **C11, C++17** | Every fixture, the spec invariants, threads, locales and allocation failure at every step with GCC, Clang (x86-64, ARM64, 32-bit), Apple Clang and MSVC, under AddressSanitizer, UBSan, ThreadSanitizer and MemorySanitizer, plus libFuzzer targets. A header-only C++17 wrapper on top. Output is byte-identical to JS on every fixture | +| **C11, C++17** | Every fixture, the spec invariants, threads, locales and allocation failure at every step. GCC and Clang on x86-64, GCC on ARM64 and 32-bit x86, GCC 9 with CMake 3.16, Apple Clang and MSVC; AddressSanitizer, UBSan, ThreadSanitizer, MemorySanitizer and Valgrind; libFuzzer targets. A header-only C++17 wrapper on top. Output is byte-identical to JS on every fixture and on 60,000 random inputs on every push and pull request | | **5,031** real tracklist lines | 117 podcast tracklists the tracklist rules were [checked against](https://4matic.github.io/trackparse/project/testing/#real-tracklists). Every line round-trips byte for byte | | **1** spec | [`spec/SPEC.md`](spec/SPEC.md) defines the behaviour ([on the site](https://4matic.github.io/trackparse/reference/spec/)). The five packages share its version number and are released together | @@ -180,6 +180,9 @@ FetchContent_MakeAvailable(trackparse) target_link_libraries(app PRIVATE trackparse::trackparse) ``` +0.7.0 is not out yet; until the releases page lists `c-v0.7.0`, build from a clone as in +[the C README](c/README.md#from-source). + ## Quick start **Docs:** [Getting started](https://4matic.github.io/trackparse/start/getting-started/) · [Introduction](https://4matic.github.io/trackparse/start/introduction/) @@ -280,7 +283,7 @@ Rust API is in [`rust/README.md`](rust/README.md#api) and on [docs.rs](https://d Results are structs with exported fields ([`Track`](https://pkg.go.dev/github.com/4matic/trackparse/go#Track)); fields that can be `null` are pointers. Roles, version types and junk kinds are typed strings with constants -(`trackparse.RoleFeatured`). `json.Marshal` gives the spec's JSON, with `&`, `<` and `>` escaped as `&`, `<` and `>`: the same +(`trackparse.RoleFeatured`). `json.Marshal` gives the spec's JSON, with `&`, `<` and `>` escaped as `\u0026`, `\u003c` and `\u003e`: the same values in different bytes. For the exact bytes of `JSON.stringify`, call [`MarshalJSON`](https://pkg.go.dev/github.com/4matic/trackparse/go#Track.MarshalJSON) directly. @@ -384,6 +387,27 @@ Options are opaque objects filled by setters `trackparse_parse_with(s, len, o)`. `trackparse_track_to_json` writes the bytes `JSON.stringify` writes. The full C API, memory rules and the C++ wrapper are in [`c/README.md`](c/README.md#api). +In C++17, `trackparse.hpp` wraps the same calls: results free themselves, strings read from +results are `std::string_view` (`format`, `normalize` and `to_json` return `std::string`), fields +that can be `null` are `std::optional`, and options chain. The only exception it throws is +`std::bad_alloc`. + +```cpp +#include +#include + +auto track = trackparse::parse("Noisia feat. Foreign Beggars - Shellshock"); +for (const auto &a : track.artists()) + std::cout << a.name() << ' ' << trackparse::name(a.role()) << '\n'; +// Noisia primary +// Foreign Beggars featured + +trackparse::parser parser(trackparse::parse_options{}.known_artist("Chase & Status")); +auto t = parser.parse("Chase & Status - Baddadan (Extended Mix)"); +std::cout << t.artists()[0].name() << ", " << t.versions()[0].type_name() << '\n'; +// Chase & Status, extended +``` + Every example on the [documentation site](https://4matic.github.io/trackparse/) has JavaScript, Python, Rust, Go and C tabs. @@ -621,14 +645,14 @@ dash as a version or a genre. `parseTracklist` parses each line with | `8 Linkin Park_-_Points Of Authority (Gydra Bootleg)` | no separator | position 8, Linkin Park / `Points Of Authority`, bootleg by Gydra | | `10 Optiv & BTK-Inception (Gydra remix)` | no separator | position 10, Optiv, BTK / `Inception`, remix by Gydra | -The last two rows need the neighbours. A bare `8 ` only counts as a position when the nearest line +The last two rows need the neighbors. A bare `8 ` only counts as a position when the nearest line before or after it that has a time or a spaced dash starts with a bare 7 or 9 ([bare track numbers](https://4matic.github.io/trackparse/guides/tracklists/#bare-track-numbers), [R13.5](https://4matic.github.io/trackparse/reference/spec/#r135-bare-positions)). Dotted numbers like `01.` never count as -neighbours, so `2 Unlimited - No Limit` between `01.` and `03.` stays an artist. The tight +neighbors, so `2 Unlimited - No Limit` between `01.` and `03.` stays an artist. The tight `BTK-Inception` dash only splits on a timed line without a marker word, and only when at least half of the list uses spaced dashes ([R6.10](https://4matic.github.io/trackparse/reference/spec/#r6-artisttitle-separator)). -[Try both lines with their neighbours](https://4matic.github.io/trackparse/playground/#list=00%3A00%207%20Noisia%20-%20Stigma%0A03%3A00%208%20Linkin%20Park_-_Points%20Of%20Authority%20%28Gydra%20Bootleg%29%0A06%3A00%209%20Optiv%20%26%20BTK-Inception%20%28Gydra%20remix%29%0A09%3A00%2010%20Imanu%20-%20Sacrifice) in the playground. +[Try both lines with their neighbors](https://4matic.github.io/trackparse/playground/#list=00%3A00%207%20Noisia%20-%20Stigma%0A03%3A00%208%20Linkin%20Park_-_Points%20Of%20Authority%20%28Gydra%20Bootleg%29%0A06%3A00%209%20Optiv%20%26%20BTK-Inception%20%28Gydra%20remix%29%0A09%3A00%2010%20Imanu%20-%20Sacrifice) in the playground. ## How it's tested @@ -645,7 +669,8 @@ Passing a fixture only checks the fields the case asserts ([matching rules](spec five ports and diffs the complete outputs, tracklists and edits included. Result: 0 differences, byte for byte. [`scripts/fuzz-ports.mjs`](scripts/fuzz-ports.mjs) does the same with random input. The Rust crate and the Go module were each compared with JS on about 500,000 random single-track -cases and 290,000 random tracklists with edits: 0 differences +cases and 290,000 random tracklists with edits: 0 differences. CI runs the C library against JS +on 50,000 random tracks and 10,000 random tracklists on every push ([port against port](https://4matic.github.io/trackparse/project/testing/#port-against-port)). ### Handwritten: 1,203 cases in 27 files @@ -700,7 +725,7 @@ uses [fast-check](https://github.com/dubzzz/fast-check), the Python suite [Hypothesis](https://hypothesis.works), and the Rust crate, the Go module and the C library small seeded generators of their own, so they need no extra dev dependency. The Go module also has fuzz targets for `go test -fuzz`, and the C library libFuzzer targets. The C suite also runs under -AddressSanitizer, UBSan, ThreadSanitizer and MemorySanitizer, fails every allocation in turn, and +AddressSanitizer, UBSan, ThreadSanitizer, MemorySanitizer and Valgrind, fails every allocation in turn, and compares the output under German and Turkish locales with the `C` locale's. The invariants: - it never throws or panics, on any input; @@ -718,7 +743,8 @@ For tracklists, on random multi-line text and random edit lists - `raw + eol` over all entries gives the input back, and `lead + time + gap + rest` gives `raw`; - `applyEdits(t, [])` returns `t`, and an edit never touches a line it doesn't name; - `shift(+s)` then `shift(-s)` restores the text when nothing was clamped or upgraded; -- 10,000 lines parse inside each suite's ceiling (3 s in JS, Go and C); +- 10,000 lines parse inside each suite's ceiling (3 s in JS, Go, C and a Rust release build, + 18 s in a Rust debug build, 15 s in Python); - a one-line list gives the same track as `parse()` in tracklist mode on its text without Markdown emphasis or a leading `w/`; - Markdown emphasis around a time or a track line gives the same kind, time and track as the plain @@ -752,7 +778,7 @@ pnpm conformance # pass rate per fixture file and per spec rule (cd python && uv run pytest) # the same fixtures and invariants in Python (cd rust && cargo test) # and in Rust (cd go && go test ./...) # and in Go -(cd c && cmake -S . -B build && cmake --build build && ctest --test-dir build) # and in C +(cd c && cmake -S . -B build-test && cmake --build build-test && ctest --test-dir build-test) # and in C pnpm --filter trackparse build node scripts/compare-ports.mjs # all five ports on every fixture; must print "differences: 0" @@ -798,8 +824,8 @@ types: [JavaScript](js/README.md#api), [Python](python/README.md#api), [Rust](ru [Go](go/README.md#api), [C](c/README.md#api). No function throws or panics on any string, and bad options fall back to the defaults. The -exceptions: Python raises `TypeError` when the input is not a `str`, and the C functions return -`NULL` when memory runs out. +exceptions: Python raises `TypeError` when the input is not a `str`, the C functions return +`NULL` when memory runs out, and the C++ wrapper throws `std::bad_alloc` then. ### `parse(input, options?)` → `ParsedTrack` @@ -862,7 +888,7 @@ The JSON shape is fixed by [`spec/schema/parsed-track.schema.json`](spec/schema/ | [`mode`](https://4matic.github.io/trackparse/guides/modes/) | `"auto"` | `"clean"`, `"youtube"`, `"filename"`, `"tracklist"`, or detect from the string | | [`knownArtists`](https://4matic.github.io/trackparse/guides/artists/#knownartists) | `[]` | Names that are never split (`Chase & Status`, `Earth, Wind & Fire`) | | [`uploader`](https://4matic.github.io/trackparse/guides/modes/#the-uploader-fallback) | – | YouTube channel; in youtube mode it's used as the artist when there's no separator (`- Topic` and `VEVO` are dropped) | -| [`splitAnd`](https://4matic.github.io/trackparse/guides/artists/#and-is-special) | `"auto"` | `and` splits only after a comma (`A, B and C`), so `Simon and Garfunkel` stays whole | +| [`splitAnd`](https://4matic.github.io/trackparse/guides/artists/#and-is-special) | `"auto"` | `and` splits only after a comma or semicolon (`A, B and C`), so `Simon and Garfunkel` stays whole | | [`keywords`](https://4matic.github.io/trackparse/reference/options/#keywords) | – | Extra vocabulary: `versionHeads`, `descriptors`, `genres`, `junk`, `featMarkers` | JavaScript takes an options object, Python takes keyword arguments @@ -932,6 +958,22 @@ parser := trackparse.NewParser(trackparse.ParseOptions{ fmt.Println(parser.Parse("Chase & Status x Camo & Krooked - Track (Alix Perez Rerub)").Versions[0].Type) // rework ``` +```c +trackparse_parse_options *o = trackparse_parse_options_new(); +trackparse_parse_options_add_known_artist(o, "Chase & Status", TRACKPARSE_NUL_TERMINATED); +trackparse_parse_options_add_known_artist(o, "Camo & Krooked", TRACKPARSE_NUL_TERMINATED); +trackparse_parse_options_add_version_head(o, "rerub", TRACKPARSE_NUL_TERMINATED, "rework", + TRACKPARSE_NUL_TERMINATED); +trackparse_parser *parser = trackparse_parser_new(o); +trackparse_parse_options_free(o); + +trackparse_track *t = trackparse_parser_parse( + parser, "Chase & Status x Camo & Krooked - Track (Alix Perez Rerub)", TRACKPARSE_NUL_TERMINATED); +printf("%s\n", t->versions[0].type_name.ptr); // rework +trackparse_track_free(t); +trackparse_parser_free(parser); +``` + ### Modes **Docs:** [Modes](https://4matic.github.io/trackparse/guides/modes/) · [R2 in the spec](https://4matic.github.io/trackparse/reference/spec/#r2-mode-prelude) @@ -1055,9 +1097,11 @@ are built with [`SetTime(line, seconds)`](https://pkg.go.dev/github.com/4matic/t each line in auto mode ([details](go/README.md#pointer-fields-and-ptr)). C has `trackparse_parse_tracklist_with`, which takes a `trackparse_tracklist_options` -(`trackparse_tracklist_options_set_audio_seconds(o, 3600)`), and edit lists filled with -`trackparse_edits_set_time`, `_shift`, `_shift_from`, `_shift_lines`, `_sort_by_time`, -`_set_rest`, `_insert` and `_delete` ([details](c/README.md#tracklists-and-edits)). +(`trackparse_tracklist_options_set_audio_seconds(o, 3600)`, +`trackparse_tracklist_options_add_marker_word(o, "drop", TRACKPARSE_NUL_TERMINATED)`). +`trackparse_apply_edits` takes no options, since edits don't depend on them. Its edit list is +filled with `trackparse_edits_set_time`, `_shift`, `_shift_from`, `_shift_lines`, +`_sort_by_time`, `_set_rest`, `_insert` and `_delete` ([details](c/README.md#tracklists-and-edits)). More on the options: [Tracklist options](https://4matic.github.io/trackparse/reference/options/#tracklist-options). @@ -1092,7 +1136,7 @@ are in [spec/SPEC.md](spec/SPEC.md), which the site also shows as a Tracklists ([R13](https://4matic.github.io/trackparse/reference/spec/#r13-tracklists)) sit on top of that. The text is split into lines with their terminators, a small scanner reads the time at the start of each line, and the rest goes through the same pipeline in -tracklist mode. Two things look across lines: bare track numbers are only accepted when a neighbour +tracklist mode. Two things look across lines: bare track numbers are only accepted when a neighbor continues the sequence, and the unspaced-dash split is only switched on when most of the list uses spaced dashes. The checks run last, over the finished entries. @@ -1125,7 +1169,7 @@ Changes to the rules and the fixtures are in [spec/CHANGELOG.md](spec/CHANGELOG. Want another language? Start with [Adding a language](https://4matic.github.io/trackparse/project/ports/#adding-a-language). The -full porting checklist is in [AGENTS.md](AGENTS.md#porting-guide-rust-go-others), along with the +full porting checklist is in [AGENTS.md](AGENTS.md#porting-guide-rust-go-c-others), along with the problems the earlier ports ran into. ## Compared to other libraries diff --git a/go/README.md b/go/README.md index ad9f5b4..176d122 100644 --- a/go/README.md +++ b/go/README.md @@ -164,7 +164,7 @@ spec in order. | [`Mode`](https://4matic.github.io/trackparse/guides/modes/) | `ModeAuto` | `ModeClean`, `ModeYouTube`, `ModeFilename`, `ModeTracklist`, or `ModeAuto` to detect from the string. See [Modes](#modes) | | [`Uploader`](https://4matic.github.io/trackparse/guides/modes/#the-uploader-fallback) | none | YouTube channel name, used as the artist when there's no separator (`- Topic` and `VEVO` are dropped) | | [`KnownArtists`](https://4matic.github.io/trackparse/guides/artists/#knownartists) | none | Names that are never split. There is no built-in list | -| [`SplitAnd`](https://4matic.github.io/trackparse/guides/artists/#and-is-special) | `SplitAndAuto` | `SplitAndAuto` splits on `and` only after a comma (`A, B and C`), so `Simon and Garfunkel` stays whole. Also `SplitAndAlways`, `SplitAndNever` | +| [`SplitAnd`](https://4matic.github.io/trackparse/guides/artists/#and-is-special) | `SplitAndAuto` | `SplitAndAuto` splits on `and` only after a comma or semicolon (`A, B and C`), so `Simon and Garfunkel` stays whole. Also `SplitAndAlways`, `SplitAndNever` | | [`Keywords`](https://4matic.github.io/trackparse/reference/options/#keywords) | none | Extra vocabulary, added to the built-in lists (see below) | Options are plain structs, and the zero value of every struct is the default: `Parse(s)` is @@ -560,7 +560,7 @@ fmt.Println(s.Lines, s.Tracks, s.Markers, s.Timed, *s.FirstTime, *s.LastTime) // ``` The [suggestion](https://4matic.github.io/trackparse/reference/warnings/#suggestions) exists because exactly one time, one digit away from `00:11:02`, -fits between its neighbours. With several candidates or none, `Suggestion` is `nil`. +fits between its neighbors. With several candidates or none, `Suggestion` is `nil`. [Open this list in the playground](https://4matic.github.io/trackparse/playground/#list=Hour%202%0A48%3A20%20Noisia%20-%20Stigma%0A52%3A47%20Mefjus%20%26%20Kasra%20-%20Bandwagon%20%28Phace%20Remix%29%0A56%3A05%20Black%20Sun%20Empire%20-%20ID%0A59%3A31%20Alix%20Perez%20-%20Fade%20Away%0A01%3A03%3A10%20Interview%20with%20Hybris%0A01%3A07%3A44%20Imanu%20-%20Sacrifice%0A00%3A11%3A02%20Current%20Value%20feat.%20Teddy%20Killerz%20-%20Payload%0A01%3A15%3A36%20Hybris%20-%20Spinning%20Top). [`ApplyEdits`](https://pkg.go.dev/github.com/4matic/trackparse/go#ApplyEdits) takes a slice of [`Edit`](https://pkg.go.dev/github.com/4matic/trackparse/go#Edit) values and only rewrites the @@ -661,8 +661,8 @@ result is `Track.UnmarshalJSON`, which reads JSON you give it. A Go string can hold bytes that are not valid UTF-8. Every function reads such input with the WHATWG rule, the one `TextDecoder` uses in JavaScript and `String::from_utf8_lossy` in Rust: each -maximal ill-formed subsequence becomes one U+FFFD. So the Go module and the Rust crate read the -same bytes as the same text, and every output string is valid UTF-8. +maximal ill-formed subsequence becomes one U+FFFD. So the Go module, the Rust crate and the C +library read the same bytes as the same text, and every output string is valid UTF-8. ```go fmt.Printf("%q\n", trackparse.Parse("Noisia - Sti\xffgma\xe2\x82").Title) // "Sti�gma�" @@ -763,7 +763,7 @@ difference is described under [Unicode version](#unicode-version). | Python | [trackparse on PyPI](https://pypi.org/project/trackparse/) | `pip install trackparse` | [README](https://github.com/4matic/trackparse/blob/main/python/README.md) · [changelog](https://github.com/4matic/trackparse/blob/main/python/CHANGELOG.md) · [API](https://4matic.github.io/trackparse/reference/parse/) | | Rust | [trackparse on crates.io](https://crates.io/crates/trackparse) | `cargo add trackparse` | [README](https://github.com/4matic/trackparse/blob/main/rust/README.md) · [changelog](https://github.com/4matic/trackparse/blob/main/rust/CHANGELOG.md) · [API on docs.rs](https://docs.rs/trackparse) | | Go | [github.com/4matic/trackparse/go](https://pkg.go.dev/github.com/4matic/trackparse/go) | `go get github.com/4matic/trackparse/go` | [README](https://github.com/4matic/trackparse/blob/main/go/README.md) · [changelog](https://github.com/4matic/trackparse/blob/main/go/CHANGELOG.md) · [API on pkg.go.dev](https://pkg.go.dev/github.com/4matic/trackparse/go) | -| C / C++ | [C library and C++ header](https://github.com/4matic/trackparse/blob/main/c/README.md) | CMake FetchContent from the [release tarball](https://github.com/4matic/trackparse/releases), or the amalgamation | [README](https://github.com/4matic/trackparse/blob/main/c/README.md) · [changelog](https://github.com/4matic/trackparse/blob/main/c/CHANGELOG.md) · [header](https://github.com/4matic/trackparse/blob/main/c/include/trackparse.h) | +| C / C++ | [C library and C++ header](https://github.com/4matic/trackparse/blob/main/c/README.md) | CMake FetchContent from the [release tarball](https://github.com/4matic/trackparse/releases), or the amalgamation (from 0.7.0) | [README](https://github.com/4matic/trackparse/blob/main/c/README.md) · [changelog](https://github.com/4matic/trackparse/blob/main/c/CHANGELOG.md) · [header](https://github.com/4matic/trackparse/blob/main/c/include/trackparse.h) | ## Limitations diff --git a/go/doc.go b/go/doc.go index 979ab5c..74f7363 100644 --- a/go/doc.go +++ b/go/doc.go @@ -43,11 +43,12 @@ // # Spec and other languages // // This is the Go port of a spec-driven parser. The JavaScript (npm), Python (PyPI), Rust -// (crates.io) and Go packages implement one spec, pass the same shared fixtures, give the same -// output on every fixture input, and are released together under one version number -// ([SpecVersion]). Comments in the source cite the spec's rule IDs (R0 to R13). +// (crates.io) and Go packages and the C library (with a C++17 header) implement one spec, pass +// the same shared fixtures, give the same output on every fixture input, and are released +// together under one version number ([SpecVersion]). Comments in the source cite the spec's rule +// IDs (R0 to R13). // -// - Documentation, with every example in all four languages: https://4matic.github.io/trackparse/ +// - Documentation, with every example in all five languages: https://4matic.github.io/trackparse/ // - Playground: https://4matic.github.io/trackparse/playground/ // - Spec: https://github.com/4matic/trackparse/blob/main/spec/SPEC.md // - Repository and README: https://github.com/4matic/trackparse/tree/main/go diff --git a/js/README.md b/js/README.md index 3c7167c..ca48b02 100644 --- a/js/README.md +++ b/js/README.md @@ -145,7 +145,7 @@ spec in order. | [`mode`](https://4matic.github.io/trackparse/guides/modes/) | `"auto"` | `"clean"`, `"youtube"`, `"filename"`, `"tracklist"`, or `"auto"` to detect from the string. See [Modes](#modes) | | [`uploader`](https://4matic.github.io/trackparse/guides/modes/#the-uploader-fallback) | – | YouTube channel name, used as the artist when there's no separator (`- Topic` and `VEVO` are dropped) | | [`knownArtists`](https://4matic.github.io/trackparse/guides/artists/#knownartists) | `[]` | Names that are never split. There is no built-in list | -| [`splitAnd`](https://4matic.github.io/trackparse/guides/artists/#and-is-special) | `"auto"` | `"auto"` splits on `and` only after a comma (`A, B and C`), so `Simon and Garfunkel` stays whole. Also `"always"`, `"never"` | +| [`splitAnd`](https://4matic.github.io/trackparse/guides/artists/#and-is-special) | `"auto"` | `"auto"` splits on `and` only after a comma or semicolon (`A, B and C`), so `Simon and Garfunkel` stays whole. Also `"always"`, `"never"` | | [`keywords`](https://4matic.github.io/trackparse/reference/options/#keywords) | – | Extra vocabulary, added to the built-in lists (see below) | ```js @@ -451,7 +451,7 @@ list.stats; ``` The [suggestion](https://4matic.github.io/trackparse/reference/warnings/#suggestions) exists because exactly one time, one digit away from `00:11:02`, -fits between its neighbours. With several candidates or none, `suggestion` is `null`. +fits between its neighbors. With several candidates or none, `suggestion` is `null`. [Open this list in the playground](https://4matic.github.io/trackparse/playground/#list=Hour%202%0A48%3A20%20Noisia%20-%20Stigma%0A52%3A47%20Mefjus%20%26%20Kasra%20-%20Bandwagon%20%28Phace%20Remix%29%0A56%3A05%20Black%20Sun%20Empire%20-%20ID%0A59%3A31%20Alix%20Perez%20-%20Fade%20Away%0A01%3A03%3A10%20Interview%20with%20Hybris%0A01%3A07%3A44%20Imanu%20-%20Sacrifice%0A00%3A11%3A02%20Current%20Value%20feat.%20Teddy%20Killerz%20-%20Payload%0A01%3A15%3A36%20Hybris%20-%20Spinning%20Top). `applyEdits` takes an array of [edit objects](https://4matic.github.io/trackparse/reference/tracklist/#edits) and only rewrites the lines they name: @@ -594,7 +594,7 @@ fixture input. You can parse in one language and read the result in another. | Python | [trackparse on PyPI](https://pypi.org/project/trackparse/) | `pip install trackparse` | [README](https://github.com/4matic/trackparse/blob/main/python/README.md) · [changelog](https://github.com/4matic/trackparse/blob/main/python/CHANGELOG.md) · [API](https://4matic.github.io/trackparse/reference/parse/) | | Rust | [trackparse on crates.io](https://crates.io/crates/trackparse) | `cargo add trackparse` | [README](https://github.com/4matic/trackparse/blob/main/rust/README.md) · [changelog](https://github.com/4matic/trackparse/blob/main/rust/CHANGELOG.md) · [API on docs.rs](https://docs.rs/trackparse) | | Go | [github.com/4matic/trackparse/go](https://pkg.go.dev/github.com/4matic/trackparse/go) | `go get github.com/4matic/trackparse/go` | [README](https://github.com/4matic/trackparse/blob/main/go/README.md) · [changelog](https://github.com/4matic/trackparse/blob/main/go/CHANGELOG.md) · [API on pkg.go.dev](https://pkg.go.dev/github.com/4matic/trackparse/go) | -| C / C++ | [C library and C++ header](https://github.com/4matic/trackparse/blob/main/c/README.md) | CMake FetchContent from the [release tarball](https://github.com/4matic/trackparse/releases), or the amalgamation | [README](https://github.com/4matic/trackparse/blob/main/c/README.md) · [changelog](https://github.com/4matic/trackparse/blob/main/c/CHANGELOG.md) · [header](https://github.com/4matic/trackparse/blob/main/c/include/trackparse.h) | +| C / C++ | [C library and C++ header](https://github.com/4matic/trackparse/blob/main/c/README.md) | CMake FetchContent from the [release tarball](https://github.com/4matic/trackparse/releases), or the amalgamation (from 0.7.0) | [README](https://github.com/4matic/trackparse/blob/main/c/README.md) · [changelog](https://github.com/4matic/trackparse/blob/main/c/CHANGELOG.md) · [header](https://github.com/4matic/trackparse/blob/main/c/include/trackparse.h) | ## Limitations diff --git a/python/README.md b/python/README.md index d72aeaf..11880b9 100644 --- a/python/README.md +++ b/python/README.md @@ -121,7 +121,7 @@ parse(input, *, mode="auto", uploader=None, known_artists=(), split_and="auto", parse_artists(input, *, ) -> list[Artist] format_track(track, *, feat="source", feat_marker=None, joiners="original", versions="all", producers=True, position=False) -> str -normalize(s) -> str +normalize(input) -> str all_artists(track) -> list[Artist] create_parser(**options) -> Parser # Parser.parse(...), Parser.parse_artists(...) SPEC_VERSION, __version__ @@ -147,7 +147,7 @@ spec in order. | [`mode`](https://4matic.github.io/trackparse/guides/modes/) | `"auto"` | `"clean"`, `"youtube"`, `"filename"`, `"tracklist"`, or `"auto"` to detect from the string. See [Modes](#modes) | | [`uploader`](https://4matic.github.io/trackparse/guides/modes/#the-uploader-fallback) | `None` | YouTube channel name, used as the artist when there's no separator (`- Topic` and `VEVO` are dropped) | | [`known_artists`](https://4matic.github.io/trackparse/guides/artists/#knownartists) | `()` | Names that are never split. There is no built-in list | -| [`split_and`](https://4matic.github.io/trackparse/guides/artists/#and-is-special) | `"auto"` | `"auto"` splits on `and` only after a comma (`A, B and C`), so `Simon and Garfunkel` stays whole. Also `"always"`, `"never"` | +| [`split_and`](https://4matic.github.io/trackparse/guides/artists/#and-is-special) | `"auto"` | `"auto"` splits on `and` only after a comma or semicolon (`A, B and C`), so `Simon and Garfunkel` stays whole. Also `"always"`, `"never"` | | [`keywords`](https://4matic.github.io/trackparse/reference/options/#keywords) | `None` | Extra vocabulary, added to the built-in lists (see below) | ```python @@ -284,7 +284,7 @@ format_track(t, feat_marker="featuring") format_track(t, position=True) # '01. Wilkinson ft. Becky Hill - Afterglow (Sub Focus Remix)' ``` -### `normalize(s)` +### `normalize(input)` **Docs:** [normalize](https://4matic.github.io/trackparse/reference/functions/#normalizeinput) @@ -444,7 +444,7 @@ tl.stats ``` The [suggestion](https://4matic.github.io/trackparse/reference/warnings/#suggestions) exists because exactly one time, one digit away from `00:11:02`, -fits between its neighbours. With several candidates or none, `suggestion` is `None`. +fits between its neighbors. With several candidates or none, `suggestion` is `None`. [Open this list in the playground](https://4matic.github.io/trackparse/playground/#list=Hour%202%0A48%3A20%20Noisia%20-%20Stigma%0A52%3A47%20Mefjus%20%26%20Kasra%20-%20Bandwagon%20%28Phace%20Remix%29%0A56%3A05%20Black%20Sun%20Empire%20-%20ID%0A59%3A31%20Alix%20Perez%20-%20Fade%20Away%0A01%3A03%3A10%20Interview%20with%20Hybris%0A01%3A07%3A44%20Imanu%20-%20Sacrifice%0A00%3A11%3A02%20Current%20Value%20feat.%20Teddy%20Killerz%20-%20Payload%0A01%3A15%3A36%20Hybris%20-%20Spinning%20Top). `apply_edits` takes a list of dicts with the [spec's keys](https://4matic.github.io/trackparse/reference/tracklist/#edits) (`op`, `line`, `seconds`, `lines`, `from`, @@ -597,7 +597,7 @@ fixture input. You can parse in one language and read the result in another. | Python | [trackparse on PyPI](https://pypi.org/project/trackparse/) | `pip install trackparse` | [README](https://github.com/4matic/trackparse/blob/main/python/README.md) · [changelog](https://github.com/4matic/trackparse/blob/main/python/CHANGELOG.md) · [API](https://4matic.github.io/trackparse/reference/parse/) | | Rust | [trackparse on crates.io](https://crates.io/crates/trackparse) | `cargo add trackparse` | [README](https://github.com/4matic/trackparse/blob/main/rust/README.md) · [changelog](https://github.com/4matic/trackparse/blob/main/rust/CHANGELOG.md) · [API on docs.rs](https://docs.rs/trackparse) | | Go | [github.com/4matic/trackparse/go](https://pkg.go.dev/github.com/4matic/trackparse/go) | `go get github.com/4matic/trackparse/go` | [README](https://github.com/4matic/trackparse/blob/main/go/README.md) · [changelog](https://github.com/4matic/trackparse/blob/main/go/CHANGELOG.md) · [API on pkg.go.dev](https://pkg.go.dev/github.com/4matic/trackparse/go) | -| C / C++ | [C library and C++ header](https://github.com/4matic/trackparse/blob/main/c/README.md) | CMake FetchContent from the [release tarball](https://github.com/4matic/trackparse/releases), or the amalgamation | [README](https://github.com/4matic/trackparse/blob/main/c/README.md) · [changelog](https://github.com/4matic/trackparse/blob/main/c/CHANGELOG.md) · [header](https://github.com/4matic/trackparse/blob/main/c/include/trackparse.h) | +| C / C++ | [C library and C++ header](https://github.com/4matic/trackparse/blob/main/c/README.md) | CMake FetchContent from the [release tarball](https://github.com/4matic/trackparse/releases), or the amalgamation (from 0.7.0) | [README](https://github.com/4matic/trackparse/blob/main/c/README.md) · [changelog](https://github.com/4matic/trackparse/blob/main/c/CHANGELOG.md) · [header](https://github.com/4matic/trackparse/blob/main/c/include/trackparse.h) | ## Limitations diff --git a/rust/README.md b/rust/README.md index 083421e..ae541fc 100644 --- a/rust/README.md +++ b/rust/README.md @@ -154,7 +154,7 @@ spec in order. | [`mode`](https://4matic.github.io/trackparse/guides/modes/) | `ModeOption::Auto` | `Clean`, `Youtube`, `Filename`, `Tracklist`, or `Auto` to detect from the string. See [Modes](#modes) | | [`uploader`](https://4matic.github.io/trackparse/guides/modes/#the-uploader-fallback) | `None` | YouTube channel name, used as the artist when there's no separator (`- Topic` and `VEVO` are dropped) | | [`known_artists`](https://4matic.github.io/trackparse/guides/artists/#knownartists) | empty | Names that are never split. There is no built-in list | -| [`split_and`](https://4matic.github.io/trackparse/guides/artists/#and-is-special) | `SplitAnd::Auto` | `Auto` splits on `and` only after a comma (`A, B and C`), so `Simon and Garfunkel` stays whole. Also `Always`, `Never` | +| [`split_and`](https://4matic.github.io/trackparse/guides/artists/#and-is-special) | `SplitAnd::Auto` | `Auto` splits on `and` only after a comma or semicolon (`A, B and C`), so `Simon and Garfunkel` stays whole. Also `Always`, `Never` | | [`keywords`](https://4matic.github.io/trackparse/reference/options/#keywords) | `None` | Extra vocabulary, added to the built-in lists (see below) | Options are built with chained setters. The structs are `#[non_exhaustive]`, so start from @@ -566,7 +566,7 @@ assert_eq!((stats.first_time, stats.last_time), (Some(2900.0), Some(4536.0))); ``` The [suggestion](https://4matic.github.io/trackparse/reference/warnings/#suggestions) exists because exactly one time, one digit away from `00:11:02`, -fits between its neighbours. With several candidates or none, `suggestion` is `None`. +fits between its neighbors. With several candidates or none, `suggestion` is `None`. [Open this list in the playground](https://4matic.github.io/trackparse/playground/#list=Hour%202%0A48%3A20%20Noisia%20-%20Stigma%0A52%3A47%20Mefjus%20%26%20Kasra%20-%20Bandwagon%20%28Phace%20Remix%29%0A56%3A05%20Black%20Sun%20Empire%20-%20ID%0A59%3A31%20Alix%20Perez%20-%20Fade%20Away%0A01%3A03%3A10%20Interview%20with%20Hybris%0A01%3A07%3A44%20Imanu%20-%20Sacrifice%0A00%3A11%3A02%20Current%20Value%20feat.%20Teddy%20Killerz%20-%20Payload%0A01%3A15%3A36%20Hybris%20-%20Spinning%20Top). [`apply_edits`](https://docs.rs/trackparse/latest/trackparse/tracklist/fn.apply_edits.html) takes a slice of [`Edit`](https://docs.rs/trackparse/latest/trackparse/tracklist/enum.Edit.html) @@ -730,7 +730,7 @@ difference is described under [Unicode version](#unicode-version). | Python | [trackparse on PyPI](https://pypi.org/project/trackparse/) | `pip install trackparse` | [README](https://github.com/4matic/trackparse/blob/main/python/README.md) · [changelog](https://github.com/4matic/trackparse/blob/main/python/CHANGELOG.md) · [API](https://4matic.github.io/trackparse/reference/parse/) | | Rust | [trackparse on crates.io](https://crates.io/crates/trackparse) | `cargo add trackparse` | [README](https://github.com/4matic/trackparse/blob/main/rust/README.md) · [changelog](https://github.com/4matic/trackparse/blob/main/rust/CHANGELOG.md) · [API on docs.rs](https://docs.rs/trackparse) | | Go | [github.com/4matic/trackparse/go](https://pkg.go.dev/github.com/4matic/trackparse/go) | `go get github.com/4matic/trackparse/go` | [README](https://github.com/4matic/trackparse/blob/main/go/README.md) · [changelog](https://github.com/4matic/trackparse/blob/main/go/CHANGELOG.md) · [API on pkg.go.dev](https://pkg.go.dev/github.com/4matic/trackparse/go) | -| C / C++ | [C library and C++ header](https://github.com/4matic/trackparse/blob/main/c/README.md) | CMake FetchContent from the [release tarball](https://github.com/4matic/trackparse/releases), or the amalgamation | [README](https://github.com/4matic/trackparse/blob/main/c/README.md) · [changelog](https://github.com/4matic/trackparse/blob/main/c/CHANGELOG.md) · [header](https://github.com/4matic/trackparse/blob/main/c/include/trackparse.h) | +| C / C++ | [C library and C++ header](https://github.com/4matic/trackparse/blob/main/c/README.md) | CMake FetchContent from the [release tarball](https://github.com/4matic/trackparse/releases), or the amalgamation (from 0.7.0) | [README](https://github.com/4matic/trackparse/blob/main/c/README.md) · [changelog](https://github.com/4matic/trackparse/blob/main/c/CHANGELOG.md) · [header](https://github.com/4matic/trackparse/blob/main/c/include/trackparse.h) | ## Limitations diff --git a/spec/fixtures/README.md b/spec/fixtures/README.md index 360c7c8..fa8a843 100644 --- a/spec/fixtures/README.md +++ b/spec/fixtures/README.md @@ -3,7 +3,7 @@ The shared test corpus: 13,130 cases, [1,203 written by hand](https://4matic.github.io/trackparse/project/testing/#handwritten-1203-cases) and [11,927 generated](https://4matic.github.io/trackparse/project/testing/#generated-11927-cases). Every port ([JavaScript](../../js/README.md), [Python](../../python/README.md), [Rust](../../rust/README.md), -[Go](../../go/README.md) and [C](https://github.com/4matic/trackparse/blob/main/c/README.md)) runs +[Go](../../go/README.md) and [C](../../c/README.md)) runs every case here. The fixtures, not any one implementation, define correct behaviour. @@ -64,8 +64,8 @@ The rule IDs in `rules` are the ones in [`../SPEC.md`](../SPEC.md), also shown o Every port implements this matcher (about 40 lines). It is the same everywhere: [`js/test/match.ts`](../../js/test/match.ts), [`python/tests/match.py`](../../python/tests/match.py), -`matches` in [`rust/tests/fixtures.rs`](../../rust/tests/fixtures.rs) and `matches` in -[`go/match_test.go`](../../go/match_test.go). +`matches` in [`rust/tests/fixtures.rs`](../../rust/tests/fixtures.rs), `matches` in +[`go/match_test.go`](../../go/match_test.go) and [`c/tests/match.c`](../../c/tests/match.c). 1. **Objects:** every key in `expected` must exist in `actual` and match recursively. Keys not in `expected` are ignored. An explicit `null` must be `null`. @@ -105,7 +105,7 @@ pnpm test # JavaScript: js/test/fixtures.test.ts (cd python && uv run pytest) # Python: python/tests/test_fixtures.py (cd rust && cargo test) # Rust: rust/tests/fixtures.rs (cd go && go test ./...) # Go: go/fixtures_test.go -(cd c && cmake -S . -B build && cmake --build build && ctest --test-dir build -R fixtures) +(cd c && cmake -S . -B build-test && cmake --build build-test && ctest --test-dir build-test -R fixtures) # C: c/tests/runner.c # one case, by id @@ -113,14 +113,14 @@ pnpm --filter trackparse exec vitest run test/fixtures.test.ts -t "brackets-vers (cd python && uv run pytest tests/test_fixtures.py -k "brackets-version-001") (cd rust && TRACKPARSE_ONLY=brackets-version-001 cargo test --test fixtures) (cd go && TRACKPARSE_ONLY=brackets-version-001 go test -run TestFixtures -v) -(cd c && TRACKPARSE_ONLY=brackets-version-001 ./build/trackparse-fixtures ../spec/fixtures/*/*.json) +(cd c && TRACKPARSE_ONLY=brackets-version-001 ./build-test/trackparse-fixtures ../spec/fixtures/*/*.json) # pass rate per fixture file and per spec rule pnpm conformance (cd python && uv run python scripts/conformance.py) (cd rust && TRACKPARSE_REPORT=1 cargo test --test fixtures -- --nocapture) (cd go && TRACKPARSE_REPORT=1 go test -run TestFixtures -v) -(cd c && TRACKPARSE_REPORT=1 ./build/trackparse-fixtures ../spec/fixtures/*/*.json) +(cd c && TRACKPARSE_REPORT=1 ./build-test/trackparse-fixtures ../spec/fixtures/*/*.json) # after pnpm build: the complete output of all five ports, compared node scripts/compare-ports.mjs diff --git a/spec/generator/README.md b/spec/generator/README.md index 0e1d9f8..cf25e61 100644 --- a/spec/generator/README.md +++ b/spec/generator/README.md @@ -95,5 +95,6 @@ pnpm --filter @trackparse/fixture-gen typecheck atom's expectation is wrong or the reference implementation disagrees with the spec. Fix the one that is wrong. Never edit generated files by hand. 5. Run the other ports on the new files (`cd python && uv run pytest`, `cd rust && cargo test`, - `cd go && go test ./...`), then [`node scripts/compare-ports.mjs`](../../scripts/compare-ports.mjs) + `cd go && go test ./...`, and in `c/` a CMake build with `ctest`, as in + [`../fixtures/README.md`](../fixtures/README.md#running-the-fixtures)), then [`node scripts/compare-ports.mjs`](../../scripts/compare-ports.mjs) from the repository root. It must print `differences: 0`. From 8bdda7cae802f792bc4e8c5f3f0e5a6214e68955 Mon Sep 17 00:00:00 2001 From: 4matic Date: Sun, 15 Nov 2026 04:35:38 +0200 Subject: [PATCH 3/5] docs(site): wide name tables become per-language tabs or naming rules, five tabs fit on phones, playground code scrolls instead of wrapping, the C install line before 0.7.0, checked examples in all five languages --- site/src/components/Install.astro | 26 ++++- site/src/components/Playground.astro | 8 +- site/src/content/docs/guides/artists.mdx | 13 ++- .../docs/guides/editing-tracklists.mdx | 100 ++++++++++++---- site/src/content/docs/guides/formatting.mdx | 39 +++++-- site/src/content/docs/guides/modes.mdx | 5 +- site/src/content/docs/guides/tracklists.mdx | 8 +- site/src/content/docs/project/contributing.md | 12 +- site/src/content/docs/project/how-it-works.md | 13 ++- .../docs/project/{ports.md => ports.mdx} | 88 ++++++++++++-- site/src/content/docs/project/roadmap.md | 3 +- site/src/content/docs/project/testing.md | 63 ++++++----- site/src/content/docs/reference/functions.mdx | 98 ++++++++++++++-- site/src/content/docs/reference/options.mdx | 37 +++--- site/src/content/docs/reference/parse.mdx | 2 +- site/src/content/docs/reference/tracklist.mdx | 107 ++++++++++++++---- site/src/content/docs/reference/warnings.mdx | 72 +++++++----- .../content/docs/start/getting-started.mdx | 10 +- site/src/content/docs/start/introduction.mdx | 78 ++++++++++--- site/src/lib/codegen.ts | 8 +- site/src/lib/lang.ts | 11 +- site/src/styles/custom.css | 13 +++ site/src/styles/playground.css | 13 +++ 23 files changed, 633 insertions(+), 194 deletions(-) rename site/src/content/docs/project/{ports.md => ports.mdx} (83%) diff --git a/site/src/components/Install.astro b/site/src/components/Install.astro index 8ff3d91..427df2b 100644 --- a/site/src/components/Install.astro +++ b/site/src/components/Install.astro @@ -4,7 +4,10 @@ // The switch shares its choice with the docs' language tabs and the playground (lib/lang.ts). import Check from "@lucide/astro/icons/check"; import Copy from "@lucide/astro/icons/copy"; -import { C_FETCHCONTENT, PACKAGE } from "../lib/lang"; +import { C_FETCHCONTENT, C_RELEASED, PACKAGE } from "../lib/lang"; + +const C_README = "https://github.com/4matic/trackparse/tree/main/c#readme"; +const C_SOURCE = "https://github.com/4matic/trackparse/tree/main/c#from-source"; const pms = [ { lang: "js", label: "npm" }, @@ -32,10 +35,21 @@ const command = (lang: (typeof pms)[number]["lang"]) => (lang === "c" ? C_FETCHC

Published on npm, PyPI,{" "} - crates.io and the Go module proxy; the C library is a tarball on{" "} - GitHub Releases. The Rust API docs are on{" "} - docs.rs, the Go API docs on pkg.go.dev, the C - API in the C README. + crates.io and the Go module proxy;{" "} + { + C_RELEASED ? ( + <> + the C library is a tarball on GitHub Releases. + + ) : ( + <> + the C library ships as a tarball on GitHub Releases from 0.7.0, which is not + out yet; until then, build it from the repository. + + ) + }{" "} + The Rust API docs are on docs.rs, the Go API docs on{" "} + pkg.go.dev, the C API in the C README.

@@ -54,6 +68,8 @@ const command = (lang: (typeof pms)[number]["lang"]) => (lang === "c" ? C_FETCHC } .seg { display: flex; + /* The buttons keep their height when the CMake lines make the box taller. */ + align-items: center; padding: 0.25rem; gap: 0.15rem; border-right: 1px solid var(--tp-border); diff --git a/site/src/components/Playground.astro b/site/src/components/Playground.astro index 1dfb765..b178aa0 100644 --- a/site/src/components/Playground.astro +++ b/site/src/components/Playground.astro @@ -23,7 +23,7 @@ const ref = { feat: doc(`guides/formatting/#options${frag("feat", '"source"')}`), joiners: doc(`guides/formatting/#options${frag("joiners", '"original"')}`), versions: doc(`guides/formatting/#options${frag("versions", '"all"')}`), - shift: doc(`reference/tracklist/#edits${frag("Edit::shift_from")}`), + shift: doc(`reference/tracklist/#edits${frag('"shift", seconds, from')}`), edits: doc("guides/editing-tracklists/#the-edits"), }; // The tracklist table's columns: entry fields in reference/tracklist, track fields in reference/parse. @@ -697,7 +697,7 @@ const listExamples: { label: string; title: string; text: string }[] = [ import { format, parse, type ParseOptions } from "trackparse"; import { applyEdits, parseTracklist, type Edit, type Tracklist, type TracklistEntry, type TracklistOptions } from "trackparse/tracklist"; import { icon } from "../lib/icons"; - import { getLang, PACKAGE, setLang, type Lang } from "../lib/lang"; + import { C_RELEASED, getLang, PACKAGE, setLang, type Lang } from "../lib/lang"; import { apiUrl, listCode, trackCode, type Snippet } from "../lib/codegen"; import { chip, codeHtml, GUIDE, escapeHtml, fieldsHtml, highlight, jsonHtml, KIND_LABEL, roleKind, segmentsHtml, type Kind } from "../lib/trackview"; @@ -823,8 +823,10 @@ const listExamples: { label: string; title: string; text: string }[] = [ for (const x of document.querySelectorAll("[data-lang]")) x.setAttribute("aria-pressed", String(x.dataset.lang === lang)); const p = PACKAGE[lang]; + // Before 0.7.0 there is no C release yet, so the FetchContent URL answers 404. + const pending = lang === "c" && !C_RELEASED ? " (from 0.7.0, not released yet)" : ""; const html = - `Install: ${escapeHtml(p.install)}` + + `Install: ${escapeHtml(p.install)}${pending}` + `Getting started` + `${p.registry}` + // The API docs: docs.rs for the crate, pkg.go.dev (the link above) for the module, the diff --git a/site/src/content/docs/guides/artists.mdx b/site/src/content/docs/guides/artists.mdx index 454fced..e50220a 100644 --- a/site/src/content/docs/guides/artists.mdx +++ b/site/src/content/docs/guides/artists.mdx @@ -80,8 +80,9 @@ Remixers live inside `versions`, not in `artists`. Use [`allArtists(track)`](/tr ## Joiners -`&`, `x`, `vs.`, `,`, `;`, `+`, `/` and `and` separate names. They're joiners, not roles: every name -they produce is still primary. +`&`, `x`, `vs.`, `,`, `;`, `+`, `/` and `and` separate names, and so do `b2b`, `meets`, `pres.` and +the others in [`joiners.json`](https://github.com/4matic/trackparse/blob/main/spec/data/joiners.json). +They're joiners, not roles: every name they produce is still primary. @@ -199,8 +200,8 @@ in the playground to see every joiner. ### `and` is special -`and` is common inside band names, so by default it only splits after a comma has already split the -same list: +`and` is common inside band names, so by default it only splits after a comma or semicolon has already +split the same list: @@ -484,7 +485,7 @@ trackparse_track_free(t); -Names are compared with full Unicode case folding and accents removed, so `Sigur Rós` and +Names are compared with full Unicode lowercasing and accents removed, so `Sigur Rós` and `SIGUR ROS` count as the same artist ([R9.2](/trackparse/reference/spec/#r9-assembly-and-dedup:~:text=R9.2%20Dedup)). [Try the example](/trackparse/playground/#track=Noisia%20feat.%20Foreign%20Beggars%20-%20Shellshock%20%28feat.%20Foreign%20Beggars%29) @@ -624,7 +625,7 @@ trackparse_parse_options_free(options); -A known name is matched case- and accent-insensitively wherever a credit list starts. It also +A known name is matched case- and accent-insensitively wherever a name starts in a credit list. It also protects names that begin with digits from being read as a track number (`3 Doors Down`). If you parse a lot of strings with the same names, put them in [`createParser`](/trackparse/reference/functions/#createparseroptions) (`create_parser` in Python, diff --git a/site/src/content/docs/guides/editing-tracklists.mdx b/site/src/content/docs/guides/editing-tracklists.mdx index bd3fd28..3d5ee81 100644 --- a/site/src/content/docs/guides/editing-tracklists.mdx +++ b/site/src/content/docs/guides/editing-tracklists.mdx @@ -217,8 +217,9 @@ it is an [`Edit`](https://pkg.go.dev/github.com/4matic/trackparse/go#Edit) struc In C the edits go into a `trackparse_edits` list from `trackparse_edits_new()`, one call per edit (`trackparse_edits_set_time(edits, line, seconds)`, `trackparse_edits_shift_from(edits, seconds, from)`), declared in [`trackparse.h`](https://github.com/4matic/trackparse/blob/main/c/include/trackparse.h). -The list copies what it is given, so it can be freed as soon as `trackparse_apply_edits` returns; -the result is freed with `trackparse_edit_result_free`. +The list copies the strings it is given, and the result owns its memory, so `trackparse_edits_free` +can run as soon as `trackparse_apply_edits` returns; the result is freed with +`trackparse_edit_result_free`. Lines 1 to 4 are untouched, CRLF included ([R13.9.1](/trackparse/reference/spec/#r139-edits:~:text=R13.9.1%20Locality)). Edits run in order, each on the text the previous one produced, with line numbers as that text has them. The @@ -228,22 +229,83 @@ does the same with buttons: the suggested fix, a shift and a sort, with undo. ## The edits There are six edits. JavaScript and Python write them the same way, as an object or a dict. Rust -and Go have a constructor for each, and C a function that appends it to a `trackparse_edits` list -(shortened here to the part after `trackparse_edits_`): - -| JavaScript and Python | Rust | Go | C | Effect | -|---|---|---|---|---| -| `{ op: "set-time", line, seconds }` | `Edit::set_time(line, seconds)` | `SetTime(line, seconds)` | `set_time(e, line, seconds)` | Rewrite the time on that line | -| `{ op: "shift", seconds }` | `Edit::shift(seconds)` | `Shift(seconds)` | `shift(e, seconds)` | Add `seconds` (negative to go back) to every timed line | -| `{ op: "shift", seconds, from }` | `Edit::shift_from(seconds, from)` | `ShiftFrom(seconds, from)` | `shift_from(e, seconds, from)` | The same, for every timed line from line `from` on | -| `{ op: "shift", seconds, lines }` | `Edit::shift_lines(seconds, lines)` | `ShiftLines(seconds, lines...)` | `shift_lines(e, seconds, lines, count)` | The same, for the listed lines only | -| `{ op: "sort-by-time" }` | `Edit::sort_by_time()` | `SortByTime()` | `sort_by_time(e)` | Reorder by time. Untimed lines move with the timed line above them, and lines before the first time stay on top | -| `{ op: "set-rest", line, rest }` | `Edit::set_rest(line, rest)` | `SetRest(line, rest)` | `set_rest(e, line, rest, len)` | Replace everything after the time, for example with `format(track)` ([`format_track`](/trackparse/reference/functions/#formattrack-options), Go `Format`, C `trackparse_format`) | -| `{ op: "insert", after, text }` | `Edit::insert(after, text)` | `Insert(after, text)` | `insert(e, after, text, len)` | Insert a line after line `after` (`0` puts it at the top). It gets the text's usual line ending | -| `{ op: "delete", line }` | `Edit::delete(line)` | `Delete(line)` | `delete(e, line)` | Remove a line | - -In Python the dict keys are quoted: `{"op": "set-time", "line": 3, "seconds": 90}`. Line numbers -start at 1. Sorting is [R13.9.4](/trackparse/reference/spec/#r139-edits:~:text=R13.9.4%20Sort), and inserting and deleting +and Go have a constructor for each, and C a function that appends it to a `trackparse_edits` list; +the tabs under the table give those names: + +| JavaScript and Python | Effect | +|---|---| +| `{ op: "set-time", line, seconds }` | Rewrite the time on that line | +| `{ op: "shift", seconds }` | Add `seconds` (negative to go back) to every timed line | +| `{ op: "shift", seconds, from }` | The same, for every timed line from line `from` on | +| `{ op: "shift", seconds, lines }` | The same, for the listed lines only | +| `{ op: "sort-by-time" }` | Reorder by time. Untimed lines move with the timed line above them, and lines before the first time stay on top | +| `{ op: "set-rest", line, rest }` | Replace everything after the time, for example with `format(track)` (Python and Rust [`format_track`](/trackparse/reference/functions/#formattrack-options), Go `Format`, C `trackparse_format`) | +| `{ op: "insert", after, text }` | Insert a line after line `after` (`0` puts it at the top). It gets the text's usual line ending | +| `{ op: "delete", line }` | Remove a line | + + + + +An edit is an object with an `op` and the fields in the table. + + + + +An edit is a dict with the same keys, quoted: `{"op": "set-time", "line": 3, "seconds": 90}`. + + + + +Each edit has a constructor on `Edit`. + +| Edit | Rust | +|---|---| +| `set-time` | `Edit::set_time(line, seconds)` | +| `shift` | `Edit::shift(seconds)` | +| `shift` with `from` | `Edit::shift_from(seconds, from)` | +| `shift` with `lines` | `Edit::shift_lines(seconds, lines)` | +| `sort-by-time` | `Edit::sort_by_time()` | +| `set-rest` | `Edit::set_rest(line, rest)` | +| `insert` | `Edit::insert(after, text)` | +| `delete` | `Edit::delete(line)` | + + + + +Each edit has a constructor in the package, such as `trackparse.SetTime`. + +| Edit | Go | +|---|---| +| `set-time` | `SetTime(line, seconds)` | +| `shift` | `Shift(seconds)` | +| `shift` with `from` | `ShiftFrom(seconds, from)` | +| `shift` with `lines` | `ShiftLines(seconds, lines...)` | +| `sort-by-time` | `SortByTime()` | +| `set-rest` | `SetRest(line, rest)` | +| `insert` | `Insert(after, text)` | +| `delete` | `Delete(line)` | + + + + +Each edit is a function that appends it to a `trackparse_edits` list. + +| Edit | C | +|---|---| +| `set-time` | `trackparse_edits_set_time(e, line, seconds)` | +| `shift` | `trackparse_edits_shift(e, seconds)` | +| `shift` with `from` | `trackparse_edits_shift_from(e, seconds, from)` | +| `shift` with `lines` | `trackparse_edits_shift_lines(e, seconds, lines, count)` | +| `sort-by-time` | `trackparse_edits_sort_by_time(e)` | +| `set-rest` | `trackparse_edits_set_rest(e, line, rest, len)` | +| `insert` | `trackparse_edits_insert(e, after, text, len)` | +| `delete` | `trackparse_edits_delete(e, line)` | + + + + + +Line numbers start at 1. Sorting is [R13.9.4](/trackparse/reference/spec/#r139-edits:~:text=R13.9.4%20Sort), and inserting and deleting [R13.9.5](/trackparse/reference/spec/#r139-edits:~:text=R13.9.5%20Insert%20and%20delete). This example sorts a list, rewrites one line's track text with @@ -375,7 +437,7 @@ after the insert the outro is line 4. ## Times keep their style -A rewritten time looks like its neighbours. Hours or no hours, digit widths and fraction digits are +A rewritten time looks like its neighbors. Hours or no hours, digit widths and fraction digits are all kept, so `52:47` plus 45 seconds is `53:32`, not `00:53:32` ([R13.9.2](/trackparse/reference/spec/#r139-edits:~:text=R13.9.2%20Time%20style)). diff --git a/site/src/content/docs/guides/formatting.mdx b/site/src/content/docs/guides/formatting.mdx index 06ec603..ae99579 100644 --- a/site/src/content/docs/guides/formatting.mdx +++ b/site/src/content/docs/guides/formatting.mdx @@ -119,20 +119,14 @@ are typed string constants ([`FeatPlacement`](https://pkg.go.dev/github.com/4mat Since a Go `bool` field defaults to `false`, `producers` becomes `OmitProducers`. C takes a `trackparse_format_options` handle from `trackparse_format_options_new()`, with one setter per option and C enums for the values; an option you don't set keeps its default, and -`trackparse_format_options_free` releases the handle: - -| Option | Python | Rust | Go | C | -|---|---|---|---|---| -| `feat` | `feat="title"` | `.feat(FeatPlacement::Title)`: `Source`, `Artist`, `Title`, `Omit` | `Feat: trackparse.FeatTitle`: `FeatSource`, `FeatArtist`, `FeatTitle`, `FeatOmit` | `trackparse_format_options_set_feat(o, TRACKPARSE_FEAT_TITLE)`: `_SOURCE`, `_ARTIST`, `_TITLE`, `_OMIT` | -| `featMarker` | `feat_marker="featuring"` | `.feat_marker("featuring")` | `FeatMarker: trackparse.Ptr("featuring")` (a `*string`) | `trackparse_format_options_set_feat_marker(o, "featuring", TRACKPARSE_NUL_TERMINATED)` | -| `joiners` | `joiners="canonical"` | `.joiners(JoinerStyle::Canonical)`: `Original`, `Canonical` | `Joiners: trackparse.JoinersCanonical`: `JoinersOriginal`, `JoinersCanonical` | `trackparse_format_options_set_joiners(o, TRACKPARSE_JOINERS_CANONICAL)`: `_ORIGINAL`, `_CANONICAL` | -| `versions` | `versions="none"` | `.versions(VersionsOption::None)`: `All`, `None` | `Versions: trackparse.VersionsNone`: `VersionsAll`, `VersionsNone` | `trackparse_format_options_set_versions(o, TRACKPARSE_VERSIONS_NONE)`: `_ALL`, `_NONE` | -| `producers` | `producers=False` | `.producers(false)` | `OmitProducers: true` | `trackparse_format_options_set_omit_producers(o, true)` | -| `position` | `position=True` | `.position(true)` | `Position: true` | `trackparse_format_options_set_position(o, true)` | +`trackparse_format_options_free` releases the handle. Each tab below starts with the names in +that language. +The names and values are those of the table above, as keys of one object. + ```js format(t, { feat: "title" }); // 'Wilkinson - Afterglow (ft. Becky Hill & Tom Cane) (Sub Focus VIP Remix)' @@ -154,6 +148,10 @@ format(parse("Future - Mask Off (prod. by Metro Boomin)"), { producers: false }) +- `feat="title"`: `"source"`, `"artist"`, `"title"` or `"omit"` +- `feat_marker="featuring"`, `joiners="canonical"`, `versions="none"` +- `producers=False`, `position=True` + ```python format_track(t, feat="title") # 'Wilkinson - Afterglow (ft. Becky Hill & Tom Cane) (Sub Focus VIP Remix)' @@ -175,6 +173,12 @@ format_track(parse("Future - Mask Off (prod. by Metro Boomin)"), producers=False +- `.feat(FeatPlacement::Title)`: `Source`, `Artist`, `Title` or `Omit` +- `.feat_marker("featuring")` +- `.joiners(JoinerStyle::Canonical)`: `Original` or `Canonical` +- `.versions(VersionsOption::None)`: `All` or `None` +- `.producers(false)`, `.position(true)` + ```rust use trackparse::{format_track_with, FeatPlacement, FormatOptions, JoinerStyle, VersionsOption}; @@ -204,6 +208,12 @@ format_track_with( +- `Feat: trackparse.FeatTitle`: `FeatSource`, `FeatArtist`, `FeatTitle` or `FeatOmit` +- `FeatMarker: trackparse.Ptr("featuring")` (a `*string`) +- `Joiners: trackparse.JoinersCanonical`: `JoinersOriginal` or `JoinersCanonical` +- `Versions: trackparse.VersionsNone`: `VersionsAll` or `VersionsNone` +- `OmitProducers: true` for `producers: false`, and `Position: true` + ```go fmt.Printf("%q\n", trackparse.FormatWith(t, trackparse.FormatOptions{Feat: trackparse.FeatTitle})) // "Wilkinson - Afterglow (ft. Becky Hill & Tom Cane) (Sub Focus VIP Remix)" @@ -234,6 +244,15 @@ fmt.Printf("%q\n", trackparse.FormatWith( +- `trackparse_format_options_set_feat(o, TRACKPARSE_FEAT_TITLE)`: `_SOURCE`, `_ARTIST`, `_TITLE` + or `_OMIT` +- `trackparse_format_options_set_feat_marker(o, "featuring", TRACKPARSE_NUL_TERMINATED)` +- `trackparse_format_options_set_joiners(o, TRACKPARSE_JOINERS_CANONICAL)`: `_ORIGINAL` or + `_CANONICAL` +- `trackparse_format_options_set_versions(o, TRACKPARSE_VERSIONS_NONE)`: `_ALL` or `_NONE` +- `trackparse_format_options_set_omit_producers(o, true)` for `producers: false` +- `trackparse_format_options_set_position(o, true)` + ```c trackparse_format_options *o = trackparse_format_options_new(); trackparse_format_options_set_feat(o, TRACKPARSE_FEAT_TITLE); diff --git a/site/src/content/docs/guides/modes.mdx b/site/src/content/docs/guides/modes.mdx index 76edd84..24575b1 100644 --- a/site/src/content/docs/guides/modes.mdx +++ b/site/src/content/docs/guides/modes.mdx @@ -24,7 +24,8 @@ The resolved mode is in `track.mode`, so you can always see which one ran. You p which has no `Auto`. In Go both are the string type [`Mode`](https://pkg.go.dev/github.com/4matic/trackparse/go#Mode): [`trackparse.ModeAuto`](https://pkg.go.dev/github.com/4matic/trackparse/go#ModeAuto) (`"auto"`) asks for auto, an empty `Mode` in `ParseOptions` means auto too, and `Track.Mode` is never `ModeAuto`. In C both are the enum `trackparse_mode`: -`TRACKPARSE_MODE_AUTO` is the default of `trackparse_parse_options_set_mode`, and a result's +`TRACKPARSE_MODE_AUTO` is what a new options handle uses until `trackparse_parse_options_set_mode` +changes it, and a result's `mode` is never `TRACKPARSE_MODE_AUTO`; `trackparse_mode_name` gives the name. The mode rules are [R2](/trackparse/reference/spec/#r2-mode-prelude) in the spec. @@ -32,7 +33,7 @@ means auto too, and `Track.Mode` is never `ModeAuto`. In C both are the enum `tr 1. A known audio or video extension at the end (`.mp3`, `.flac`, `.wav`, `.mp4`…) means `filename`. -2. Junk, a `|`, or a platform suffix like `- YouTube` means `youtube`. +2. Junk (a genre bracket doesn't count), a `|`, or a platform suffix like `- YouTube` means `youtube`. 3. Anything else is `clean`. That order is [R2.1](/trackparse/reference/spec/#r2-mode-prelude:~:text=R2.1%20Resolution). Open the diff --git a/site/src/content/docs/guides/tracklists.mdx b/site/src/content/docs/guides/tracklists.mdx index 16dd25d..d5cdaa2 100644 --- a/site/src/content/docs/guides/tracklists.mdx +++ b/site/src/content/docs/guides/tracklists.mdx @@ -269,7 +269,7 @@ printf("%d %d %d %d %g %g\n", s->lines, s->tracks, s->markers, s->timed, *s->fir -Paste it into the [playground](/trackparse/playground/#list=Hour%202%0A48%3A20%20Noisia%20-%20Stigma%0A52%3A47%20Mefjus%20%26%20Kasra%20-%20Bandwagon%20(Phace%20Remix)%0A56%3A05%20Black%20Sun%20Empire%20-%20ID%0A59%3A31%20Alix%20Perez%20-%20Fade%20Away%0A01%3A03%3A10%20Interview%20with%20Hybris%0A01%3A07%3A44%20Imanu%20-%20Sacrifice%0A00%3A11%3A02%20Current%20Value%20feat.%20Teddy%20Killerz%20-%20Payload%0A01%3A15%3A36%20Hybris%20-%20Spinning%20Top) +Paste it into the [playground](/trackparse/playground/#list=Hour%202%0A48%3A20%20Noisia%20-%20Stigma%0A52%3A47%20Mefjus%20%26%20Kasra%20-%20Bandwagon%20%28Phace%20Remix%29%0A56%3A05%20Black%20Sun%20Empire%20-%20ID%0A59%3A31%20Alix%20Perez%20-%20Fade%20Away%0A01%3A03%3A10%20Interview%20with%20Hybris%0A01%3A07%3A44%20Imanu%20-%20Sacrifice%0A00%3A11%3A02%20Current%20Value%20feat.%20Teddy%20Killerz%20-%20Payload%0A01%3A15%3A36%20Hybris%20-%20Spinning%20Top) to see the table, the warnings and the fix button. ## Nothing is lost @@ -464,7 +464,7 @@ DJ tracklists mark a track played over the previous one, like an acapella on the `w/` where the track number would go. Such a line gets `layered: true`. The `w/` stays in `rest` and is left out of the parsed track. An untimed layered line plays at the previous track's time, so it doesn't warn [`time-missing`](/trackparse/reference/warnings/#tracklist-warnings:~:text=time%2Dmissing), -and it doesn't count as a neighbour for bare track numbers. [Open the +and it doesn't count as a neighbor for bare track numbers. [Open the example](/trackparse/playground/#list=00%3A00%20Noisia%20-%20Stigma%0Aw%2F%20Phace%20-%20Psycho%20%28Acapella%29%0A03%3A10%20Mefjus%20-%20Sleepless) in the playground. @@ -770,7 +770,7 @@ each language. To apply a suggestion, see Some lists number their lines without a dot: `1 Artist - Title`, `2 Artist - Title`. A single [`parse()`](/trackparse/reference/parse/) call would read `1 Artist` as the artist's name, and it should, because `2 Unlimited` -exists. In a list, trackparse looks at the neighbours: a bare number counts as a position when the +exists. In a list, trackparse looks at the neighbors: a bare number counts as a position when the nearest line before or after it carries the next or previous number ([R13.5](/trackparse/reference/spec/#r135-bare-positions)). @@ -788,7 +788,7 @@ parsed with `mode: "tracklist"` ([Modes](/trackparse/guides/modes/#tracklist-mod | `10 Optiv & BTK-Inception (Gydra remix)` | no separator | position 10, Optiv, BTK / `Inception`, remix by Gydra | The first three open in the playground in tracklist mode; set the mode back to `auto` there to see -what a plain `parse()` makes of them. The last two need neighbours: the position needs a 7 or 9 next to it, and the unspaced +what a plain `parse()` makes of them. The last two need neighbors: the position needs a 7 or 9 next to it, and the unspaced `BTK-Inception` dash only splits on a timed line when at least half the list uses spaced dashes. ## JSON diff --git a/site/src/content/docs/project/contributing.md b/site/src/content/docs/project/contributing.md index 717aa28..00ff3a2 100644 --- a/site/src/content/docs/project/contributing.md +++ b/site/src/content/docs/project/contributing.md @@ -121,15 +121,15 @@ by file; [`c/src/PORTING.md`](https://github.com/4matic/trackparse/blob/main/c/s the conventions. ```sh -cmake -S c -B c/build -DTRACKPARSE_WERROR=ON -cmake --build c/build -ctest --test-dir c/build --output-on-failure # fixtures, schema check, unit tests -TRACKPARSE_REPORT=1 c/build/trackparse-fixtures spec/fixtures/*/*.json # pass rate per file and per rule -TRACKPARSE_ONLY=brackets-version-001 c/build/trackparse-fixtures spec/fixtures/*/*.json # one case +cmake -S c -B c/build-test -DTRACKPARSE_WERROR=ON +cmake --build c/build-test +ctest --test-dir c/build-test --output-on-failure # fixtures, schema check, unit tests +TRACKPARSE_REPORT=1 c/build-test/trackparse-fixtures spec/fixtures/*/*.json # pass rate per file and per rule +TRACKPARSE_ONLY=brackets-version-001 c/build-test/trackparse-fixtures spec/fixtures/*/*.json # one case cmake -S c -B c/build-asan -DTRACKPARSE_SANITIZE=ON # the same suite under ASan and UBSan node c/scripts/gen_data.mjs # regenerate src/data_gen.c from spec/data node c/scripts/gen_unicode.mjs # regenerate src/unicode_gen.c -node c/scripts/amalgamate.mjs # write c/dist/trackparse.c and trackparse.h +node c/scripts/amalgamate.mjs # write trackparse.c, .h and .hpp into c/dist ``` `src/` uses no `strtod`, no float `printf`, no `` and no `qsort`: the first three follow diff --git a/site/src/content/docs/project/how-it-works.md b/site/src/content/docs/project/how-it-works.md index f74f9b0..fd73bee 100644 --- a/site/src/content/docs/project/how-it-works.md +++ b/site/src/content/docs/project/how-it-works.md @@ -5,8 +5,8 @@ description: The parsing pipeline, why it has no regex lookaround, and how track trackparse is a fixed pipeline of small hand-written scanners. There are no regexes with lookaround or backreferences, so nothing backtracks. A 10,000-code-point input takes at most tens of -milliseconds in JavaScript, Rust and Go, and well under a second in Python. -The same design is what lets the JavaScript, Python, Rust, Go and C packages give the same output: +milliseconds in JavaScript, Rust, Go and C, and well under a second in Python. The same design +is what lets the JavaScript, Python, Rust, Go and C packages give the same output: each step is a short function that reads the same way in all five languages. Each step below is a rule group in the [spec](/trackparse/reference/spec/): @@ -28,8 +28,9 @@ exposes its first step on its own. Every port keeps one source file per step, wi IDs in the comments: [`js/src`](https://github.com/4matic/trackparse/tree/main/js/src), [`python/src/trackparse`](https://github.com/4matic/trackparse/tree/main/python/src/trackparse), -[`rust/src`](https://github.com/4matic/trackparse/tree/main/rust/src) and -[`go`](https://github.com/4matic/trackparse/tree/main/go). +[`rust/src`](https://github.com/4matic/trackparse/tree/main/rust/src), +[`go`](https://github.com/4matic/trackparse/tree/main/go) and +[`c/src`](https://github.com/4matic/trackparse/tree/main/c/src). ## Brackets first @@ -73,7 +74,7 @@ every port gives the same bytes: - A "digit" is `0` to `9` and nothing else. - "Letter" and "uppercase letter" mean the Unicode general categories L and Lu, not whatever a language's `isalpha` accepts ([R0.6](/trackparse/reference/spec/#r0-portability:~:text=R0.6%20Letter%20means)). -- Any string must produce a result. Nothing throws or panics ([R0.8](/trackparse/reference/spec/#r0-portability:~:text=R0.8%20Parsing%20is)). +- Any string must produce a result. Nothing throws or panics, and the C library returns `NULL` only when memory runs out ([R0.8](/trackparse/reference/spec/#r0-portability:~:text=R0.8%20Parsing%20is)). [Ports](/trackparse/project/ports/) lists the places where a language's standard library disagreed with these rules. @@ -84,7 +85,7 @@ with these rules. lines, keeping each line's terminator. A small scanner reads the time at the start of each line, and the rest goes through [`parse()`](/trackparse/reference/parse/) in tracklist mode. -Two decisions look across lines. A bare track number is only accepted when a neighbour continues +Two decisions look across lines. A bare track number is only accepted when a neighbor continues the sequence. And an unspaced dash only splits when at least half the list uses spaced dashes. To make both decisions without parsing everything twice, each line first gets a cheap probe (time, normalization, prefixes), then one real parse. The checks run last, over the finished entries. diff --git a/site/src/content/docs/project/ports.md b/site/src/content/docs/project/ports.mdx similarity index 83% rename from site/src/content/docs/project/ports.md rename to site/src/content/docs/project/ports.mdx index fd9501e..34ebb3f 100644 --- a/site/src/content/docs/project/ports.md +++ b/site/src/content/docs/project/ports.mdx @@ -3,6 +3,8 @@ title: Ports description: The JavaScript, Python, Rust, Go and C implementations, and what it takes to add another language. --- +import { Tabs, TabItem } from "@astrojs/starlight/components"; + | Language | Package | Status | |---|---|---| | JavaScript / TypeScript | [`trackparse`](https://www.npmjs.com/package/trackparse) on npm | Reference implementation. 13,130 / 13,130 fixtures. Tracklists in `trackparse/tracklist` | @@ -11,16 +13,78 @@ description: The JavaScript, Python, Rust, Go and C implementations, and what it | Go | [`github.com/4matic/trackparse/go`](https://pkg.go.dev/github.com/4matic/trackparse/go), API docs on [pkg.go.dev](https://pkg.go.dev/github.com/4matic/trackparse/go) | 13,130 / 13,130 fixtures, output identical to JS. Tracklists in the same package (`trackparse.ParseTracklist`) | | C | Source tarball and amalgamation on each [GitHub Release](https://github.com/4matic/trackparse/releases) from 0.7.0; the API is [`trackparse.h`](https://github.com/4matic/trackparse/blob/main/c/include/trackparse.h) | 13,130 / 13,130 fixtures, output identical to JS. Tracklists in the same library (`trackparse_parse_tracklist`) | -| | JavaScript | Python | Rust | Go | C | -|---|---|---|---|---|---| -| Install | `npm install trackparse` | `pip install trackparse` | `cargo add trackparse` | `go get github.com/4matic/trackparse/go@latest` | CMake `FetchContent` from the release tarball, or copy the amalgamation | -| Needs | Node 18 or newer, or any ES2020 runtime | Python 3.9 or newer | Rust 1.74 or newer | Go 1.22 or newer | a C11 compiler (GCC, Clang or MSVC); CMake 3.16 or newer for the CMake build | -| Dependencies | none | none | `unicode-normalization`; `serde` is optional | none | none beyond the C standard library and the system's threads | -| Types | TypeScript types included | `py.typed`, passes `mypy --strict` | structs and enums, no `unsafe` | structs and typed string constants, no `unsafe`, no cgo | read-only structs, C enums with `_name()` functions, opaque option handles | -| Names | [`parseArtists`](/trackparse/reference/functions/#parseartistsinput-options), [`fullTitle`](/trackparse/reference/parse/#parsedtrack) | `parse_artists`, `full_title` | `parse_artists`, `full_title` | `ParseArtists`, `FullTitle` | `trackparse_parse_artists`, `full_title` | -| Options | one object | keyword arguments | `_with` functions and option builders | `With` functions and option structs | `_with` functions and option handles with setters | -| On bad input | never throws on a string | `TypeError` if the input isn't a `str` | never panics, no `Result` | never panics, no `error` | never crashes; `NULL` only when memory runs out | -| JSON | `JSON.stringify(track)` | `track.to_dict()` | `track.to_json()`, or `serde` | `json.Marshal(track)` | `trackparse_track_to_json(track)` | + + + +| What | JavaScript | +|---|---| +| Install | `npm install trackparse` | +| Needs | Node 18 or newer, or any ES2020 runtime | +| Dependencies | none | +| Types | TypeScript types included | +| Names | [`parseArtists`](/trackparse/reference/functions/#parseartistsinput-options), [`fullTitle`](/trackparse/reference/parse/#parsedtrack) | +| 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.0) | +| 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](/trackparse/start/getting-started/) has the install steps, and [Other functions](/trackparse/reference/functions/) has the full table of names. @@ -32,7 +96,7 @@ the tag `go/vX.Y.Z`, which the Go module proxy reads ([published versions](https://proxy.golang.org/github.com/4matic/trackparse/go/@v/list)). 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. 0.7.0 is the first. The +`SHA256SUMS` attached to its GitHub Release, starting with 0.7.0. The [changelogs](/trackparse/project/roadmap/#next) list what each release brought. ## Adding a language @@ -150,7 +214,7 @@ JavaScript's `trim()`, WHATWG UTF-8, key order, stable sorts). What C added: - **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:precise` on MSVC), `num.c` sets the standard pragma where the compiler - honours it, and the product goes through a `volatile`, so the amalgamation is safe under other + honors it, and the product goes through a `volatile`, so the amalgamation is safe under other flags too. On 32-bit x86, x87 registers compute with extra precision, so `num.c` refuses to compile unless `FLT_EVAL_METHOD` is 0 (`-msse2 -mfpmath=sse`). - **Unicode tables from Node, as in Go.** The C library can't take letters, lowercasing or diff --git a/site/src/content/docs/project/roadmap.md b/site/src/content/docs/project/roadmap.md index 6f2062b..091baf7 100644 --- a/site/src/content/docs/project/roadmap.md +++ b/site/src/content/docs/project/roadmap.md @@ -35,7 +35,8 @@ The changelogs list what has shipped so far: [Python](https://github.com/4matic/trackparse/blob/main/python/CHANGELOG.md), [Rust](https://github.com/4matic/trackparse/blob/main/rust/CHANGELOG.md), [Go](https://github.com/4matic/trackparse/blob/main/go/CHANGELOG.md) and the -[spec](https://github.com/4matic/trackparse/blob/main/spec/CHANGELOG.md). +[spec](https://github.com/4matic/trackparse/blob/main/spec/CHANGELOG.md). The C library gets its +changelog (`c/CHANGELOG.md`) with 0.7.0, its first release. ## See also diff --git a/site/src/content/docs/project/testing.md b/site/src/content/docs/project/testing.md index e4fdde9..4b31ebc 100644 --- a/site/src/content/docs/project/testing.md +++ b/site/src/content/docs/project/testing.md @@ -53,16 +53,36 @@ Each port throws thousands of random strings at the parser to check the [invariants](/trackparse/reference/spec/#invariants) from the spec. The JavaScript suite uses [fast-check](https://github.com/dubzzz/fast-check) and the Python suite uses [Hypothesis](https://hypothesis.works). The Rust, Go and C suites each have a small seeded -generator of their own, so none of them needs an extra test dependency. The Go module also has -fuzz targets for `Parse`, [`ParseArtists`](/trackparse/reference/functions/#parseartistsinput-options), `Format`, [`ParseTracklist`](/trackparse/reference/tracklist/#parsetracklisttext-options), [`ApplyEdits`](/trackparse/reference/tracklist/#applyeditstext-edits-options), `Track.UnmarshalJSON` and the -internal pipeline (`go test -fuzz`) that run the same checks on whatever the fuzzer finds, and a -test that calls the parser, the tracklist functions and the edits from 16 goroutines at once under -the race detector. +generator of their own, so none of them needs an extra test dependency. The checks: + +- it never throws or panics, on any input, in any mode; +- a 10,000-code-point input finishes inside a ceiling: 1 s in JavaScript and Python, 2 s in Rust, + Go and C (Go and C widen it ten times under the race detector or a sanitizer). It normally + takes tens of milliseconds in JavaScript and Rust, a few milliseconds in Go and C, and well + under a second in Python. The ceiling is loose so that a busy CI machine doesn't fail the run + but a blowup does; +- [`normalize`](/trackparse/reference/functions/#normalizeinput) is idempotent; +- whitespace, dash and zero-width noise don't change the result; +- every output validates against the JSON Schema (JavaScript and Python with a schema library, + Go with a small validator of its own, C through a Node script that checks every output the + fixture runner writes; the Rust output is compared with JavaScript byte for byte instead, see + below); +- no word of the input goes missing from the output (the Rust, Go and C suites); +- `parse(format(parse(s)))` round-trips. + +The Go module also has fuzz targets for `Parse`, +[`ParseArtists`](/trackparse/reference/functions/#parseartistsinput-options), `Format`, +[`ParseTracklist`](/trackparse/reference/tracklist/#parsetracklisttext-options), +[`ApplyEdits`](/trackparse/reference/tracklist/#applyeditstext-edits-options), +`Track.UnmarshalJSON` and the internal pipeline (`go test -fuzz`) that run the same checks on +whatever the fuzzer finds, and a test that calls the parser, the tracklist functions and the edits +from 16 goroutines at once under the race detector. The C library has the same kinds of tests, plus a few that only C needs: - libFuzzer targets for `parse`, `parse_artists`, `format`, `parse_tracklist`, `apply_edits` and - the JSON reader of the tests, seeded with every fixture input and checking the same invariants; + the JSON door that the cross-port diff runs, seeded with every fixture input and checking the + same invariants; - an out-of-memory test: for about 50 inputs across the API, the n-th allocation fails, for every n until the call succeeds, and each call must return `NULL` or the correct result and free every block it took; @@ -74,21 +94,6 @@ The C library has the same kinds of tests, plus a few that only C needs: MemorySanitizer and Valgrind, so an out-of-bounds read, an uninitialized value, a leak or undefined behaviour fails it. -- it never throws or panics, on any input, in any mode; -- a 10,000-code-point input finishes inside a ceiling: 1 s in JavaScript and Python, 2 s in Rust, - Go and C (Go and C widen it ten times under the race detector or a sanitizer). - It normally takes tens of milliseconds in JavaScript and Rust, a few milliseconds in Go and C and - well under a second in Python; - the ceiling is loose so that a busy CI machine doesn't - fail the run but a blowup does; -- [`normalize`](/trackparse/reference/functions/#normalizeinput) is idempotent; -- whitespace, dash and zero-width noise don't change the result; -- every output validates against the JSON Schema (JavaScript, Python, Go and C, where the fixture - runner writes every output and a Node script checks it; the Rust output is compared with - JavaScript byte for byte instead, see below); -- no word of the input goes missing from the output (the Rust, Go and C suites); -- `parse(format(parse(s)))` round-trips. - For tracklists, on random multi-line text and random edit lists: - `raw + eol` over all entries gives back the input, and `lead + time + gap + rest` gives `raw`; @@ -111,7 +116,7 @@ JSON output, tracklists and edits included. The difference count is zero. same with random input, which reaches places no fixture does. The Rust crate and the Go module were each run against JavaScript on about 500,000 random single-track cases and 290,000 random tracklists with edits, again with zero differences. CI runs the C library against JavaScript on -50,000 random tracks and 10,000 tracklists on every push. +50,000 random tracks and 10,000 tracklists on every push and pull request that `c.yml` runs on. ## Real tracklists @@ -121,7 +126,8 @@ became a handwritten fixture instead, which is why the tracklist fixtures talk a ## In CI -Every push runs one workflow per port, plus one for the spec: +Every push to `main` runs one workflow per port, plus one for the spec. A pull request runs the +workflows whose files it touches: | Workflow | What it runs | |---|---| @@ -157,10 +163,10 @@ TRACKPARSE_REPORT=1 go test -run TestFixtures -v . # pass rate per file and pe # C (a C11 compiler, CMake 3.16 or newer) cd .. -cmake -S c -B c/build -cmake --build c/build -ctest --test-dir c/build --output-on-failure # the same fixtures, schema check, unit tests -TRACKPARSE_REPORT=1 c/build/trackparse-fixtures spec/fixtures/*/*.json # pass rate per file and per rule +cmake -S c -B c/build-test +cmake --build c/build-test +ctest --test-dir c/build-test --output-on-failure # the same fixtures, schema check, unit tests +TRACKPARSE_REPORT=1 c/build-test/trackparse-fixtures spec/fixtures/*/*.json # pass rate per file and per rule cmake -S c -B c/build-asan -DTRACKPARSE_SANITIZE=ON # the same suite under ASan and UBSan cmake --build c/build-asan && ctest --test-dir c/build-asan -LE consumer @@ -170,6 +176,9 @@ node scripts/compare-ports.mjs # must print "differences: 0" node scripts/fuzz-ports.mjs # the same diff on random tracks and tracklists with edits ``` +The C suite builds in `c/build-test`, not `c/build`: `compare-ports` configures `c/build` with the +tests off. + ## See also - [Ports](/trackparse/project/ports/) for what each port had to get right. diff --git a/site/src/content/docs/reference/functions.mdx b/site/src/content/docs/reference/functions.mdx index 05067e5..a1d06f8 100644 --- a/site/src/content/docs/reference/functions.mdx +++ b/site/src/content/docs/reference/functions.mdx @@ -10,16 +10,81 @@ functions in snake_case, the Go package in CamelCase, and the C library in snake `trackparse_` prefix. [`parse`](/trackparse/reference/parse/) and the [tracklist functions](/trackparse/reference/tracklist/) have pages of their own. -| JavaScript | Python | Rust | Go | C | -|---|---|---|---|---| -| `parse` | `parse` | `parse`, `parse_with` | `Parse`, `ParseWith` | `trackparse_parse`, `trackparse_parse_with` | -| `parseArtists` | `parse_artists` | `parse_artists`, `parse_artists_with` | `ParseArtists`, `ParseArtistsWith` | `trackparse_parse_artists`, `trackparse_parse_artists_with` | -| `format` | `format_track` | `format_track`, `format_track_with` | `Format`, `FormatWith` | `trackparse_format`, `trackparse_format_with` | -| `normalize` | `normalize` | `normalize` | `Normalize` | `trackparse_normalize` | -| `allArtists` | `all_artists` | `all_artists` | `AllArtists` | `trackparse_all_artists` | -| `createParser` | `create_parser` | `Parser::new` | `NewParser` | `trackparse_parser_new` | -| `SPEC_VERSION` | `SPEC_VERSION` | `SPEC_VERSION` | `SpecVersion` | `trackparse_spec_version()` | -| [`parseTracklist`](/trackparse/reference/tracklist/#parsetracklisttext-options), [`applyEdits`](/trackparse/reference/tracklist/#applyeditstext-edits-options) (from `trackparse/tracklist`) | `parse_tracklist`, `apply_edits` (from `trackparse.tracklist`) | `parse_tracklist`, `parse_tracklist_with`, `apply_edits`, `apply_edits_with` (from `trackparse::tracklist`) | `ParseTracklist`, `ParseTracklistWith`, `ApplyEdits`, `ApplyEditsWith` (same package) | `trackparse_parse_tracklist`, `trackparse_parse_tracklist_with`, `trackparse_apply_edits` (same header) | + + + +| JavaScript | What it does | +|---|---| +| [`parse`](/trackparse/reference/parse/) | Parses one track string | +| [`parseArtists`](#parseartistsinput-options) | Splits a bare artist string into credits | +| [`format`](#formattrack-options) | Renders a track back to a string | +| [`normalize`](#normalizeinput) | The Unicode cleanup every function runs first | +| [`allArtists`](#allartiststrack) | The artists and remixers in one list, without duplicates | +| [`createParser`](#createparseroptions) | Compiles options once for many calls | +| [`SPEC_VERSION`](#spec_version) | The spec version the package implements | + + + + +| JavaScript | Python | +|---|---| +| `parse` | `parse` | +| `parseArtists` | `parse_artists` | +| `format` | `format_track` | +| `normalize` | `normalize` | +| `allArtists` | `all_artists` | +| `createParser` | `create_parser` | +| `SPEC_VERSION` | `SPEC_VERSION` | + + + + +| JavaScript | Rust | +|---|---| +| `parse` | `parse`, `parse_with` | +| `parseArtists` | `parse_artists`, `parse_artists_with` | +| `format` | `format_track`, `format_track_with` | +| `normalize` | `normalize` | +| `allArtists` | `all_artists` | +| `createParser` | `Parser::new` | +| `SPEC_VERSION` | `SPEC_VERSION` | + + + + +| JavaScript | Go | +|---|---| +| `parse` | `Parse`, `ParseWith` | +| `parseArtists` | `ParseArtists`, `ParseArtistsWith` | +| `format` | `Format`, `FormatWith` | +| `normalize` | `Normalize` | +| `allArtists` | `AllArtists` | +| `createParser` | `NewParser` | +| `SPEC_VERSION` | `SpecVersion` | + + + + +| JavaScript | C | +|---|---| +| `parse` | `trackparse_parse`, `trackparse_parse_with` | +| `parseArtists` | `trackparse_parse_artists`, `trackparse_parse_artists_with` | +| `format` | `trackparse_format`, `trackparse_format_with` | +| `normalize` | `trackparse_normalize` | +| `allArtists` | `trackparse_all_artists` | +| `createParser` | `trackparse_parser_new` | +| `SPEC_VERSION` | `trackparse_spec_version()` | + + + + +The tracklist functions are [`parseTracklist`](/trackparse/reference/tracklist/#parsetracklisttext-options) +and [`applyEdits`](/trackparse/reference/tracklist/#applyeditstext-edits-options), from the entry +`trackparse/tracklist` in JavaScript. They are `parse_tracklist` and `apply_edits` in Python (from +`trackparse.tracklist`); `parse_tracklist`, `parse_tracklist_with`, `apply_edits` and +`apply_edits_with` in Rust (from `trackparse::tracklist`); `ParseTracklist`, `ParseTracklistWith`, +`ApplyEdits` and `ApplyEditsWith` in Go (same package); and `trackparse_parse_tracklist`, +`trackparse_parse_tracklist_with` and `trackparse_apply_edits` in C (same header). What to know for each language: @@ -52,6 +117,19 @@ What to know for each language: and enums have a `_name()` function that gives the spec's string. Strings in results are `trackparse_str`, a `ptr` and a `len`, and `ptr` is also NUL-terminated. A function returns `NULL` only when memory runs out; it never crashes on any input. All functions are thread-safe. + `trackparse_set_allocator` replaces `malloc`, `realloc` and `free` for the whole process; call + it once, before any other function. +- **C++** ([`trackparse.hpp`](https://github.com/4matic/trackparse/blob/main/c/include/trackparse.hpp)). + A header-only C++17 wrapper over the C library, installed next to `trackparse.h`. The functions + are in the namespace `trackparse` with the C names minus the prefix (`trackparse::parse`, + `trackparse::parse_tracklist`), and options are a second argument instead of a `_with` form. + Results are move-only owners that free their C object, strings read from results are + `std::string_view` (`format`, `normalize` and `to_json` return `std::string`), nullable fields + are `std::optional`, and options chain: + `trackparse::parse_options{}.known_artist("Chase & Status")`. The only exception it throws is + `std::bad_alloc`, when memory runs out. The + [C README](https://github.com/4matic/trackparse/blob/main/c/README.md#c-wrapper) has a full + example. The options themselves are on the [Options](/trackparse/reference/options/) page. diff --git a/site/src/content/docs/reference/options.mdx b/site/src/content/docs/reference/options.mdx index 085fd00..d3e4f00 100644 --- a/site/src/content/docs/reference/options.mdx +++ b/site/src/content/docs/reference/options.mdx @@ -33,8 +33,8 @@ parse( input, *, mode: ModeOption = "auto", # "auto" | "clean" | "youtube" | "filename" | "tracklist" - known_artists: Sequence[str] = (), uploader: Optional[str] = None, + known_artists: Sequence[str] = (), split_and: str = "auto", # "auto" | "always" | "never" keywords: Optional[KeywordOptions] = None, ) @@ -134,15 +134,20 @@ trackparse_parse_options_free(options); -| JavaScript | Python and Rust | Go | C | Default | | -|---|---|---|---|---|---| -| `mode` | `mode` | `Mode` | `trackparse_parse_options_set_mode` | `"auto"` | Which [mode](/trackparse/guides/modes/) to use. `auto` picks `filename`, `youtube` or `clean` from the string | -| `knownArtists` | `known_artists` | `KnownArtists` | `trackparse_parse_options_add_known_artist` | empty | Names that are never split, like `Chase & Status` or `Earth, Wind & Fire`. Matched case- and accent-insensitively. See [knownArtists](/trackparse/guides/artists/#knownartists) | -| `uploader` | `uploader` | `Uploader` | `trackparse_parse_options_set_uploader` | none | The YouTube channel. In youtube mode it becomes the artist when there's no separator. `- Topic` and `VEVO` are dropped. See [the uploader fallback](/trackparse/guides/modes/#the-uploader-fallback) | -| `splitAnd` | `split_and` | `SplitAnd` | `trackparse_parse_options_set_split_and` | `"auto"` | `auto` splits on `and` only after a comma (`A, B and C`), so `Simon and Garfunkel` stays whole. `always` and `never` do what they say. See [`and` is special](/trackparse/guides/artists/#and-is-special) | -| `keywords` | `keywords` | `Keywords` | `trackparse_parse_options_add_version_head` and the other `add_` setters | none | Extra vocabulary, see [keywords](#keywords) below | +The C setters are on the options handle and are named after the option in snake_case: +`trackparse_parse_options_set_mode`, `_set_uploader` and `_set_split_and`. A list option is an +`add_` setter that takes one entry, named in the singular: `_add_known_artist`. `keywords` has no +setter of its own; each of its lists is an `add_` setter, listed under [keywords](#keywords). -All five work the same in [`parse`](/trackparse/reference/parse/), +| JavaScript | Python and Rust
Go | Default | | +|---|---|---|---| +| `mode` | `mode`
`Mode` | `"auto"` | Which [mode](/trackparse/guides/modes/) to use. `auto` picks `filename`, `youtube` or `clean` from the string | +| `knownArtists` | `known_artists`
`KnownArtists` | empty | Names that are never split, like `Chase & Status` or `Earth, Wind & Fire`. Matched case- and accent-insensitively. See [knownArtists](/trackparse/guides/artists/#knownartists) | +| `uploader` | `uploader`
`Uploader` | none | The YouTube channel. In youtube mode it becomes the artist when there's no separator. `- Topic` and `VEVO` are dropped. See [the uploader fallback](/trackparse/guides/modes/#the-uploader-fallback) | +| `splitAnd` | `split_and`
`SplitAnd` | `"auto"` | `auto` splits on `and` only after a comma or semicolon (`A, B and C`), so `Simon and Garfunkel` stays whole. `always` and `never` do what they say. See [`and` is special](/trackparse/guides/artists/#and-is-special) | +| `keywords` | `keywords`
`Keywords` | none | Extra vocabulary, see [keywords](#keywords) below | + +All five options work the same in [`parse`](/trackparse/reference/parse/), [`parseArtists`](/trackparse/reference/functions/#parseartistsinput-options) (which ignores `mode` and `uploader`) and [`createParser`](/trackparse/reference/functions/#createparseroptions). The playground has a field for each but `keywords`: @@ -456,10 +461,16 @@ In C they are the setters of a `trackparse_tracklist_options` handle (`trackparse_tracklist_options_new()`), passed to `trackparse_parse_tracklist_with`. The rules are [R13.10](/trackparse/reference/spec/#r1310-options): -| JavaScript | Python and Rust | Go | C | Default | Description | -|---|---|---|---|---|---| -| [`audioSeconds`](/trackparse/guides/tracklists/#options) | `audio_seconds` | `AudioSeconds` | `trackparse_tracklist_options_set_audio_seconds` | none | Length of the audio. Turns on the [`time-after-audio-end`](/trackparse/reference/warnings/#tracklist-warnings:~:text=time%2Dafter%2Daudio%2Dend) check | -| [`markerWords`](/trackparse/guides/tracklists/#options) | `marker_words` | `MarkerWords` | `trackparse_tracklist_options_add_marker_word` | empty | Extra marker words. With `["drop"]`, `03:00 Drop` is a marker, not a track | +| JavaScript | Python and Rust
Go | Default | Description | +|---|---|---|---| +| [`audioSeconds`](/trackparse/guides/tracklists/#options) | `audio_seconds`
`AudioSeconds` | none | Length of the audio. Turns on the [`time-after-audio-end`](/trackparse/reference/warnings/#tracklist-warnings:~:text=time%2Dafter%2Daudio%2Dend) check | +| [`markerWords`](/trackparse/guides/tracklists/#options) | `marker_words`
`MarkerWords` | empty | Extra marker words. With `["drop"]`, `03:00 Drop` is a marker, not a track | + +In C these two are `trackparse_tracklist_options_set_audio_seconds` and +`trackparse_tracklist_options_add_marker_word` (one word per call). The shared options have the +same setters as on the parse options handle, with `trackparse_tracklist_options_` in front: +`_set_mode`, `_set_split_and`, `_add_known_artist` and the five keyword setters. There is no +uploader on a tracklist. In Go the zero value of `TracklistOptions` is the defaults too: an empty `Mode` means `ModeTracklist`, and `ModeAuto` asks for auto mode on each line. `AudioSeconds` is a `*float64`, diff --git a/site/src/content/docs/reference/parse.mdx b/site/src/content/docs/reference/parse.mdx index e129f64..4161e05 100644 --- a/site/src/content/docs/reference/parse.mdx +++ b/site/src/content/docs/reference/parse.mdx @@ -20,7 +20,7 @@ parse(input: string, options?: ParseOptions): ParsedTrack ```python from trackparse import parse -parse(input: str, *, mode="auto", known_artists=(), uploader=None, split_and="auto", keywords=None) -> ParsedTrack +parse(input: str, *, mode="auto", uploader=None, known_artists=(), split_and="auto", keywords=None) -> ParsedTrack ``` diff --git a/site/src/content/docs/reference/tracklist.mdx b/site/src/content/docs/reference/tracklist.mdx index 73e641b..f9599c5 100644 --- a/site/src/content/docs/reference/tracklist.mdx +++ b/site/src/content/docs/reference/tracklist.mdx @@ -286,19 +286,80 @@ are [R13.9](/trackparse/reference/spec/#r139-edits). ### Edits -| JavaScript and Python | Rust | Go | C | Effect | -|---|---|---|---|---| -| `{ op: "set-time", line, seconds }` | `Edit::set_time(line, seconds)` | `SetTime(line, seconds)` | `trackparse_edits_set_time(e, line, seconds)` | Rewrite the time on that line | -| `{ op: "shift", seconds }` | `Edit::shift(seconds)` | `Shift(seconds)` | `trackparse_edits_shift(e, seconds)` | Add `seconds` to every timed line | -| `{ op: "shift", seconds, from }` | `Edit::shift_from(seconds, from)` | `ShiftFrom(seconds, from)` | `trackparse_edits_shift_from(e, seconds, from)` | Add `seconds` to every timed line from `from` on | -| `{ op: "shift", seconds, lines }` | `Edit::shift_lines(seconds, lines)` | `ShiftLines(seconds, lines...)` | `trackparse_edits_shift_lines(e, seconds, lines, count)` | Add `seconds` to the listed lines | -| `{ op: "sort-by-time" }` | `Edit::sort_by_time()` | `SortByTime()` | `trackparse_edits_sort_by_time(e)` | Stable sort by time. Untimed lines move with the timed line above them | -| `{ op: "set-rest", line, rest }` | `Edit::set_rest(line, rest)` | `SetRest(line, rest)` | `trackparse_edits_set_rest(e, line, rest, len)` | Replace everything after the time | -| `{ op: "insert", after, text }` | `Edit::insert(after, text)` | `Insert(after, text)` | `trackparse_edits_insert(e, after, text, len)` | Insert a line after `after` (`0` = at the top) | -| `{ op: "delete", line }` | `Edit::delete(line)` | `Delete(line)` | `trackparse_edits_delete(e, line)` | Remove a line | - -In Python an edit is a dict with quoted keys: `{"op": "shift", "seconds": 45, "from": 5}`. With the -`serde` feature, the Rust `Edit` reads and writes that same JSON. The Go `Edit` writes it with +| JavaScript and Python | Effect | +|---|---| +| `{ op: "set-time", line, seconds }` | Rewrite the time on that line | +| `{ op: "shift", seconds }` | Add `seconds` to every timed line | +| `{ op: "shift", seconds, from }` | Add `seconds` to every timed line from `from` on | +| `{ op: "shift", seconds, lines }` | Add `seconds` to the listed lines | +| `{ op: "sort-by-time" }` | Stable sort by time. Untimed lines move with the timed line above them | +| `{ op: "set-rest", line, rest }` | Replace everything after the time | +| `{ op: "insert", after, text }` | Insert a line after `after` (`0` = at the top) | +| `{ op: "delete", line }` | Remove a line | + + + + +Pass the objects in the table as an array: `applyEdits(text, [{ op: "shift", seconds: 45, from: 5 }])`. + + + + +An edit is a dict with the same keys, quoted: `{"op": "shift", "seconds": 45, "from": 5}`. + + + + +Each edit has a constructor on [`Edit`](https://docs.rs/trackparse/latest/trackparse/tracklist/enum.Edit.html); pass a slice of them. + +| Edit | Rust | +|---|---| +| `set-time` | `Edit::set_time(line, seconds)` | +| `shift` | `Edit::shift(seconds)` | +| `shift` with `from` | `Edit::shift_from(seconds, from)` | +| `shift` with `lines` | `Edit::shift_lines(seconds, lines)` | +| `sort-by-time` | `Edit::sort_by_time()` | +| `set-rest` | `Edit::set_rest(line, rest)` | +| `insert` | `Edit::insert(after, text)` | +| `delete` | `Edit::delete(line)` | + + + + +Each edit has a constructor that returns an [`Edit`](https://pkg.go.dev/github.com/4matic/trackparse/go#Edit); pass a `[]trackparse.Edit`. + +| Edit | Go | +|---|---| +| `set-time` | `SetTime(line, seconds)` | +| `shift` | `Shift(seconds)` | +| `shift` with `from` | `ShiftFrom(seconds, from)` | +| `shift` with `lines` | `ShiftLines(seconds, lines...)` | +| `sort-by-time` | `SortByTime()` | +| `set-rest` | `SetRest(line, rest)` | +| `insert` | `Insert(after, text)` | +| `delete` | `Delete(line)` | + + + + +Each edit is a function that appends it to a `trackparse_edits` list from `trackparse_edits_new()`. It returns `false` only when memory runs out. + +| Edit | C | +|---|---| +| `set-time` | `trackparse_edits_set_time(e, line, seconds)` | +| `shift` | `trackparse_edits_shift(e, seconds)` | +| `shift` with `from` | `trackparse_edits_shift_from(e, seconds, from)` | +| `shift` with `lines` | `trackparse_edits_shift_lines(e, seconds, lines, count)` | +| `sort-by-time` | `trackparse_edits_sort_by_time(e)` | +| `set-rest` | `trackparse_edits_set_rest(e, line, rest, len)` | +| `insert` | `trackparse_edits_insert(e, after, text, len)` | +| `delete` | `trackparse_edits_delete(e, line)` | + + + + + +With the `serde` feature, the Rust `Edit` reads and writes the JSON of the JavaScript objects. The Go `Edit` writes it with `json.Marshal`. Edits run in sequence, each on the result of the one before. Times are written in their line's @@ -324,12 +385,20 @@ In Rust the codes are [`EditWarningCode`](https://docs.rs/trackparse/latest/trac Both functions take the same options ([R13.10](/trackparse/reference/spec/#r1310-options)). `applyEdits` accepts them for symmetry; edits don't depend on them, and the C `trackparse_apply_edits` has no options argument. -| JavaScript | Python and Rust | Go | C | Default | Description | -|---|---|---|---|---|---| -| `mode` | `mode` | `Mode` | `trackparse_tracklist_options_set_mode` | `"tracklist"` | Mode for each line's [`parse()`](/trackparse/reference/parse/). See [Tracklist mode](/trackparse/guides/tracklists/#tracklist-mode) | -| [`knownArtists`](/trackparse/guides/artists/#knownartists), [`splitAnd`](/trackparse/guides/artists/#and-is-special), [`keywords`](/trackparse/reference/options/#keywords) | `known_artists`, `split_and`, `keywords` | `KnownArtists`, `SplitAnd`, `Keywords` | `_add_known_artist`, `_set_split_and`, `_add_version_head` and the other `add_` setters | as for `parse` | As for [`parse()`](/trackparse/reference/options/) | -| [`audioSeconds`](/trackparse/guides/tracklists/#options) | `audio_seconds` | `AudioSeconds` | `trackparse_tracklist_options_set_audio_seconds` | none | Length of the audio. Enables [`time-after-audio-end`](/trackparse/reference/warnings/#tracklist-warnings:~:text=time%2Dafter%2Daudio%2Dend) | -| [`markerWords`](/trackparse/guides/tracklists/#options) | `marker_words` | `MarkerWords` | `trackparse_tracklist_options_add_marker_word` | empty | Extra marker words | +| JavaScript | Python and Rust
Go | Default | Description | +|---|---|---|---| +| `mode` | `mode`
`Mode` | `"tracklist"` | Mode for each line's [`parse()`](/trackparse/reference/parse/). See [Tracklist mode](/trackparse/guides/tracklists/#tracklist-mode) | +| [`knownArtists`](/trackparse/guides/artists/#knownartists) | `known_artists`
`KnownArtists` | empty | As for [`parse()`](/trackparse/reference/options/#parse-options) | +| [`splitAnd`](/trackparse/guides/artists/#and-is-special) | `split_and`
`SplitAnd` | `"auto"` | As for `parse()` | +| [`keywords`](/trackparse/reference/options/#keywords) | `keywords`
`Keywords` | none | As for `parse()` | +| [`audioSeconds`](/trackparse/guides/tracklists/#options) | `audio_seconds`
`AudioSeconds` | none | Length of the audio. Enables [`time-after-audio-end`](/trackparse/reference/warnings/#tracklist-warnings:~:text=time%2Dafter%2Daudio%2Dend) | +| [`markerWords`](/trackparse/guides/tracklists/#options) | `marker_words`
`MarkerWords` | empty | Extra marker words | + +The C setters are named after the option, after `trackparse_tracklist_options_`: `set_mode`, +`set_split_and` and `set_audio_seconds` take a value, and the list options take one entry per call, +named in the singular: `add_known_artist` and `add_marker_word`. `keywords` is five setters, as on +the [parse options](/trackparse/reference/options/#keywords): `add_version_head`, `add_descriptor`, +`add_genre`, `add_junk` and `add_feat_marker`. Python uses keyword arguments. Rust has a setter of the same name for each on [`TracklistOptions`](https://docs.rs/trackparse/latest/trackparse/tracklist/struct.TracklistOptions.html), for example `TracklistOptions::new().audio_seconds(3600.0).marker_words(["drop"])`, and passes it diff --git a/site/src/content/docs/reference/warnings.mdx b/site/src/content/docs/reference/warnings.mdx index 92efee3..2e2657d 100644 --- a/site/src/content/docs/reference/warnings.mdx +++ b/site/src/content/docs/reference/warnings.mdx @@ -11,7 +11,8 @@ three kinds: on a single track, on a tracklist, and on an edit. In JavaScript and Python a warning code is a string. In Rust it is an enum variant, and `as_str()` or `Display` gives the same string. In Go it is a constant of a string type, whose value is the string. In C it is an enum value, and its `_name()` function gives the string. The tables below -give the string, the Rust variant, the Go constant and the C enum value for each code, and +give the string and what it means, and each section says once how the Rust, Go and C names are +made from it. The names follow that rule for every code, with no exceptions. Each meaning links the rule of the [spec](/trackparse/reference/spec/) that raises it. ## Track warnings @@ -22,16 +23,21 @@ Python, a `Vec` in Rust ([`Warning`](https://docs.rs/trackparse/latest/ ([`trackparse.h`](https://github.com/4matic/trackparse/blob/main/c/include/trackparse.h)). An empty list means every decision was unambiguous. Click an example to open it in the playground. -| Warning | Rust | Go | C | Means | Example | -|---|---|---|---|---|---| -| `noSeparator` | `Warning::NoSeparator` | `WarningNoSeparator` | `TRACKPARSE_WARNING_NO_SEPARATOR` | No artist/title separator was found. The whole string is the title ([R6.8](/trackparse/reference/spec/#r6-artisttitle-separator:~:text=R6.8%20No%20separator)) | [`Around the World`](/trackparse/playground/#track=Around%20the%20World) | -| `ambiguousSeparator` | `Warning::AmbiguousSeparator` | `WarningAmbiguousSeparator` | `TRACKPARSE_WARNING_AMBIGUOUS_SEPARATOR` | A pipe-separated YouTube title had two parts and no dash, so they were read as artist and title ([R2.4](/trackparse/reference/spec/#r2-mode-prelude:~:text=R2.4%20youtube%20pipes)) | [`Noisia \| Stigma`](/trackparse/playground/#track=Noisia%20%7C%20Stigma&mode=youtube) | -| `unspacedDashSplit` | `Warning::UnspacedDashSplit` | `WarningUnspacedDashSplit` | `TRACKPARSE_WARNING_UNSPACED_DASH_SPLIT` | Split at a dash without spaces around it (youtube and filename modes, and timed tracklist lines: [R6.7](/trackparse/reference/spec/#r6-artisttitle-separator:~:text=R6.7%20Unspaced%20dash), [R6.10](/trackparse/reference/spec/#r6-artisttitle-separator:~:text=R6.10%20Tracklist%20mode)) | [`Blink-182-All The Small Things`](/trackparse/playground/#track=Blink-182-All%20The%20Small%20Things&mode=youtube) | -| `asymmetricDashSplit` | `Warning::AsymmetricDashSplit` | `WarningAsymmetricDashSplit` | `TRACKPARSE_WARNING_ASYMMETRIC_DASH_SPLIT` | Split at a dash with a space on one side only ([R6.4](/trackparse/reference/spec/#r6-artisttitle-separator:~:text=R6.4%20Asymmetric%20dash)) | [`Artist -Title`](/trackparse/playground/#track=Artist%20-Title) | -| `bySplit` | `Warning::BySplit` | `WarningBySplit` | `TRACKPARSE_WARNING_BY_SPLIT` | Read `"Title" by Artist` (youtube mode, [R6.6](/trackparse/reference/spec/#r6-artisttitle-separator:~:text=R6.6%20by%20%28youtube%20only%29)) | [`"Numb" by Linkin Park`](/trackparse/playground/#track=%22Numb%22%20by%20Linkin%20Park&mode=youtube) | -| `quotedTitleSplit` | `Warning::QuotedTitleSplit` | `WarningQuotedTitleSplit` | `TRACKPARSE_WARNING_QUOTED_TITLE_SPLIT` | Took a quoted span as the title and what came before it as the artist (youtube mode, [R6.5](/trackparse/reference/spec/#r6-artisttitle-separator:~:text=R6.5%20Quoted%20title)) | [`Linkin Park: "Numb"`](/trackparse/playground/#track=Linkin%20Park%3A%20%22Numb%22&mode=youtube) | -| `ambiguousMixCredit` | `Warning::AmbiguousMixCredit` | `WarningAmbiguousMixCredit` | `TRACKPARSE_WARNING_AMBIGUOUS_MIX_CREDIT` | ` Mix` was read as a remix, but the name is long enough that it might be a style ([R5.7](/trackparse/reference/spec/#r5-group-classification:~:text=R5.7%20Version)) | [`(Fonetick Lee & Sonic Art Space Drums Mix)`](/trackparse/playground/#track=Artist%20-%20Title%20%28Fonetick%20Lee%20%26%20Sonic%20Art%20Space%20Drums%20Mix%29) | -| `unbalancedBrackets` | `Warning::UnbalancedBrackets` | `WarningUnbalancedBrackets` | `TRACKPARSE_WARNING_UNBALANCED_BRACKETS` | A bracket was opened and never closed ([R3.3](/trackparse/reference/spec/#r3-group-scanner-and-skeleton:~:text=R3.3%20An%20opener)) | [`Noisia - Stigma (VIP`](/trackparse/playground/#track=Noisia%20-%20Stigma%20%28VIP) | +| Warning | Means | Example | +|---|---|---| +| `noSeparator` | No artist/title separator was found. The whole string is the title ([R6.8](/trackparse/reference/spec/#r6-artisttitle-separator:~:text=R6.8%20No%20separator)) | [`Around the World`](/trackparse/playground/#track=Around%20the%20World) | +| `ambiguousSeparator` | A pipe-separated YouTube title had two parts and no dash, so they were read as artist and title ([R2.4](/trackparse/reference/spec/#r2-mode-prelude:~:text=R2.4%20youtube%20pipes)) | [`Noisia \| Stigma`](/trackparse/playground/#track=Noisia%20%7C%20Stigma&mode=youtube) | +| `unspacedDashSplit` | Split at a dash without spaces around it (youtube and filename modes, and timed tracklist lines: [R6.7](/trackparse/reference/spec/#r6-artisttitle-separator:~:text=R6.7%20Unspaced%20dash), [R6.10](/trackparse/reference/spec/#r6-artisttitle-separator:~:text=R6.10%20Tracklist%20mode)) | [`Blink-182-All The Small Things`](/trackparse/playground/#track=Blink-182-All%20The%20Small%20Things&mode=youtube) | +| `asymmetricDashSplit` | Split at a dash with a space on one side only ([R6.4](/trackparse/reference/spec/#r6-artisttitle-separator:~:text=R6.4%20Asymmetric%20dash)) | [`Artist -Title`](/trackparse/playground/#track=Artist%20-Title) | +| `bySplit` | Read `"Title" by Artist` (youtube mode, [R6.6](/trackparse/reference/spec/#r6-artisttitle-separator:~:text=R6.6%20by%20%28youtube%20only%29)) | [`"Numb" by Linkin Park`](/trackparse/playground/#track=%22Numb%22%20by%20Linkin%20Park&mode=youtube) | +| `quotedTitleSplit` | Took a quoted span as the title and what came before it as the artist (youtube mode, [R6.5](/trackparse/reference/spec/#r6-artisttitle-separator:~:text=R6.5%20Quoted%20title)) | [`Linkin Park: "Numb"`](/trackparse/playground/#track=Linkin%20Park%3A%20%22Numb%22&mode=youtube) | +| `ambiguousMixCredit` | ` Mix` was read as a remix, but the name is long enough that it might be a style ([R5.7](/trackparse/reference/spec/#r5-group-classification:~:text=R5.7%20Version)) | [`(Fonetick Lee & Sonic Art Space Drums Mix)`](/trackparse/playground/#track=Artist%20-%20Title%20%28Fonetick%20Lee%20%26%20Sonic%20Art%20Space%20Drums%20Mix%29) | +| `unbalancedBrackets` | A bracket was opened and never closed ([R3.3](/trackparse/reference/spec/#r3-group-scanner-and-skeleton:~:text=R3.3%20An%20opener)) | [`Noisia - Stigma (VIP`](/trackparse/playground/#track=Noisia%20-%20Stigma%20%28VIP) | + +In the other languages the name is the code with its first letter capitalized, after a prefix: +`Warning::` in Rust, `Warning` in Go (`trackparse.WarningNoSeparator`). In C the code is written +in upper case with an underscore between its words, after `TRACKPARSE_WARNING_` +(`TRACKPARSE_WARNING_NO_SEPARATOR`). What to do with them depends on your data. For a music library, a track with any warning is a good candidate for a human to look at. For scrobbling, most of them are fine to accept. @@ -177,17 +183,22 @@ and `Suggestion` is a pointer. In C they are a `trackparse_tracklist_warning_cod `TRACKPARSE_SEVERITY_INFO` or `TRACKPARSE_SEVERITY_WARNING`, and `suggestion` is a pointer. All of them are [R13.7](/trackparse/reference/spec/#r137-warnings) in the spec. -| Code | Rust | Go | C | Severity | When | -|---|---|---|---|---|---| -| `time-missing` | `WarningCode::TimeMissing` | `WarningCodeTimeMissing` | `TRACKPARSE_TL_TIME_MISSING` | warning | A track line has no time while other lines do (not raised on a `w/` line, which plays at the previous track's time) | -| `time-out-of-order` | `WarningCode::TimeOutOfOrder` | `WarningCodeTimeOutOfOrder` | `TRACKPARSE_TL_TIME_OUT_OF_ORDER` | warning | Earlier than the previous timed line. May carry a `suggestion` | -| `time-duplicate` | `WarningCode::TimeDuplicate` | `WarningCodeTimeDuplicate` | `TRACKPARSE_TL_TIME_DUPLICATE` | warning | Same time as the previous timed line | -| `no-start-at-zero` | `WarningCode::NoStartAtZero` | `WarningCodeNoStartAtZero` | `TRACKPARSE_TL_NO_START_AT_ZERO` | info | The first time isn't `0:00` | -| `time-after-audio-end` | `WarningCode::TimeAfterAudioEnd` | `WarningCodeTimeAfterAudioEnd` | `TRACKPARSE_TL_TIME_AFTER_AUDIO_END` | warning | Later than [`audioSeconds`](/trackparse/guides/tracklists/#options) (`audio_seconds`, `AudioSeconds`) | -| `invalid-time` | `WarningCode::InvalidTime` | `WarningCodeInvalidTime` | `TRACKPARSE_TL_INVALID_TIME` | warning | Looks like a time but isn't one (`1:75`, `0:61:00`). The line keeps it in `rest` | -| `position-gap` | `WarningCode::PositionGap` | `WarningCodePositionGap` | `TRACKPARSE_TL_POSITION_GAP` | warning | A track number isn't the previous one plus 1 | -| `position-duplicate` | `WarningCode::PositionDuplicate` | `WarningCodePositionDuplicate` | `TRACKPARSE_TL_POSITION_DUPLICATE` | warning | Same track number as the previous one | -| `line-unparsed` | `WarningCode::LineUnparsed` | `WarningCodeLineUnparsed` | `TRACKPARSE_TL_LINE_UNPARSED` | warning | A track line with no artist/title separator, or nothing after the time | +The names drop the dashes and capitalize each word after a prefix: `WarningCode::` in Rust +(`WarningCode::TimeOutOfOrder`), `WarningCode` in Go (`trackparse.WarningCodeTimeOutOfOrder`). In +C the dashes become underscores, in upper case, after `TRACKPARSE_TL_` +(`TRACKPARSE_TL_TIME_OUT_OF_ORDER`). + +| Code | Severity | When | +|---|---|---| +| `time-missing` | warning | A track line has no time while other lines do (not raised on a `w/` line, which plays at the previous track's time) | +| `time-out-of-order` | warning | Earlier than the previous timed line. May carry a `suggestion` | +| `time-duplicate` | warning | Same time as the previous timed line | +| `no-start-at-zero` | info | The first time isn't `0:00` | +| `time-after-audio-end` | warning | Later than [`audioSeconds`](/trackparse/guides/tracklists/#options) (`audio_seconds`, `AudioSeconds`) | +| `invalid-time` | warning | Looks like a time but isn't one (`1:75`, `0:61:00`). The line keeps it in `rest` | +| `position-gap` | warning | A track number isn't the previous one plus 1 | +| `position-duplicate` | warning | Same track number as the previous one | +| `line-unparsed` | warning | A track line with no artist/title separator, or nothing after the time | Warnings of each line's own track stay on `entries[i].track.warnings`. They are the [track warnings](#track-warnings) above and are not repeated in the list's `warnings`. @@ -314,7 +325,7 @@ trackparse_tracklist_free(list); -Here line 3 has no suggestion, because more than one time would fit between its neighbours. +Here line 3 has no suggestion, because more than one time would fit between its neighbors. [Tracklists](/trackparse/guides/tracklists/#checks) walks through a list that does get a suggestion. @@ -342,11 +353,16 @@ objects ([`EditWarning`](https://docs.rs/trackparse/latest/trackparse/tracklist/ `null` (`None`, `nil` in Go, `NULL` in C) when the edit names no line. The rules are [R13.9](/trackparse/reference/spec/#r139-edits). -| Code | Rust | Go | C | When | -|---|---|---|---|---| -| `style-upgraded` | `EditWarningCode::StyleUpgraded` | `EditWarningCodeStyleUpgraded` | `TRACKPARSE_EDIT_WARNING_STYLE_UPGRADED` | a time without hours passed one hour and gained them ([R13.9.2](/trackparse/reference/spec/#r139-edits:~:text=R13.9.2%20Time%20style)) | -| `time-clamped` | `EditWarningCode::TimeClamped` | `EditWarningCodeTimeClamped` | `TRACKPARSE_EDIT_WARNING_TIME_CLAMPED` | a time would go below zero and was set to zero ([R13.9.3](/trackparse/reference/spec/#r139-edits:~:text=R13.9.3%20Clamp)) | -| `edit-invalid` | `EditWarningCode::EditInvalid` | `EditWarningCodeEditInvalid` | `TRACKPARSE_EDIT_WARNING_EDIT_INVALID` | the edit could not apply and changed nothing ([R13.9.6](/trackparse/reference/spec/#r139-edits:~:text=R13.9.6%20Totality)) | +The names follow the tracklist codes with another prefix: `EditWarningCode::` in Rust +(`EditWarningCode::EditInvalid`), `EditWarningCode` in Go +(`trackparse.EditWarningCodeEditInvalid`) and `TRACKPARSE_EDIT_WARNING_` in C +(`TRACKPARSE_EDIT_WARNING_EDIT_INVALID`), of the enum `trackparse_edit_warning_code`. + +| Code | When | +|---|---| +| `style-upgraded` | a time without hours passed one hour and gained them ([R13.9.2](/trackparse/reference/spec/#r139-edits:~:text=R13.9.2%20Time%20style)) | +| `time-clamped` | a time would go below zero and was set to zero ([R13.9.3](/trackparse/reference/spec/#r139-edits:~:text=R13.9.3%20Clamp)) | +| `edit-invalid` | the edit could not apply and changed nothing ([R13.9.6](/trackparse/reference/spec/#r139-edits:~:text=R13.9.6%20Totality)) | diff --git a/site/src/content/docs/start/getting-started.mdx b/site/src/content/docs/start/getting-started.mdx index cef6da3..84ccfd6 100644 --- a/site/src/content/docs/start/getting-started.mdx +++ b/site/src/content/docs/start/getting-started.mdx @@ -59,10 +59,12 @@ import { Aside, Steps, Tabs, TabItem } from "@astrojs/starlight/components"; target_link_libraries(my_app PRIVATE trackparse::trackparse) ``` - C11, no dependencies beyond the C standard library; it builds with GCC, Clang and MSVC. - Every release from 0.7.0, the first with the C library, attaches the source tarball above - (CMake 3.16 or newer), `SHA256SUMS` and an amalgamation to its - [GitHub Release](https://github.com/4matic/trackparse/releases). + C11, no dependencies beyond libc, `libm` and threads; it builds + with GCC, Clang and MSVC. Each release from 0.7.0 on, the first with the C library, + attaches the source tarball above (CMake 3.16 or newer), `SHA256SUMS` and an amalgamation + to its [GitHub Release](https://github.com/4matic/trackparse/releases). If the 0.7.0 + release doesn't list them yet, build from a clone of the repository as the + [C README](https://github.com/4matic/trackparse/blob/main/c/README.md#from-source) shows. `cmake --install` also gives you `find_package(trackparse)` and a `trackparse.pc` for pkg-config. Without CMake, copy `trackparse.c` and `trackparse.h` from `trackparse-c-0.7.0-amalgamation.zip` into your project and compile them with your diff --git a/site/src/content/docs/start/introduction.mdx b/site/src/content/docs/start/introduction.mdx index 5d719cd..2e8e6b6 100644 --- a/site/src/content/docs/start/introduction.mdx +++ b/site/src/content/docs/start/introduction.mdx @@ -18,9 +18,8 @@ It comes as five packages with the same behaviour: `trackparse` on and a C library with one header, [`trackparse.h`](https://github.com/4matic/trackparse/blob/main/c/include/trackparse.h), released as a source tarball and an amalgamation on each -[GitHub Release](https://github.com/4matic/trackparse/releases) from 0.7.0 on. -Every example -on this site has a tab for each language. The API docs of the Rust crate are on +[GitHub Release](https://github.com/4matic/trackparse/releases) from 0.7.0 on. Every example on +this site has a tab for each language. The API docs of the Rust crate are on [docs.rs](https://docs.rs/trackparse), and those of the Go module on [pkg.go.dev](https://pkg.go.dev/github.com/4matic/trackparse/go). @@ -154,8 +153,7 @@ dataclass with snake_case attributes, and `to_dict()` turns it into the JSON abo struct with snake_case fields, and `to_json()` writes that JSON as a string. In Go it is a struct with exported CamelCase fields, and `json.Marshal` writes that JSON. In C it is a read-only struct with snake_case members that owns its memory, and `trackparse_track_to_json` writes that -JSON. The -[`parse` reference](/trackparse/reference/parse/) explains every field, and +JSON. The [`parse` reference](/trackparse/reference/parse/) explains every field, and [Serializing to JSON](/trackparse/reference/parse/#serializing-to-json) shows the round trip in each language. [Try this track in the playground](/trackparse/playground/#track=Queen%20-%20Bohemian%20Rhapsody%20%28Live%20at%20Wembley%201986%29). @@ -164,14 +162,68 @@ language. [Try this track in the playground](/trackparse/playground/#track=Queen The docs use the JavaScript and JSON names in running text. Python and Rust use snake_case for the same things, Go uses exported CamelCase, and C prefixes every name with `trackparse_`: -| | JavaScript | Python | Rust | Go | C | -|---|---|---|---|---|---| -| Parse | [`parse(s, options?)`](/trackparse/reference/parse/) | `parse(s, **options)` | [`parse(s)`](https://docs.rs/trackparse/latest/trackparse/fn.parse.html), [`parse_with(s, &options)`](https://docs.rs/trackparse/latest/trackparse/fn.parse_with.html) | [`Parse(s)`](https://pkg.go.dev/github.com/4matic/trackparse/go#Parse), [`ParseWith(s, options)`](https://pkg.go.dev/github.com/4matic/trackparse/go#ParseWith) | `trackparse_parse(s, len)`, `trackparse_parse_with(s, len, options)` | -| A field | `track.fullTitle` | `track.full_title` | `track.full_title` | `track.FullTitle` | `track->full_title` | -| An option | [`{ knownArtists: […] }`](/trackparse/reference/options/) | `known_artists=[…]` | [`ParseOptions::new().known_artists([…])`](https://docs.rs/trackparse/latest/trackparse/struct.ParseOptions.html) | [`ParseOptions{KnownArtists: …}`](https://pkg.go.dev/github.com/4matic/trackparse/go#ParseOptions) | `trackparse_parse_options_add_known_artist(options, …)` | -| A value | `"remix"`, `null` | `"remix"`, `None` | `VersionType::Remix`, `None` | `VersionTypeRemix`, `nil` | `TRACKPARSE_VERSION_REMIX`, `NULL` | -| Lists | arrays | tuples | `Vec` | slices | a pointer and a `_count` | -| JSON | `JSON.stringify(track)` | `track.to_dict()` | `track.to_json()`, or `serde` | `json.Marshal(track)` | `trackparse_track_to_json(track)` | + + + +| What | JavaScript | +|---|---| +| Parse | [`parse(s, options?)`](/trackparse/reference/parse/) | +| A field | `track.fullTitle` | +| An option | [`{ knownArtists: […] }`](/trackparse/reference/options/) | +| A value | `"remix"`, `null` | +| Lists | arrays | +| JSON | `JSON.stringify(track)` | + + + + +| What | Python | +|---|---| +| Parse | `parse(s, **options)` | +| A field | `track.full_title` | +| An option | `known_artists=[…]` | +| A value | `"remix"`, `None` | +| Lists | tuples | +| JSON | `track.to_dict()` | + + + + +| What | Rust | +|---|---| +| Parse | [`parse(s)`](https://docs.rs/trackparse/latest/trackparse/fn.parse.html), [`parse_with(s, &options)`](https://docs.rs/trackparse/latest/trackparse/fn.parse_with.html) | +| A field | `track.full_title` | +| An option | [`ParseOptions::new().known_artists([…])`](https://docs.rs/trackparse/latest/trackparse/struct.ParseOptions.html) | +| A value | `VersionType::Remix`, `None` | +| Lists | `Vec` | +| JSON | `track.to_json()`, or `serde` | + + + + +| What | Go | +|---|---| +| Parse | [`Parse(s)`](https://pkg.go.dev/github.com/4matic/trackparse/go#Parse), [`ParseWith(s, options)`](https://pkg.go.dev/github.com/4matic/trackparse/go#ParseWith) | +| A field | `track.FullTitle` | +| An option | [`ParseOptions{KnownArtists: …}`](https://pkg.go.dev/github.com/4matic/trackparse/go#ParseOptions) | +| A value | `VersionTypeRemix`, `nil` | +| Lists | slices | +| JSON | `json.Marshal(track)` | + + + + +| What | C | +|---|---| +| Parse | `trackparse_parse(s, len)`, `trackparse_parse_with(s, len, options)` | +| A field | `track->full_title` | +| An option | `trackparse_parse_options_add_known_artist` | +| A value | `TRACKPARSE_VERSION_REMIX`, `NULL` | +| Lists | a pointer and a `_count` | +| JSON | `trackparse_track_to_json(track)` | + + + [Other functions](/trackparse/reference/functions/) has the full table of function names. diff --git a/site/src/lib/codegen.ts b/site/src/lib/codegen.ts index fdd27f4..67ce252 100644 --- a/site/src/lib/codegen.ts +++ b/site/src/lib/codegen.ts @@ -747,7 +747,13 @@ export function listCode(lang: Lang, x: ListInput): Snippet { if (audioSeconds !== undefined) opts.audioSeconds = audioSeconds; if (knownArtists) opts.knownArtists = knownArtists; const head = "const text = "; - const textLine = joined ? `${head}${jsLay(lines, "", head, '.join("\\n");')}.join("\\n");` : `${head}${strLit(text)};`; + // One string too long for the line goes on the next one, as Biome breaks after `=`. + const one = `${head}${strLit(text)};`; + const textLine = joined + ? `${head}${jsLay(lines, "", head, '.join("\\n");')}.join("\\n");` + : cols(one) <= WIDTH + ? one + : `const text =\n ${strLit(text)};`; const out = [ 'import { applyEdits, parseTracklist } from "trackparse/tracklist";', "", diff --git a/site/src/lib/lang.ts b/site/src/lib/lang.ts index 8b1f017..4a4644d 100644 --- a/site/src/lib/lang.ts +++ b/site/src/lib/lang.ts @@ -17,10 +17,13 @@ export const LANG_LABEL: Record = { js: "JavaScript", py: "Python" * The C library's version. All packages share one version (release-please bumps js/package.json * with the rest), and the first C release is 0.7.0, so an older version means "not yet". */ -const C_VERSION = (() => { - const [a, b] = version.split(".").map(Number); - return a > 0 || b >= 7 ? version : "0.7.0"; -})(); +const [MAJOR, MINOR] = version.split(".").map(Number); +/** + * Whether a C release exists. Before 0.7.0 the tarball URL below answers 404: the install switch + * and the playground say so. The release PR bumps js/package.json, so the note goes away with it. + */ +export const C_RELEASED = MAJOR > 0 || MINOR >= 7; +const C_VERSION = C_RELEASED ? version : "0.7.0"; const C_TARBALL = `https://github.com/4matic/trackparse/releases/download/c-v${C_VERSION}/trackparse-c-${C_VERSION}.tar.gz`; /** The CMake lines that fetch and link the C library (the install switch shows them for C). */ diff --git a/site/src/styles/custom.css b/site/src/styles/custom.css index 9efdc0d..fc23bc9 100644 --- a/site/src/styles/custom.css +++ b/site/src/styles/custom.css @@ -213,6 +213,11 @@ h5 { .sl-markdown-content table { font-variant-numeric: tabular-nums; font-size: 0.92em; + /* A table wider than the column (the five language columns) scrolls sideways. A thin scrollbar + that stays visible says so; an overlay one that shows only while scrolling hid the last + columns without a hint. */ + scrollbar-width: thin; + scrollbar-color: var(--tp-border-strong) transparent; } .sl-markdown-content :is(th, td) { border-color: var(--tp-border); @@ -283,6 +288,14 @@ starlight-tabs [role="tab"][aria-selected="true"] { starlight-tabs [role="tab"] { color: var(--sl-color-gray-3); } +/* Five language tabs fit a phone, also inside a numbered step: tighter padding and a smaller + label, so the strip never scrolls and the first label is never cut off. */ +@media (max-width: 50rem) { + starlight-tabs .tab > [role="tab"] { + padding-inline: 0.6rem; + font-size: var(--sl-text-sm); + } +} /* Cards and pagination: hairline boxes, no shadows. */ .sl-link-card, diff --git a/site/src/styles/playground.css b/site/src/styles/playground.css index 8ff958d..c9fec88 100644 --- a/site/src/styles/playground.css +++ b/site/src/styles/playground.css @@ -302,6 +302,19 @@ a.tp-mode:hover code { white-space: pre-wrap; overflow-wrap: anywhere; } +/* Code wraps only at spaces: breaking inside a token split `->` and names in two. A token wider + than the panel (a long string literal) scrolls instead. */ +.tp-json.tp-code { + overflow-wrap: normal; +} +/* On narrow screens a wrapped continuation line starts at the left edge and loses its indentation, + so code keeps its lines and scrolls sideways instead. */ +@media (max-width: 50rem) { + .tp-json.tp-code { + white-space: pre; + overflow-x: auto; + } +} .s-kw { color: var(--tp-syn-kw); } .s-str { color: var(--tp-syn-str); } .s-num { color: var(--tp-syn-num); } From e6f7d1b3041d473a9f89096a76fb6fb64bfe6121 Mon Sep 17 00:00:00 2001 From: 4matic Date: Sun, 15 Nov 2026 04:35:38 +0200 Subject: [PATCH 4/5] chore: TRACKPARSE_C_BUILD lets compare-ports and fuzz-ports build the C port outside c/build; AGENTS.md porting-guide heading names C --- AGENTS.md | 7 +++++-- scripts/lib/ports.mjs | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 69e0620..f4514a8 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -441,7 +441,8 @@ node scripts/compare-ports.mjs --only=go # one port ag For C, compare-ports and fuzz-ports configure `c/build` (Release, `TRACKPARSE_BUILD_TESTS=OFF`) the first time and rebuild `trackparse-dump` there when a file in `c/src`, `c/wire`, `c/tools` or -`c/include` is newer than the binary. Keep test builds out of `c/build`. +`c/include` is newer than the binary. Keep test builds out of `c/build`. To keep out of each +other's way, set `TRACKPARSE_C_BUILD=c/build-` and the scripts build and run the C port there. Corpus check for R13 changes, when you have the private corpus (JSONL, one object per tracklist with `title` and `track_list`, kept in the git-ignored `spec/corpus/`): @@ -810,7 +811,9 @@ with the count. `c.yml`), so C's own normalization and lowercasing code meets every code point only when someone runs the sweep by hand. -## Porting guide (Rust, Go, others) + + +## Porting guide (Rust, Go, C, others) A port is done when it passes every fixture and every invariant. The Python, Rust, Go and C ports are done and are good second references next to JS: the Python, Rust and Go modules map one to one diff --git a/scripts/lib/ports.mjs b/scripts/lib/ports.mjs index 0787897..d3cb4a2 100644 --- a/scripts/lib/ports.mjs +++ b/scripts/lib/ports.mjs @@ -118,7 +118,10 @@ export function runLines(name, command, args, cwd) { } const cDir = join(root, "c"); -const cBuild = join(cDir, "build"); +// TRACKPARSE_C_BUILD picks another build folder (an agent or a second checkout using c/build). +const cBuild = process.env.TRACKPARSE_C_BUILD + ? resolve(root, process.env.TRACKPARSE_C_BUILD) + : join(cDir, "build"); /** The newest modification time under the C sources the dump binary is built from. */ function newestCSource() { From a50bd591eea95502b065d9689ef89bf6443595a9 Mon Sep 17 00:00:00 2001 From: 4matic Date: Sun, 15 Nov 2026 04:39:33 +0200 Subject: [PATCH 5/5] test(c): count concurrent table builds atomically in test_rt (a race in the test, found by TSan) --- c/tests/test_rt.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/c/tests/test_rt.c b/c/tests/test_rt.c index 5eb8ffd..d73e163 100644 --- a/c/tests/test_rt.c +++ b/c/tests/test_rt.c @@ -473,11 +473,16 @@ static void test_json(void) { /* Once */ static tp_once once_a = TP_ONCE_INIT, once_b = TP_ONCE_INIT, once_fail = TP_ONCE_INIT; -static int build_b_calls; +static long build_b_calls; static void *build_b(void) { int *v = (int *)tp_alloc(sizeof(int)); - build_b_calls++; + /* Two threads may build at once (tp_once_get publishes one result), so count atomically. */ +#if defined(_MSC_VER) + InterlockedIncrement(&build_b_calls); +#else + __atomic_fetch_add(&build_b_calls, 1, __ATOMIC_RELAXED); +#endif *v = 7; return v; }