Skip to main content

parse_error_positions/
parse_error_positions.rs

1//! What a parse error says: the line, the column, what could have stood there
2//! and the offending line with a caret under it.
3//!
4//! Run with `cargo run --example parse_error_positions`.
5
6use links_notation::{parse_lino, ParseError};
7
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}