pub struct Parser<'a> {
pub mode: Mode,
pub gullet: MacroExpander<'a>,
pub leftright_depth: i32,
/* private fields */
}Expand description
The LaTeX parser. Converts a token stream into a ParseNode AST.
Follows KaTeX’s Parser.ts closely:
parse()→ parse full expressionparseExpression()→ parse a list of atomsparseAtom()→ parse one atom with optional super/subscriptsparseGroup()→ parse a group (braced or single token)parseFunction()→ parse a function call with argumentsparseSymbol()→ parse a single symbol
Fields§
§mode: Mode§gullet: MacroExpander<'a>§leftright_depth: i32Implementations§
Source§impl<'a> Parser<'a>
impl<'a> Parser<'a>
pub fn new(input: &'a str) -> Self
Sourcepub fn fetch(&mut self) -> ParseResult<Token>
pub fn fetch(&mut self) -> ParseResult<Token>
Return the current lookahead token (fetching from gullet if needed).
Sourcepub fn expect(&mut self, text: &str, do_consume: bool) -> ParseResult<()>
pub fn expect(&mut self, text: &str, do_consume: bool) -> ParseResult<()>
Expect the next token to have the given text, consuming it.
Sourcepub fn consume_spaces(&mut self) -> ParseResult<()>
pub fn consume_spaces(&mut self) -> ParseResult<()>
Consume spaces in math mode.
Sourcepub fn switch_mode(&mut self, new_mode: Mode)
pub fn switch_mode(&mut self, new_mode: Mode)
Switch between “math” and “text” modes.
Sourcepub fn parse(&mut self) -> ParseResult<Vec<ParseNode>>
pub fn parse(&mut self) -> ParseResult<Vec<ParseNode>>
Parse the entire input and return the AST.
Sourcepub fn parse_expression(
&mut self,
break_on_infix: bool,
break_on_token_text: Option<&str>,
) -> ParseResult<Vec<ParseNode>>
pub fn parse_expression( &mut self, break_on_infix: bool, break_on_token_text: Option<&str>, ) -> ParseResult<Vec<ParseNode>>
Parse an expression: a list of atoms.
Sourcepub fn parse_atom(
&mut self,
break_on_token_text: Option<&str>,
) -> ParseResult<Option<ParseNode>>
pub fn parse_atom( &mut self, break_on_token_text: Option<&str>, ) -> ParseResult<Option<ParseNode>>
Parse a single atom with optional super/subscripts.
Sourcepub fn parse_group(
&mut self,
name: &str,
break_on_token_text: Option<&str>,
) -> ParseResult<Option<ParseNode>>
pub fn parse_group( &mut self, name: &str, break_on_token_text: Option<&str>, ) -> ParseResult<Option<ParseNode>>
Parse a group: braced expression, function call, or single symbol.
Sourcepub fn parse_function(
&mut self,
break_on_token_text: Option<&str>,
name: Option<&str>,
) -> ParseResult<Option<ParseNode>>
pub fn parse_function( &mut self, break_on_token_text: Option<&str>, name: Option<&str>, ) -> ParseResult<Option<ParseNode>>
Try to parse a function call. Returns None if not a function.
Sourcepub fn call_function(
&mut self,
name: &str,
args: Vec<ParseNode>,
opt_args: Vec<Option<ParseNode>>,
token: Option<Token>,
break_on_token_text: Option<&str>,
) -> ParseResult<ParseNode>
pub fn call_function( &mut self, name: &str, args: Vec<ParseNode>, opt_args: Vec<Option<ParseNode>>, token: Option<Token>, break_on_token_text: Option<&str>, ) -> ParseResult<ParseNode>
Call a function handler.
Sourcepub fn parse_arguments(
&mut self,
func: &str,
func_data: &FunctionSpec,
) -> ParseResult<(Vec<ParseNode>, Vec<Option<ParseNode>>)>
pub fn parse_arguments( &mut self, func: &str, func_data: &FunctionSpec, ) -> ParseResult<(Vec<ParseNode>, Vec<Option<ParseNode>>)>
Parse the arguments for a function.
Sourcepub fn parse_size_group(
&mut self,
optional: bool,
) -> ParseResult<Option<ParseNode>>
pub fn parse_size_group( &mut self, optional: bool, ) -> ParseResult<Option<ParseNode>>
Parse a size group (e.g., “3pt”, “1em”).
Sourcepub fn parse_argument_group(
&mut self,
optional: bool,
mode: Option<Mode>,
) -> ParseResult<Option<ParseNode>>
pub fn parse_argument_group( &mut self, optional: bool, mode: Option<Mode>, ) -> ParseResult<Option<ParseNode>>
Parse an argument group (with optional mode switch).
Auto Trait Implementations§
impl<'a> Freeze for Parser<'a>
impl<'a> RefUnwindSafe for Parser<'a>
impl<'a> Send for Parser<'a>
impl<'a> Sync for Parser<'a>
impl<'a> Unpin for Parser<'a>
impl<'a> UnsafeUnpin for Parser<'a>
impl<'a> UnwindSafe for Parser<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more