From ec884ec1d85f6e1d7868db3e82d572579cc5d345 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 5 Oct 2022 12:49:39 +0200 Subject: Refactor syntax module --- src/syntax/ast.rs | 108 ++++----- src/syntax/highlight.rs | 283 +++++++++++----------- src/syntax/kind.rs | 548 ++++++++++++++++++++++++++++++++++++++++++ src/syntax/mod.rs | 614 +----------------------------------------------- 4 files changed, 745 insertions(+), 808 deletions(-) create mode 100644 src/syntax/kind.rs (limited to 'src/syntax') diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index 6a016e79..aa590da2 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -1,6 +1,6 @@ //! A typed layer over the untyped syntax tree. //! -//! The AST is rooted in the [`Markup`] node. +//! The AST is rooted in the [`MarkupNode`]. use std::num::NonZeroUsize; use std::ops::Deref; @@ -54,19 +54,19 @@ macro_rules! node { node! { /// The syntactical root capable of representing a full parsed document. - Markup: NodeKind::Markup { .. } + MarkupNode: NodeKind::Markup { .. } } -impl Markup { - /// The markup nodes. - pub fn nodes(&self) -> impl Iterator + '_ { +impl MarkupNode { + /// The children. + pub fn items(&self) -> impl Iterator + '_ { self.0.children().filter_map(SyntaxNode::cast) } } /// A single piece of markup. #[derive(Debug, Clone, PartialEq)] -pub enum MarkupNode { +pub enum MarkupItem { /// Whitespace containing less than two newlines. Space, /// A forced line break. @@ -81,34 +81,34 @@ pub enum MarkupNode { Strong(StrongNode), /// Emphasized content: `_Emphasized_`. Emph(EmphNode), - /// A hyperlink. + /// A hyperlink: `https://typst.org`. Link(EcoString), /// A raw block with optional syntax highlighting: `` `...` ``. Raw(RawNode), - /// A math formula: `$a^2 = b^2 + c^2$`. - Math(Math), + /// A math formula: `$x$`, `$ x^2 $`. + Math(MathNode), /// A section heading: `= Introduction`. Heading(HeadingNode), /// An item in an unordered list: `- ...`. - List(ListNode), + List(ListItem), /// An item in an enumeration (ordered list): `+ ...` or `1. ...`. - Enum(EnumNode), - /// An item in a description list: `/ Term: Details. - Desc(DescNode), - /// A label. + Enum(EnumItem), + /// An item in a description list: `/ Term: Details`. + Desc(DescItem), + /// A label: `