Repository navigation
feat(rust): the Rust port - #26
Merged
Merged
Conversation
… harness rust/ is now a Cargo package: data.rs and the Unicode L / Lu tables are generated from spec/data and the JS engine (scripts/gen_data.mjs, with --check), types mirror the schema with to_json(), and tests/fixtures.rs runs every shared fixture through trackparse::wire::call with the README matcher, xfail/ambiguous/skip handling and a conformance report. The parser is a stub: 0 / 13130.
…with it rustfmt.toml sets max_width 100 and use_small_heuristics Max, the width the JS and Python ports use. json.rs and tests/fixtures.rs are reformatted; the generated data.rs and unicode_tables.rs are skipped so gen_data.mjs stays the only writer.
…_track, normalize, Parser) Modules mirror js/src one to one (words, digits, normalize, mode, scanner, prefix, classify, separator, artists, credits, title, assemble, format, tables, context, parser, options) with the same rule IDs in comments. - Public API: parse / parse_with, parse_artists / parse_artists_with, format_track / format_track_with, normalize, all_artists, Parser, and typed ParseOptions, FormatOptions and KeywordOptions with builder-style setters. - wire::call answers parse, parseArtists, format and normalize; loose JSON options are resolved with the JS fallbacks (unknown mode, splitAnd, non-object keywords, Object.entries key order). - Offsets are UTF-16 units and the knownArtists window counts UTF-16 units, as in JS; letter and uppercase tests use the generated L / Lu tables; keyword keys are trimmed like JS trim(). - The internal ListParser (probe / finish with the list-context flag) is in place for R13. - Unit tests for the R0 primitives use values dumped from js/src/words.ts (scripts/dump_primitives.mjs writes tests/data/primitives.json). Every non-tracklist fixture passes (11,914 of 13,130; the rest are parseTracklist / applyEdits).
tests/api.rs checks that the typed API (options, format options, Parser) gives the same JSON as wire::call, that bad loose options fall back as in JS, and that 10,000-code-point inputs finish quickly in every mode. examples/dump.rs reads JSONL cases on stdin and writes one JSON result per line through wire::call, for a differential run against js/dist.
rust.yml runs fmt, clippy, every fixture and the package dry run on stable and on the MSRV (1.74), plus a job that diffs the full output of every fixture input against the built JS package. compare-ports.mjs now compares JS with each other port (--only=python / --only=rust).
Port of js/src/tracklist to rust/src/tracklist, one module per JS file: line split, time scanner, emphasis markers, kinds, bare positions, warnings with the out-of-order suggestion search, and apply_edits. wire::call now answers parseTracklist and applyEdits; typed Edit values go through the same loose-JSON path as the fixtures. - json: numbers are written as JS Number::toString does (1e+21, 1e-7, -0 as 0) - fixtures harness: 1e999 reaches the crate as infinity - tests: typed tracklist API vs the wire, R13.11 properties and time ceilings - LICENSE copied into the crate for cargo package All 13,130 shared fixtures pass with an empty skip list.
… compiler's Unicode version str::to_lowercase follows the toolchain: on Rust 1.74, 55 letters lowercased differently from the JS reference. gen_data.mjs now writes the toLowerCase() mapping and the Cased and Case_Ignorable ranges for the final-sigma rule into unicode_tables.rs; words.rs reads them. Checked against JS over every scalar value and 160,000 strings around sigma, on 1.74 and stable.
The JS / Python switch gains Rust in both code panels. The generated Rust is a whole program (use, fn main) built from the option builders and the Edit constructors; codeHtml has an rs branch.
…oject pages All 56 tab groups are JavaScript, Python, Rust. Every Rust example was compiled and run against the crate. cargo in the install switch (it wraps on phones), the Rust row and findings on the ports page, three ports in testing and contributing.
README: ports table, install, a Rust quick start, At a glance. AGENTS.md: repo map and commands for rust/, the trilingual tab template, rust.yml, the hazards the Rust port found, definition of done.
- serde (optional): Serialize and Deserialize on every output type, the options and Edit, with the spec's keys; serde_json::to_string(&x) is the text of x.to_json(). A test asserts it over every fixture input, and that options and edits read from JSON give what the JSON door gives. - to_json() is an inherent method on every output type; ToJson stays for generic code. - Enums: FromStr (UnknownName), NAMES, Default on the option enums; #[non_exhaustive] on the enums that can grow, on the option structs and on Edit. - Edit constructors: set_time, shift, shift_from, shift_lines, sort_by_time, set_rest, insert, delete. - The types and options modules are private; everything is exported from the crate root and from trackparse::tracklist. json::Json implements Display. - Crate docs and a runnable example on every public function and type; #![warn(missing_docs)].
Install, quick start, the API with options tables, JSON and serde, modes, tracklists, how it is tested and the minimum Rust version. Every Rust example is a doc test (cargo test --all-features runs the README). docs.rs builds with all features.
…o publish job rust joins js, spec and python in the linked versions (Cargo.toml and SPEC_VERSION in data.rs are bumped by the release PR). publish-crates uses crates.io trusted publishing and runs only when the repository variable CRATES_PUBLISH is "true": the first publish of a new crate has to be done by hand before a trusted publisher can be configured. spec.yml checks all four versions match.
…chain action from the publish job
…ase setup Type listings follow the real definitions (ParseOptions field order, #[non_exhaustive] on the option structs and Edit). AGENTS.md and the Ports page describe the rust release-please component, the rust-vX.Y.Z tag, the CRATES_PUBLISH gate and the first publish by hand.
…hen js/src changes
…credits Each credit list keeps its remaining names in an ordered set, so the R7.6 joiner hand-over is a lookup, not a scan of every entry. Output is unchanged: a unit test compares it with the plain algorithm on 20,000 random credit lists, and compare-ports reports 0 differences.
- EditWarning.line is Option<usize>, like every other line number (saturating from the JS number the edit ran on); to_json() and the wire still print what JavaScript prints. - unicode-normalization >= 0.1.26: older releases have older Unicode tables. - Json is #[non_exhaustive] and ToJson is sealed. - serde: numbers share the to_json() writer (digits of 2^53 and more as JavaScript prints them, lines above 2^53 as doubles), non-finite seconds are null and read back as NaN, keyword maps are written and read without repeated keys. - Hash on the Eq output and option types, Clone on Parser, doc(cfg) for docs.rs. - The guarantees no longer claim linear time; they say what the tests check. - tests/properties.rs: the single-track invariants of SPEC.md on generated strings, the 10,000-code-point ceiling and a 40k/160k scaling check.
…README compare-ports compares the complete JSON output, not bytes.
…ndencies every run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The third port: a Rust crate in
rust/, to be published astrackparseon crates.io. It passes every shared fixture and gives the same JSON as the JS reference.The crate
js/srcfile (single tracks R0–R12, tracklists R13), same rule IDs in comments.unicode-normalization≥ 0.1.26);serdebehind a feature; nounsafe; clippy deniesunwrap,expect,panicand indexing insrc/; MSRV 1.74.parse,parse_with,parse_artists,format_track,normalize,all_artists,Parser;tracklist::{parse_tracklist, apply_edits, Edit, …};to_json()on every output type gives the spec's JSON; option structs with chained setters.rust/scripts/gen_data.mjs, with--check).Evidence
scripts/compare-ports.mjsnow compares JS with Python and with Rust: 0 differences each on all 13,130 cases.Docs
rust/README.mdis the crates.io page; its 17 examples are doc tests.CI and release
rust.yml: fmt, clippy, tests on stable and 1.74 (--locked), package dry run, and the JS-vs-Rust comparison.rustjoins the linked versions (rust-vX.Y.Z).publish-cratesuses crates.io trusted publishing and is gated on the repository variableCRATES_PUBLISH, because the first publish of a new crate has to be done by hand.spec.ymlchecks four versions.Known and documented
unicode-normalization(Unicode 18); Node 24 has Unicode 17, so 32 new combining marks can order differently.