Skip to main content

csv

Function csv 

Source
pub fn csv(parser: &mut Tabnas, options: &CsvOptions) -> Result<(), PluginError>
Expand description

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.

let mut parser = tabnas_jsonic::make();
tabnas_csv::csv(&mut parser, &tabnas_csv::CsvOptions::default())?;
let value = parser.parse("a,b\n1,2")?;
assert_eq!(value.to_json().to_string(), r#"[{"a":"1","b":"2"}]"#);

In order: the closures the grammar names are registered, the per-instance engine options are applied, the embedded grammar is installed with every alternate tagged csv, and the list, elem and val rules are modified in code (replaced in strict mode, extended in non-strict mode, so embedded jsonic values keep working).