pub fn parse_lino_to_syntax_links(
document: &str,
) -> Result<Vec<LiNo<SyntaxReference>>, ParseError>Expand description
Reads a document into a collection of links whose references record how they were written.
The links are the ones parse_lino_to_links reads, with every ID a
SyntaxReference: its value is the ID
parse_lino_to_links reads and its raw is the ID
exactly as written, so (t 1 '1') still holds two equal references 1 but
the second one knows it was quoted. A link made by combining the lines of an
indented document has no ID, so it has no raw text either.
parse_lino_to_links and parse_lino are the AST mode: they read the
same links without the syntax. Turn one into the other with
LiNo::into_values or From. StreamParser::syntax reads the same
links from a stream.
ยงExamples
use links_notation::{LiNo, format_links, parse_lino_to_links, parse_lino_to_syntax_links};
let links = parse_lino_to_syntax_links("(\"a\": 'b' c)").unwrap();
let LiNo::Link { id: Some(id), values } = &links[0] else { unreachable!() };
assert_eq!(id.value, "a");
assert_eq!(id.raw.as_deref(), Some("\"a\""));
assert_eq!(id.quote(), Some('"'));
assert_eq!(values[0].raw_id(), Some("'b'"));
assert_eq!(values[1].quote(), None);
// Formatting and the plain links are exactly what the AST mode reads.
assert_eq!(format!("{}", links[0]), "(a: b c)");
let plain: Vec<LiNo<String>> = links.into_iter().map(LiNo::into_values).collect();
assert_eq!(plain, parse_lino_to_links("(\"a\": 'b' c)").unwrap());
assert_eq!(format_links(&plain), "(a: b c)");