Skip to main content

Crate tabnas_csv

Crate tabnas_csv 

Source
Expand description

The CSV grammar plugin for the tabnas parsing engine.

CSV text becomes an array of objects (one per row, keyed by the header row) or an array of arrays, with RFC 4180 ""-escaped quoting, custom field and record separators, streaming, and a strict / non-strict mode. In strict mode (the default) every field is raw text; in non-strict mode a field body can hold embedded jsonic ([1,2], {x:1}).

The plugin is not standalone: it layers on the relaxed-JSON grammar of tabnas_jsonic (the val / map / list / pair / elem rules) and reuses the engine’s lexer, comment handling and lifecycle hooks, exactly as the canonical TypeScript plugin in ts/src/csv.ts does.

let value = tabnas_csv::parse("name,age\nAlice,30\nBob,25")?;
assert_eq!(
    value.to_json().to_string(),
    r#"[{"name":"Alice","age":"30"},{"name":"Bob","age":"25"}]"#
);

TypeScript is canonical: ts/src/csv.ts defines behaviour and option defaults, and csv-grammar.jsonic at the repository root is the grammar every runtime embeds. The shared fixtures in test/spec/*.tsv are the parity contract across TypeScript, Go and Rust.

Structs§

CsvError
The error a failed parse produces, re-exported so callers need not depend on the engine crate directly. Its code is the contract the shared fixtures pin: csv_extra_field, csv_missing_field, and the engine’s own unexpected and unterminated_string.
CsvOptions
The plugin options: the counterpart of the TypeScript CsvOptions and Csv.defaults, and of the Go Defaults map. Default is the documented default set.
FieldOptions
Field options. See CsvOptions.
RecordOptions
Record options. See CsvOptions.
Stream
A streaming callback: records are handed to it as they are parsed and are not stored in the result, which comes back empty.
StringOptions
String options. See CsvOptions.

Enums§

StreamEvent
What a streaming parse reports, in order: Start, one Record per data row, then End. The counterpart of the TypeScript stream(what, record) callback’s 'start', 'record' and 'end' events.

Constants§

VERSION
This crate’s version. It MUST equal ts/package.json “version”: the release orchestrator rewrites both, and tests/version_test.rs fails the build if they drift. Mirrors VERSION in ts/src/csv.ts and const VERSION in go/csv.go.

Functions§

csv
Install the CSV plugin on parser, which must already carry the jsonic grammar: the counterpart of the TypeScript Csv plugin function and the Go Csv.
csv_string_matcher
The custom CSV string matcher factory: "a""b" is the text a"b.
grammar_text
The grammar source every runtime embeds, verbatim: the text of csv-grammar.jsonic at the repository root. Exposed so a test can hold the embedded copy to the file on disk.
make
Build a CSV parser with the default options.
make_with
Build a CSV parser with the given options: the counterpart of new Tabnas().use(jsonic).use(Csv, options) and the Go jsonic.Make() + UseDefaults(Csv, Defaults, options).
parse
Parse a CSV source string with the shared default parser.
plugin
The plugin form of csv, for Tabnas::use_plugin, with the documented defaults: the counterpart of tn.use(Csv, options) in TypeScript and j.UseDefaults(Csv, Defaults, options) in Go. The option bag use_plugin takes is deep-merged over the defaults and read as a CsvOptions.
plugin_with
The plugin over typed options, including a Stream callback, which cannot travel in the option bag. The bag use_plugin passes is recorded on the instance as the plugin’s options but the typed ones are what the grammar is built from.