book_string_simple/
book_string_simple.rs

1fn main() -> trivet::errors::ParseResult<()> {
2    let mut parser = trivet::parse_from_stdin();
3    while !parser.is_at_eof() {
4        // Save the location for later use in error messages.
5        let loc = parser.loc();
6        // Parse strings only for the supported delimiters.
7        let string = match parser.peek() {
8            // The initial and final delimiters match.
9            '"' | '\'' => parser.parse_string_match_delimiter_ws()?,
10            // Here the initial and final delimiters do not match.
11            '«' => {
12                parser.consume();
13                parser.parse_string_until_delimiter_ws('»')?
14            }
15            // This is not a legal opening delimiter.
16            ch => {
17                return Err(trivet::errors::syntax_error(
18                    loc,
19                    &format!("Invalid delimiter: '{}'", ch),
20                ));
21            }
22        };
23        println!("  --> {:?}", string);
24    }
25    Ok(())
26}