use std::hash::{Hash, Hasher}; use std::sync::Arc; use crate::geom::{AbsUnit, AngleUnit}; use crate::util::EcoString; /// All syntactical building blocks that can be part of a Typst document. /// /// Can be emitted as a token by the tokenizer or as part of a syntax node by /// the parser. #[derive(Debug, Clone, PartialEq)] pub enum NodeKind { /// A line comment: `// ...`. LineComment, /// A block comment: `/* ... */`. BlockComment, /// One or more whitespace characters. Single spaces are collapsed into text /// nodes if they would otherwise be surrounded by text nodes. /// /// Also stores how many newlines are contained. Space { newlines: usize }, /// A left curly brace, starting a code block: `{`. LeftBrace, /// A right curly brace, terminating a code block: `}`. RightBrace, /// A left square bracket, starting a content block: `[`. LeftBracket, /// A right square bracket, terminating a content block: `]`. RightBracket, /// A left round parenthesis, starting a grouped expression, collection, /// argument or parameter list: `(`. LeftParen, /// A right round parenthesis, terminating a grouped expression, collection, /// argument or parameter list: `)`. RightParen, /// A comma separator in a sequence: `,`. Comma, /// A semicolon terminating an expression: `;`. Semicolon, /// A colon between name/key and value in a dictionary, argument or /// parameter list, or between the term and body of a description list /// term: `:`. Colon, /// The strong text toggle, multiplication operator, and wildcard import /// symbol: `*`. Star, /// Toggles emphasized text and indicates a subscript in a formula: `_`. Underscore, /// Starts and ends a math formula: `$`. Dollar, /// The unary plus, binary addition operator, and start of enum items: `+`. Plus, /// The unary negation, binary subtraction operator, and start of list /// items: `-`. Minus, /// The division operator, start of description list items, and fraction /// operator in a formula: `/`. Slash, /// The superscript operator in a formula: `^`. Hat, /// The alignment operator in a formula: `&`. Amp, /// The field access and method call operator: `.`. Dot, /// The assignment operator: `=`. Eq, /// The equality operator: `==`. EqEq, /// The inequality operator: `!=`. ExclEq, /// The less-than operator: `<`. Lt, /// The less-than or equal operator: `<=`. LtEq, /// The greater-than operator: `>`. Gt, /// The greater-than or equal operator: `>=`. GtEq, /// The add-assign operator: `+=`. PlusEq, /// The subtract-assign operator: `-=`. HyphEq, /// The multiply-assign operator: `*=`. StarEq, /// The divide-assign operator: `/=`. SlashEq, /// The spread operator: `..`. Dots, /// An arrow between a closure's parameters and body: `=>`. Arrow, /// The `not` operator. Not, /// The `and` operator. And, /// The `or` operator. Or, /// The `none` literal. None, /// The `auto` literal. Auto, /// The `let` keyword. Let, /// The `set` keyword. Set, /// The `show` keyword. Show, /// The `if` keyword. If, /// The `else` keyword. Else, /// The `for` keyword. For, /// The `in` keyword. In, /// The `while` keyword. While, /// The `break` keyword. Break, /// The `continue` keyword. Continue, /// The `return` keyword. Return, /// The `import` keyword. Import, /// The `include` keyword. Include, /// The `from` keyword. From, /// Markup of which all lines must have a minimal indentation. /// /// Notably, the number does not determine in which column the markup /// started, but to the right of which column all markup elements must be, /// so it is zero except inside indent-aware constructs like lists. Markup { min_indent: usize }, /// Plain text without markup. Text(EcoString), /// A forced line break: `\`. Linebreak, /// An escape sequence: `\#`, `\u{1F5FA}`. Escape(char), /// A shorthand for a unicode codepoint. For example, `~` for non-breaking /// space or `-?` for a soft hyphen. Shorthand(char), /// A smart quote: `'` or `"`. SmartQuote { double: bool }, /// Strong content: `*Strong*`. Strong, /// Emphasized content: `_Emphasized_`. Emph, /// Raw text with optional syntax highlighting: `` `...` ``. Raw(Arc), /// A hyperlink: `https://typst.org`. Link(EcoString), /// A label: `