Skip to content

@lanexio/parser-grammar-csv

This page documents @lanexio/parser-grammar-csv, the CSV grammar package for parsing RFC 4180 compliant CSV and TSV (tab-separated values) with configurable delimiter, quoting, and header detection.

  • Version: Stable
  • Module name: parser-grammar-csv
  • Package: @lanexio/parser-grammar-csv
  • Import path: @lanexio/parser-grammar-csv
  • Layer: 2 (Grammar)
  • Runtime: Universal
  • Module format: ESM
  • Stability: Stable
  • Primary use case: Parse CSV and TSV data into a flat AST.
  • You need to parse CSV (RFC 4180) data into a traversable AST.
  • You need to parse TSV (tab-separated values) data.
  • You need configurable delimiter, quoting, or header detection.
BoundaryDescription
InputsUint8Array (source bytes) + optional ParseCsvOptions
OutputsLexTree (flat AST rooted at CsvKind.Document)
Side effectsNone
DeterminismYes
External dependencies@lanexio/parser-core
Never-throw guaranteeYes
Security surfaceNone (parse only, no output generation)
  1. Install the package.

    Terminal window
    pnpm add @lanexio/parser-grammar-csv
  2. Import the named export.

    import { parseCsv } from '@lanexio/parser-grammar-csv';
RequirementRequiredLayerNotes
@lanexio/parser-coreYes1^1.0.0
import { parseCsv } from '@lanexio/parser-grammar-csv';
const encoder = new TextEncoder();
const bytes = encoder.encode('name,age\nAlice,30\nBob,25');
const tree = parseCsv(bytes);
console.log(tree.nodeCount);
console.log(tree.root.kind); // CsvKind.Document
import { parseTsv } from '@lanexio/parser-grammar-csv';
const encoder = new TextEncoder();
const tree = parseTsv(encoder.encode('name\tage\nAlice\t30'));
import { parseCsv } from '@lanexio/parser-grammar-csv';
const encoder = new TextEncoder();
const tree = parseCsv(encoder.encode('name|age\nAlice|30'), { delimiter: 0x7c });
ExportTypeDescription
parseCsv(bytes: Uint8Array, options?: ParseCsvOptions) => LexTreeParse CSV. Never throws.
parseTsv(source: Uint8Array, opts?: ParseTsvOptions) => LexTreeParse TSV (tab-separated values).
CsvKindconst objectNumeric kind IDs for all CSV node types.
CsvFieldconst objectNumeric field IDs for CSV value slots.
CSV_FLAG_HEADER4Per-node flag: this record is the header row. Set on the first CsvKind.Record node when header option is true.
CSV_FLAG_QUOTED2Per-node flag: field is enclosed in double quotes. Set on CsvKind.Field nodes whose value is quoted.
CSV_FIELD_NAMES_BY_IDreadonly string[]Field name lookup by numeric field ID.
CSV_KIND_NAMES_BY_IDreadonly Record<number, string>Kind-name lookup by numeric ID.
csvGrammarLanexioParserPureGrammarGrammar descriptor for CSV.
tsvGrammarLanexioParserPureGrammarGrammar descriptor for TSV.
csvRegistrationGrammarRegistrationRegistration for CSV.
tsvRegistrationGrammarRegistrationRegistration for TSV.
csvReuseOracleReuseOracleIncremental reuse oracle for CSV.
tsvReuseOracleReuseOracleIncremental reuse oracle for TSV.
FieldTypeRequiredDefaultDescription
delimiternumberNo0x2C (,)Field delimiter byte.
quotenumberNo0x22 (")Quote character byte.
headerbooleanNotrueWhether the first record is a header row.
relaxQuotesbooleanNotrueAllow unescaped quotes inside quoted fields (non-RFC dialects).
FieldTypeRequiredDefaultDescription
headerbooleanNotrueWhether the first record is a header row.
PropertyTypeDescription
rootLexNodeRoot node (CsvKind.Document or CsvKind.Error on pure invalid).
nodeCountnumberTotal nodes in the tree.
sourceUint8ArrayOriginal parsed bytes.
TypePurposeNotes
ParseCsvOptionsOptions for parseCsvSee options table above.
ParseTsvOptionsOptions for parseTsv{ header?: boolean }
CsvKindTypeUnion of all CsvKind valuesType-safe kind reference
CsvFieldTypeUnion of all CsvField valuesType-safe field reference

parseCsv accepts any byte as delimiter. Use parseTsv for tab-delimited data (delegates to CSV parser with delimiter: 0x09, quote: -1).

  • No direct accessibility surface. The CSV parser produces flat AST data structures.
ConcernStatus
Generated output semanticsNot applicable (data format)
ARIA attributes in serialized outputNot applicable
Semantic element round-tripNot applicable
  • parseCsv and parseTsv never throw on any byte sequence.
ThreatMitigationStatus
Malformed input byte sequencePanic-free guarantee: all inputs accepted, errors produce CsvKind.Error AST nodesImplemented
PackageRelationshipLayerNotes
@lanexio/parser-coreRequires1Provides LexTree, LexNode, LexCursor
@lanexio/parserConsumes6Unified entry point
VersionDateStatusNotable changes
1.0.02026-05-29CurrentInitial stable release. Apache-2.0.
  • None.