Skip to main content

comments/
comments.rs

1//! Line comments: `#` hides the rest of its line, unless it sits inside a token
2//! or inside a delimited reference. Parsers accept comments by default and can
3//! be told to treat `#` as an ordinary character again.
4//!
5//! Run with `cargo run --example comments`.
6
7use links_notation::{parse_lino, parse_lino_with_config, ParserConfig};
8
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}