book_primitives_lua/
book_primitives_lua.rs

1fn main() {
2    // Text to parse.  Note that the comment ends on line 5 at column 12, with
3    // the first non-comment position at column 13.
4    let mut parser = trivet::parse_from_string(
5        r#"
6        --[[
7            I am a long form
8            Lua comment.
9        --]]"#,
10    );
11    parser.borrow_comment_parser().enable_c = false;
12    parser.borrow_comment_parser().enable_cpp = false;
13    parser.borrow_comment_parser().custom = Box::new(|parser: &mut trivet::ParserCore| -> bool {
14        if parser.peek_and_consume_chars(&['-', '-', '[', '[']) {
15            parser.take_until("--]]");
16            true
17        } else if parser.peek_and_consume_chars(&['-', '-']) {
18            parser.take_while(|ch| ch != '\n');
19            true
20        } else {
21            false
22        }
23    });
24    parser.borrow_comment_parser().enable_custom = true;
25    parser.consume_ws();
26    assert_eq!(parser.loc().to_string(), "<string>:5:13");
27    assert!(parser.is_at_eof());
28}