diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-08-30 15:00:18 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-09-07 11:07:17 +0200 |
| commit | 0d12f2ab23177642eef2e6bb9c583cdd0c743b33 (patch) | |
| tree | 03a88594081dcf360d0d880167feb1debca970e6 /src/syntax | |
| parent | 0cb876ebf9138c1ee3b3c87165952a73569ffb28 (diff) | |
[WIP] Label and reference syntax
Diffstat (limited to 'src/syntax')
| -rw-r--r-- | src/syntax/ast.rs | 6 | ||||
| -rw-r--r-- | src/syntax/highlight.rs | 34 | ||||
| -rw-r--r-- | src/syntax/mod.rs | 8 |
3 files changed, 35 insertions, 13 deletions
diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index 67f9e038..10bee4e8 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -84,6 +84,8 @@ impl Markup { NodeKind::Heading => node.cast().map(MarkupNode::Heading), NodeKind::List => node.cast().map(MarkupNode::List), NodeKind::Enum => node.cast().map(MarkupNode::Enum), + NodeKind::Label(v) => Some(MarkupNode::Label(v.clone())), + NodeKind::Ref(v) => Some(MarkupNode::Ref(v.clone())), _ => node.cast().map(MarkupNode::Expr), }) } @@ -116,6 +118,10 @@ pub enum MarkupNode { List(ListNode), /// An item in an enumeration (ordered list): `1. ...`. Enum(EnumNode), + /// A label. + Label(EcoString), + /// A reference. + Ref(EcoString), /// An expression. Expr(Expr), } diff --git a/src/syntax/highlight.rs b/src/syntax/highlight.rs index b52234d4..ff02190a 100644 --- a/src/syntax/highlight.rs +++ b/src/syntax/highlight.rs @@ -153,6 +153,10 @@ pub enum Category { Punctuation, /// A line or block comment. Comment, + /// An easily typable shortcut to a unicode codepoint. + Shortcut, + /// An escape sequence. + Escape, /// Strong text. Strong, /// Emphasized text. @@ -165,10 +169,10 @@ pub enum Category { Heading, /// A list or enumeration. List, - /// An easily typable shortcut to a unicode codepoint. - Shortcut, - /// An escape sequence. - Escape, + /// A label. + Label, + /// A reference. + Ref, /// A keyword. Keyword, /// An operator symbol. @@ -212,6 +216,13 @@ impl Category { NodeKind::Dot => Some(Category::Punctuation), NodeKind::LineComment => Some(Category::Comment), NodeKind::BlockComment => Some(Category::Comment), + NodeKind::Linebreak { .. } => Some(Category::Shortcut), + NodeKind::NonBreakingSpace => Some(Category::Shortcut), + NodeKind::Shy => Some(Category::Shortcut), + NodeKind::EnDash => Some(Category::Shortcut), + NodeKind::EmDash => Some(Category::Shortcut), + NodeKind::Ellipsis => Some(Category::Shortcut), + NodeKind::Escape(_) => Some(Category::Escape), NodeKind::Strong => Some(Category::Strong), NodeKind::Emph => Some(Category::Emph), NodeKind::Raw(_) => Some(Category::Raw), @@ -222,13 +233,8 @@ impl Category { _ => Some(Category::Operator), }, NodeKind::EnumNumbering(_) => Some(Category::List), - NodeKind::Linebreak { .. } => Some(Category::Shortcut), - NodeKind::NonBreakingSpace => Some(Category::Shortcut), - NodeKind::Shy => Some(Category::Shortcut), - NodeKind::EnDash => Some(Category::Shortcut), - NodeKind::EmDash => Some(Category::Shortcut), - NodeKind::Ellipsis => Some(Category::Shortcut), - NodeKind::Escape(_) => Some(Category::Escape), + NodeKind::Label(_) => Some(Category::Label), + NodeKind::Ref(_) => Some(Category::Ref), NodeKind::Not => Some(Category::Keyword), NodeKind::And => Some(Category::Keyword), NodeKind::Or => Some(Category::Keyword), @@ -344,14 +350,16 @@ impl Category { Self::Bracket => "punctuation.definition.typst", Self::Punctuation => "punctuation.typst", Self::Comment => "comment.typst", + Self::Shortcut => "punctuation.shortcut.typst", + Self::Escape => "constant.character.escape.content.typst", Self::Strong => "markup.bold.typst", Self::Emph => "markup.italic.typst", Self::Raw => "markup.raw.typst", Self::Math => "string.other.math.typst", Self::Heading => "markup.heading.typst", Self::List => "markup.list.typst", - Self::Shortcut => "punctuation.shortcut.typst", - Self::Escape => "constant.character.escape.content.typst", + Self::Label => "entity.name.label.typst", + Self::Ref => "markup.other.reference.typst", Self::Keyword => "keyword.typst", Self::Operator => "keyword.operator.typst", Self::None => "constant.language.none.typst", diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs index 4bae7a4b..eb070a04 100644 --- a/src/syntax/mod.rs +++ b/src/syntax/mod.rs @@ -723,6 +723,10 @@ pub enum NodeKind { /// /// Can also exist without the number: `.`. EnumNumbering(Option<usize>), + /// A label: `<label>`. + Label(EcoString), + /// A reference: `@label`. + Ref(EcoString), /// An identifier: `center`. Ident(EcoString), /// A boolean: `true`, `false`. @@ -935,6 +939,8 @@ impl NodeKind { Self::Heading => "heading", Self::Enum => "enumeration item", Self::EnumNumbering(_) => "enumeration item numbering", + Self::Label(_) => "label", + Self::Ref(_) => "reference", Self::Ident(_) => "identifier", Self::Bool(_) => "boolean", Self::Int(_) => "integer", @@ -1060,6 +1066,8 @@ impl Hash for NodeKind { Self::Heading => {} Self::Enum => {} Self::EnumNumbering(num) => num.hash(state), + Self::Label(c) => c.hash(state), + Self::Ref(c) => c.hash(state), Self::Ident(v) => v.hash(state), Self::Bool(v) => v.hash(state), Self::Int(v) => v.hash(state), |
