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, RealizeError, RootedPath, VirtualPath, VirtualRoot,
31    VirtualizeError,
32};
33pub use self::source::Source;
34pub use self::span::{
35    DiagSpan, DiagSpanKind, RangeMapper, Span, SpanKind, SpanNumber, Spanned, SubRange,
36};
37
38use self::lexer::Lexer;
39use self::parser::{reparse_block, reparse_markup};
40
41/// The syntax mode of a portion of Typst code.
42#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
43pub enum SyntaxMode {
44    /// Text and markup, as in the top level.
45    Markup,
46    /// Math atoms, operators, etc., as in equations.
47    Math,
48    /// Keywords, literals and operators, as after hashes.
49    Code,
50}