Skip to main content

typst_syntax/
lib.rs

1//! Parser and syntax tree for Typst.
2
3pub mod ast;
4pub mod package;
5
6mod highlight;
7mod kind;
8mod lexer;
9mod lines;
10mod node;
11mod parser;
12mod path;
13mod reparser;
14mod set;
15mod source;
16mod span;
17
18pub use self::highlight::{Tag, highlight, highlight_html};
19pub use self::kind::SyntaxKind;
20pub use self::lexer::{
21    is_id_continue, is_id_start, is_ident, is_newline, is_valid_label_literal_id,
22    link_prefix, split_newlines,
23};
24pub use self::lines::Lines;
25pub use self::node::{
26    Diagnosis, LinkedChildren, LinkedNode, Side, SyntaxDiagnostic, SyntaxNode,
27};
28pub use self::parser::{parse, parse_code, parse_math};
29pub use self::path::{
30    FileId, PathError, RootedPath, VirtualPath, VirtualRoot, VirtualizeError,
31};
32pub use self::source::Source;
33pub use self::span::{
34    DiagSpan, DiagSpanKind, RangeMapper, Span, SpanKind, SpanNumber, Spanned, SubRange,
35};
36
37use self::lexer::Lexer;
38use self::parser::{reparse_block, reparse_markup};
39
40/// The syntax mode of a portion of Typst code.
41#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
42pub enum SyntaxMode {
43    /// Text and markup, as in the top level.
44    Markup,
45    /// Math atoms, operators, etc., as in equations.
46    Math,
47    /// Keywords, literals and operators, as after hashes.
48    Code,
49}