Skip to content

CSV and TSV Conformance

Lanexio™ Parser implements RFC 4180 compliant CSV and TSV parsing with configurable delimiters, field quoting, and header-row detection. A single package (@lanexio/parser-grammar-csv) exports both parseCsv and parseTsv.

The conformance suite validates every clause of the RFC:

  • §2.1 — Basic format: header row, record separation, field counts
  • §2.3 — Header row: CSV_FLAG_HEADER detection and opt-in control
  • §2.4 — Multiple records: optional trailing newline
  • §2.5 — Whitespace: significant whitespace within quoted fields, insignificant elsewhere
  • §2.6 — Quoted fields: double-quote escaping, embedded commas, embedded line breaks
  • §2.7 — Double-quote within quoted field

610 tests pass across the CSV and TSV grammar paths.

Both parseCsv and parseTsv accept a mode option ("lenient" or "strict"). The default is "lenient", which keeps the recovery behavior of every previous release.

In "strict" mode the parse path still never throws, but spec-level rejections are surfaced as flags:

  • A record that fails to parse (an unclosed quote, or a bad quote position) is flagged on its Record node.
  • A record whose field count differs from the reference row is also flagged. The reference is the header row when header: true (the default), otherwise the first record.
  • When any record is rejected, the Document root carries LEX_NODE_HAS_ERROR | GRAMMAR_FLAG_NODE_ERROR and tree.root.hasError reads true.

Use strict mode when a downstream consumer needs a single, callable guarantee that the input is a rectangular table. Keep "lenient" when you parse heterogeneous or streaming data and only care about recovery.

AxisResult
never-throw0 throws across full corpus
well-formedcorpus WF = 0
losslesscorpus lossless = 0, byte-exact round-trip
conformance610/610, RFC 4180 covered

pnpm conformance:suite measured this family over the test_files/csv corpus on 2026-10-06 at Lanexio™ Parser version 1.0.0:

familyvalidinvalidrawcontract-subsetREAL-DEFECT
csv552399.1%99.6% (550/552)2

The contract-subset here is the clean valid inputs over all valid inputs (this family carries no artifact buckets); the 2 REAL-DEFECT entries are valid-classified files that report an error.