mitex_parser/
lib.rs

1//! Given source strings, MiTeX Parser provides an AST (abstract syntax tree).
2//!
3//! ## Option: Command Specification
4//! The parser retrieves a command specification which defines shape of
5//! commands. With the specification, the parser can parse commands correctly.
6//! Otherwise, all commands are parsed as barely names without arguments.
7//!
8//! ## Produce: AST
9//! It returns an untyped syntax node representing the AST defined by [`rowan`].
10//! You can access the AST conveniently with interfaces provided by
11//! [`rowan::SyntaxNode`].
12//!
13//! The untyped syntax node can convert to typed ones defined in
14//! [`crate::syntax`].
15//!
16//! The untyped syntax node can also convert to [`rowan::cursor::SyntaxNode`] to
17//! modify the AST syntactically.
18
19mod arg_match;
20mod parser;
21pub mod syntax;
22
23pub use mitex_spec as spec;
24pub use spec::preludes::command as command_preludes;
25pub use spec::*;
26use syntax::SyntaxNode;
27
28use parser::Parser;
29
30/// Parse the input text with the given command specification
31/// and return the untyped syntax tree
32///
33/// The error nodes are attached to the tree
34pub fn parse(input: &str, spec: CommandSpec) -> SyntaxNode {
35    SyntaxNode::new_root(Parser::new_macro(input, spec).parse())
36}
37
38/// It is only for internal testing
39pub fn parse_without_macro(input: &str, spec: CommandSpec) -> SyntaxNode {
40    SyntaxNode::new_root(Parser::new(input, spec).parse())
41}