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
codeis the contract the shared fixtures pin:csv_extra_field,csv_missing_field, and the engine’s ownunexpectedandunterminated_string. - CsvOptions
- The plugin options: the counterpart of the TypeScript
CsvOptionsandCsv.defaults, and of the GoDefaultsmap.Defaultis the documented default set. - Field
Options - Field options. See
CsvOptions. - Record
Options - 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.
- String
Options - String options. See
CsvOptions.
Enums§
- Stream
Event - What a streaming parse reports, in order:
Start, oneRecordper data row, thenEnd. The counterpart of the TypeScriptstream(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, andtests/version_test.rsfails the build if they drift. MirrorsVERSIONints/src/csv.tsandconst VERSIONingo/csv.go.
Functions§
- csv
- Install the CSV plugin on
parser, which must already carry the jsonic grammar: the counterpart of the TypeScriptCsvplugin function and the GoCsv. - csv_
string_ matcher - The custom CSV string matcher factory:
"a""b"is the texta"b. - grammar_
text - The grammar source every runtime embeds, verbatim: the text of
csv-grammar.jsonicat 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 Gojsonic.Make()+UseDefaults(Csv, Defaults, options). - parse
- Parse a CSV source string with the shared default parser.
- plugin
- The plugin form of
csv, forTabnas::use_plugin, with the documented defaults: the counterpart oftn.use(Csv, options)in TypeScript andj.UseDefaults(Csv, Defaults, options)in Go. The option baguse_plugintakes is deep-merged over the defaults and read as aCsvOptions. - plugin_
with - The plugin over typed options, including a
Streamcallback, which cannot travel in the option bag. The baguse_pluginpasses is recorded on the instance as the plugin’s options but the typed ones are what the grammar is built from.