Skip to main content

parse_lino

Function parse_lino 

Source
pub fn parse_lino(document: &str) -> Result<LiNo<String>, ParseError>
Expand description

Reads a document, with comments.

A # written where a line or a token starts opens a comment that runs to the end of the line; parse_lino_with_config reads a document without them.

ยงExamples

use links_notation::parse_lino;

let parsed = parse_lino("# what the gate checks\nci_gate: rust\n").unwrap();
assert_eq!(format!("{}", parsed), "((ci_gate: rust))");
Examples found in repository?
examples/parse_error_positions.rs (line 18)
8fn main() {
9    let documents = [
10        "ci_gate x\nstage: rust: nextest\nnext stage\n  clippy",
11        "a: b: c",
12        "a (b\n",
13        "a b)\n",
14        ":",
15    ];
16
17    for document in documents {
18        match parse_lino(document) {
19            Ok(links) => println!("{document:?} parses as {links}\n"),
20            Err(error) => {
21                println!("{error}");
22                if let ParseError::SyntaxError(syntax) = &error {
23                    println!(
24                        "  line {}, column {}, byte offset {}\n",
25                        syntax.line, syntax.column, syntax.offset
26                    );
27                }
28            }
29        }
30    }
31}
More examples
Hide additional examples
examples/comments.rs (line 19)
9fn main() {
10    let documents = [
11        "# a note about the document\ndeploy: staging\n",
12        "deploy: staging # only staging, for now\n",
13        "issue#1047: open\n",
14        "\"# not a comment\": still a reference\n",
15        "parent\n  # what the child is for\n  child\n",
16    ];
17
18    for document in documents {
19        match parse_lino(document) {
20            Ok(links) => println!("{document:?}\n  parses as {links}"),
21            Err(error) => println!("{document:?}\n  {error}"),
22        }
23    }
24
25    // Documents that predate comments can be read with `#` as an ordinary
26    // character.
27    let config = ParserConfig::without_comments();
28    let document = "# a b\n";
29    match parse_lino_with_config(document, &config) {
30        Ok(links) => println!("\nwithout comments {document:?}\n  parses as {links}"),
31        Err(error) => println!("\nwithout comments {document:?}\n  {error}"),
32    }
33}