summaryrefslogtreecommitdiff
path: root/crates/typst-syntax/src/ast.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/typst-syntax/src/ast.rs')
-rw-r--r--crates/typst-syntax/src/ast.rs110
1 files changed, 66 insertions, 44 deletions
diff --git a/crates/typst-syntax/src/ast.rs b/crates/typst-syntax/src/ast.rs
index 1cd9cd42..3d3a85ad 100644
--- a/crates/typst-syntax/src/ast.rs
+++ b/crates/typst-syntax/src/ast.rs
@@ -125,6 +125,8 @@ pub enum Expr<'a> {
Math(Math<'a>),
/// An identifier in math: `pi`.
MathIdent(MathIdent<'a>),
+ /// A shorthand for a unicode codepoint in math: `a <= b`.
+ MathShorthand(MathShorthand<'a>),
/// An alignment point in math: `&`.
MathAlignPoint(MathAlignPoint<'a>),
/// Matched delimiters in math: `[x + y]`.
@@ -232,6 +234,7 @@ impl<'a> AstNode<'a> for Expr<'a> {
SyntaxKind::Equation => node.cast().map(Self::Equation),
SyntaxKind::Math => node.cast().map(Self::Math),
SyntaxKind::MathIdent => node.cast().map(Self::MathIdent),
+ SyntaxKind::MathShorthand => node.cast().map(Self::MathShorthand),
SyntaxKind::MathAlignPoint => node.cast().map(Self::MathAlignPoint),
SyntaxKind::MathDelimited => node.cast().map(Self::MathDelimited),
SyntaxKind::MathAttach => node.cast().map(Self::MathAttach),
@@ -295,6 +298,7 @@ impl<'a> AstNode<'a> for Expr<'a> {
Self::Equation(v) => v.to_untyped(),
Self::Math(v) => v.to_untyped(),
Self::MathIdent(v) => v.to_untyped(),
+ Self::MathShorthand(v) => v.to_untyped(),
Self::MathAlignPoint(v) => v.to_untyped(),
Self::MathDelimited(v) => v.to_untyped(),
Self::MathAttach(v) => v.to_untyped(),
@@ -450,7 +454,7 @@ node! {
impl Shorthand<'_> {
/// A list of all shorthands in markup mode.
- pub const MARKUP_LIST: &'static [(&'static str, char)] = &[
+ pub const LIST: &'static [(&'static str, char)] = &[
("...", '…'),
("~", '\u{00A0}'),
("-", '\u{2212}'), // Only before a digit
@@ -459,52 +463,11 @@ impl Shorthand<'_> {
("-?", '\u{00AD}'),
];
- /// A list of all shorthands in math mode.
- pub const MATH_LIST: &'static [(&'static str, char)] = &[
- ("...", '…'),
- ("-", '\u{2212}'),
- ("'", '′'),
- ("*", '∗'),
- ("!=", '≠'),
- (":=", '≔'),
- ("::=", '⩴'),
- ("=:", '≕'),
- ("<<", '≪'),
- ("<<<", '⋘'),
- (">>", '≫'),
- (">>>", '⋙'),
- ("<=", '≤'),
- (">=", '≥'),
- ("->", '→'),
- ("-->", '⟶'),
- ("|->", '↦'),
- (">->", '↣'),
- ("->>", '↠'),
- ("<-", '←'),
- ("<--", '⟵'),
- ("<-<", '↢'),
- ("<<-", '↞'),
- ("<->", '↔'),
- ("<-->", '⟷'),
- ("~>", '⇝'),
- ("~~>", '⟿'),
- ("<~", '⇜'),
- ("<~~", '⬳'),
- ("=>", '⇒'),
- ("|=>", '⤇'),
- ("==>", '⟹'),
- ("<==", '⟸'),
- ("<=>", '⇔'),
- ("<==>", '⟺'),
- ("[|", '⟦'),
- ("|]", '⟧'),
- ("||", '‖'),
- ];
-
/// Get the shorthanded character.
pub fn get(self) -> char {
let text = self.0.text();
- (Self::MARKUP_LIST.iter().chain(Self::MATH_LIST))
+ Self::LIST
+ .iter()
.find(|&&(s, _)| s == text)
.map_or_else(char::default, |&(_, c)| c)
}
@@ -771,6 +734,65 @@ impl Deref for MathIdent<'_> {
}
node! {
+ /// A shorthand for a unicode codepoint in math: `a <= b`.
+ MathShorthand
+}
+
+impl MathShorthand<'_> {
+ /// A list of all shorthands in math mode.
+ pub const LIST: &'static [(&'static str, char)] = &[
+ ("...", '…'),
+ ("-", '−'),
+ ("'", '′'),
+ ("*", '∗'),
+ ("~", '∼'),
+ ("!=", '≠'),
+ (":=", '≔'),
+ ("::=", '⩴'),
+ ("=:", '≕'),
+ ("<<", '≪'),
+ ("<<<", '⋘'),
+ (">>", '≫'),
+ (">>>", '⋙'),
+ ("<=", '≤'),
+ (">=", '≥'),
+ ("->", '→'),
+ ("-->", '⟶'),
+ ("|->", '↦'),
+ (">->", '↣'),
+ ("->>", '↠'),
+ ("<-", '←'),
+ ("<--", '⟵'),
+ ("<-<", '↢'),
+ ("<<-", '↞'),
+ ("<->", '↔'),
+ ("<-->", '⟷'),
+ ("~>", '⇝'),
+ ("~~>", '⟿'),
+ ("<~", '⇜'),
+ ("<~~", '⬳'),
+ ("=>", '⇒'),
+ ("|=>", '⤇'),
+ ("==>", '⟹'),
+ ("<==", '⟸'),
+ ("<=>", '⇔'),
+ ("<==>", '⟺'),
+ ("[|", '⟦'),
+ ("|]", '⟧'),
+ ("||", '‖'),
+ ];
+
+ /// Get the shorthanded character.
+ pub fn get(self) -> char {
+ let text = self.0.text();
+ Self::LIST
+ .iter()
+ .find(|&&(s, _)| s == text)
+ .map_or_else(char::default, |&(_, c)| c)
+ }
+}
+
+node! {
/// An alignment point in math: `&`.
MathAlignPoint
}