texlang/parse/
keyword.rs

1use crate::error;
2use crate::token;
3use crate::traits::*;
4use crate::vm;
5
6/// When parsed, this type consumes an optional `by` keyword from the input stream.
7pub struct OptionalBy;
8
9impl<S: TexlangState> Parsable<S> for OptionalBy {
10    fn parse_impl(input: &mut vm::ExpandedStream<S>) -> Result<Self, Box<error::Error>> {
11        let next_is_b = get_optional_element![
12            input,
13            token::Value::Letter('b') => (),
14            token::Value::Letter('B') => (),
15        ];
16        if let Some(()) = next_is_b {
17            get_required_element![
18                input,
19                "the second of letter of the `by` keyword",
20                "the `by` keyword consists of a b or B letter token, then a y or Y letter token",
21                token::Value::Letter('y') => OptionalBy{},
22                token::Value::Letter('Y') => OptionalBy{},
23            ]
24        } else {
25            Ok(OptionalBy {})
26        }
27    }
28}