From 0d12f2ab23177642eef2e6bb9c583cdd0c743b33 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 30 Aug 2022 15:00:18 +0200 Subject: [WIP] Label and reference syntax --- src/syntax/ast.rs | 6 ++++++ src/syntax/highlight.rs | 34 +++++++++++++++++++++------------- src/syntax/mod.rs | 8 ++++++++ 3 files changed, 35 insertions(+), 13 deletions(-) (limited to 'src/syntax') 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), + /// A label: `