Skip to main content

parse_reader_with

Function parse_reader_with 

Source
pub fn parse_reader_with(
    parser: &Tabnas,
    reader: impl Read,
) -> Result<Value, Json5Error>
Expand description

Parse a JSON5 source read from reader with a parser that carries the plugin: the counterpart of parse_with for a reader, and of the Go ParseReader(j, r) and the TypeScript plugin’s tn.parseReader. The requireValue rule reads reader only as far as its answer needs (check_reader), and the parser then reads the rest through Tabnas::parse_reader: a window at a time where it declares lex.window, as make’s does, so a long document is never held whole. It gives the value and the errors parse_with gives of the same text, but for an error’s excerpt of a very long line (tabnas/parser DIVERGENCE.md).

let parser = tabnas_json5::make();
let value = tabnas_json5::parse_reader_with(&parser, &b"{ a: 0x1F, b: [2,], }"[..])?;
assert_eq!(value.to_string(), r#"{"a":31,"b":[2]}"#);
let error = tabnas_json5::parse_reader_with(&parser, &b""[..]).unwrap_err();
assert_eq!(error.code, "json5_empty");