pulldown_latex/parser/state.rs
1use super::AlignmentCount;
2use crate::event::ScriptPosition;
3
4/// State belonging to the parser that is reset every call to the `next` method of the parser.
5#[derive(Debug)]
6pub struct ParserState<'a> {
7 /// Whether the parser is currently parsing an operator that allows for its scripts to be
8 /// modified by the commands `\nolimits`, `\limits`, and `\displaylimits`.
9 pub allow_script_modifiers: bool,
10 /// What type of script should be rendered by default for the current operator.
11 pub script_position: ScriptPosition,
12 /// Whether the parser should skip script parsing for the current event.
13 pub skip_scripts: bool,
14 /// Whether we are currently handling an arument to a control sequence.
15 ///
16 /// This affects things like whether we can parse the `\relax` command and
17 /// subscripts/superscripts.
18 ///
19 /// Another example: if we are looking for an argument to a control sequence, we should not
20 /// allow '&' or '\\' to be parsed.
21 pub handling_argument: bool,
22 /// Number of `&` characters allowed in the current line of the current group.
23 ///
24 /// If `None`, then we are in a group where both `\\` (newlines) and `&` (alignments) are disallowed.
25 /// Otherwise, this is the number of `&` characters allowed in the current line.
26 pub allowed_alignment_count: Option<&'a mut AlignmentCount>,
27}
28
29impl<'a> Default for ParserState<'a> {
30 fn default() -> Self {
31 Self {
32 allow_script_modifiers: false,
33 script_position: ScriptPosition::Right,
34 skip_scripts: false,
35 handling_argument: false,
36 allowed_alignment_count: None,
37 }
38 }
39}