links_notation/parser_config.rs
1/// ParserConfig for reading Links Notation documents.
2///
3/// Provides configuration options for controlling how a document is read.
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct ParserConfig {
6 /// If true, a `#` written where a line or a token starts opens a comment
7 /// that runs to the end of the line (default: true)
8 pub comments: bool,
9}
10
11impl Default for ParserConfig {
12 fn default() -> Self {
13 Self { comments: true }
14 }
15}
16
17impl ParserConfig {
18 /// Create a new ParserConfig with default values
19 ///
20 /// # Examples
21 /// ```
22 /// use links_notation::ParserConfig;
23 ///
24 /// assert!(ParserConfig::new().comments);
25 /// ```
26 pub fn new() -> Self {
27 Self::default()
28 }
29
30 /// Create a ParserConfig that reads `#` as an ordinary reference character,
31 /// the way documents written before comments existed were read.
32 ///
33 /// # Examples
34 /// ```
35 /// use links_notation::{parse_lino_with_config, ParserConfig};
36 ///
37 /// let parsed = parse_lino_with_config("# a b", &ParserConfig::without_comments()).unwrap();
38 /// assert_eq!(format!("{}", parsed), "((# a b))");
39 /// ```
40 pub fn without_comments() -> Self {
41 Self { comments: false }
42 }
43
44 /// Create a ParserConfig that turns comments on or off
45 ///
46 /// # Examples
47 /// ```
48 /// use links_notation::ParserConfig;
49 ///
50 /// assert_eq!(ParserConfig::with_comments(false), ParserConfig::without_comments());
51 /// ```
52 pub fn with_comments(comments: bool) -> Self {
53 Self { comments }
54 }
55}