summaryrefslogtreecommitdiff
path: root/src/syntax
diff options
context:
space:
mode:
Diffstat (limited to 'src/syntax')
-rw-r--r--src/syntax/ast.rs19
-rw-r--r--src/syntax/highlight.rs4
-rw-r--r--src/syntax/kind.rs5
-rw-r--r--src/syntax/parsing.rs1
-rw-r--r--src/syntax/tokens.rs21
5 files changed, 49 insertions, 1 deletions
diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs
index 3c60acbb..c44fa2a0 100644
--- a/src/syntax/ast.rs
+++ b/src/syntax/ast.rs
@@ -85,6 +85,8 @@ pub enum MarkupNode {
/// A shorthand for a unicode codepoint. For example, `~` for non-breaking
/// space or `-?` for a soft hyphen.
Shorthand(Shorthand),
+ /// Symbol notation: `:arrow:l:`.
+ Symbol(Symbol),
/// A smart quote: `'` or `"`.
SmartQuote(SmartQuote),
/// Strong content: `*Strong*`.
@@ -119,6 +121,7 @@ impl AstNode for MarkupNode {
SyntaxKind::Text(_) => node.cast().map(Self::Text),
SyntaxKind::Escape(_) => node.cast().map(Self::Escape),
SyntaxKind::Shorthand(_) => node.cast().map(Self::Shorthand),
+ SyntaxKind::Symbol(_) => node.cast().map(Self::Symbol),
SyntaxKind::SmartQuote { .. } => node.cast().map(Self::SmartQuote),
SyntaxKind::Strong => node.cast().map(Self::Strong),
SyntaxKind::Emph => node.cast().map(Self::Emph),
@@ -141,6 +144,7 @@ impl AstNode for MarkupNode {
Self::Text(v) => v.as_untyped(),
Self::Escape(v) => v.as_untyped(),
Self::Shorthand(v) => v.as_untyped(),
+ Self::Symbol(v) => v.as_untyped(),
Self::SmartQuote(v) => v.as_untyped(),
Self::Strong(v) => v.as_untyped(),
Self::Emph(v) => v.as_untyped(),
@@ -224,6 +228,21 @@ impl Shorthand {
}
node! {
+ /// Symbol notation: `:arrow:l:`.
+ Symbol
+}
+
+impl Symbol {
+ /// Get the symbol's notation.
+ pub fn get(&self) -> &EcoString {
+ match self.0.kind() {
+ SyntaxKind::Symbol(v) => v,
+ _ => panic!("symbol is of wrong kind"),
+ }
+ }
+}
+
+node! {
/// A smart quote: `'` or `"`.
SmartQuote
}
diff --git a/src/syntax/highlight.rs b/src/syntax/highlight.rs
index 526d1302..d4da7b3e 100644
--- a/src/syntax/highlight.rs
+++ b/src/syntax/highlight.rs
@@ -139,6 +139,8 @@ pub enum Category {
Escape,
/// An easily typable shortcut to a unicode codepoint.
Shorthand,
+ /// Symbol notation.
+ Symbol,
/// A smart quote.
SmartQuote,
/// Strong markup.
@@ -285,6 +287,7 @@ impl Category {
SyntaxKind::Linebreak => Some(Category::Escape),
SyntaxKind::Escape(_) => Some(Category::Escape),
SyntaxKind::Shorthand(_) => Some(Category::Shorthand),
+ SyntaxKind::Symbol(_) => Some(Category::Symbol),
SyntaxKind::SmartQuote { .. } => Some(Category::SmartQuote),
SyntaxKind::Strong => Some(Category::Strong),
SyntaxKind::Emph => Some(Category::Emph),
@@ -369,6 +372,7 @@ impl Category {
Self::Punctuation => "punctuation.typst",
Self::Escape => "constant.character.escape.typst",
Self::Shorthand => "constant.character.shorthand.typst",
+ Self::Symbol => "constant.symbol.typst",
Self::SmartQuote => "constant.character.quote.typst",
Self::Strong => "markup.bold.typst",
Self::Emph => "markup.italic.typst",
diff --git a/src/syntax/kind.rs b/src/syntax/kind.rs
index a7425d70..a4eb317b 100644
--- a/src/syntax/kind.rs
+++ b/src/syntax/kind.rs
@@ -144,6 +144,9 @@ pub enum SyntaxKind {
/// A shorthand for a unicode codepoint. For example, `~` for non-breaking
/// space or `-?` for a soft hyphen.
Shorthand(char),
+ /// Symbol notation: `:arrow:l:`. The string only contains the inner part
+ /// without leading and trailing dot.
+ Symbol(EcoString),
/// A smart quote: `'` or `"`.
SmartQuote { double: bool },
/// Strong content: `*Strong*`.
@@ -389,6 +392,7 @@ impl SyntaxKind {
Self::Linebreak => "linebreak",
Self::Escape(_) => "escape sequence",
Self::Shorthand(_) => "shorthand",
+ Self::Symbol(_) => "symbol notation",
Self::Strong => "strong content",
Self::Emph => "emphasized content",
Self::Raw(_) => "raw block",
@@ -507,6 +511,7 @@ impl Hash for SyntaxKind {
Self::Linebreak => {}
Self::Escape(c) => c.hash(state),
Self::Shorthand(c) => c.hash(state),
+ Self::Symbol(s) => s.hash(state),
Self::SmartQuote { double } => double.hash(state),
Self::Strong => {}
Self::Emph => {}
diff --git a/src/syntax/parsing.rs b/src/syntax/parsing.rs
index 1678eb01..59e066a6 100644
--- a/src/syntax/parsing.rs
+++ b/src/syntax/parsing.rs
@@ -230,6 +230,7 @@ fn markup_node(p: &mut Parser, at_start: &mut bool) {
| SyntaxKind::SmartQuote { .. }
| SyntaxKind::Escape(_)
| SyntaxKind::Shorthand(_)
+ | SyntaxKind::Symbol(_)
| SyntaxKind::Link(_)
| SyntaxKind::Raw(_)
| SyntaxKind::Ref(_) => p.eat(),
diff --git a/src/syntax/tokens.rs b/src/syntax/tokens.rs
index e7015bb2..130ad668 100644
--- a/src/syntax/tokens.rs
+++ b/src/syntax/tokens.rs
@@ -203,6 +203,7 @@ impl<'s> Tokens<'s> {
'#' => self.hash(start),
'.' if self.s.eat_if("..") => SyntaxKind::Shorthand('\u{2026}'),
'-' => self.hyph(),
+ ':' => self.colon(),
'h' if self.s.eat_if("ttp://") || self.s.eat_if("ttps://") => {
self.link(start)
}
@@ -224,7 +225,6 @@ impl<'s> Tokens<'s> {
'=' => SyntaxKind::Eq,
'+' => SyntaxKind::Plus,
'/' => SyntaxKind::Slash,
- ':' => SyntaxKind::Colon,
// Plain text.
_ => self.text(start),
@@ -328,6 +328,25 @@ impl<'s> Tokens<'s> {
}
}
+ fn colon(&mut self) -> SyntaxKind {
+ let start = self.s.cursor();
+ let mut end = start;
+ while !self.s.eat_while(char::is_ascii_alphanumeric).is_empty() && self.s.at(':')
+ {
+ end = self.s.cursor();
+ self.s.eat();
+ }
+
+ self.s.jump(end);
+
+ if start < end {
+ self.s.expect(':');
+ SyntaxKind::Symbol(self.s.get(start..end).into())
+ } else {
+ SyntaxKind::Colon
+ }
+ }
+
fn link(&mut self, start: usize) -> SyntaxKind {
#[rustfmt::skip]
self.s.eat_while(|c: char| matches!(c,