1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use crate::error;
use crate::token;
use crate::traits::*;
use crate::vm;

/// When parsed, this type consumes an optional `by` keyword from the input stream.
pub struct OptionalBy;

impl<S: TexlangState> Parsable<S> for OptionalBy {
    fn parse_impl(input: &mut vm::ExpandedStream<S>) -> Result<Self, Box<error::Error>> {
        let next_is_b = get_optional_element![
            input,
            token::Value::Letter('b') => (),
            token::Value::Letter('B') => (),
        ];
        if let Some(()) = next_is_b {
            get_required_element![
                input,
                "the second of letter of the `by` keyword",
                "the `by` keyword consists of a b or B letter token, then a y or Y letter token",
                token::Value::Letter('y') => OptionalBy{},
                token::Value::Letter('Y') => OptionalBy{},
            ]
        } else {
            Ok(OptionalBy {})
        }
    }
}

/// When parsed, this type consumes a required `to` keyword from the input stream.
pub struct To;

impl<S: TexlangState> Parsable<S> for To {
    fn parse_impl(input: &mut vm::ExpandedStream<S>) -> Result<Self, Box<error::Error>> {
        get_required_element![
            input,
                "the first of letter of the `to` keyword",
                "the `to` keyword consists of a t or T letter token, then a o or O letter token",
            token::Value::Letter('t') => (),
            token::Value::Letter('T') => (),
        ]?;
        get_required_element![
            input,
            "the second of letter of the `to` keyword",
            "the `to` keyword consists of a t or T letter token, then a o or O letter token",
            token::Value::Letter('o') => OptionalBy{},
            token::Value::Letter('O') => OptionalBy{},
        ]?;
        Ok(To {})
    }
}