From 4fd031a256b2ecfe524859d5599fafb386395572 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Mon, 17 Oct 2022 16:47:07 +0200 Subject: More spans in AST --- src/syntax/ast.rs | 823 +++++++++++++++++++++++++++++------------------- src/syntax/highlight.rs | 114 ++++--- src/syntax/kind.rs | 335 ++++++++++---------- 3 files changed, 727 insertions(+), 545 deletions(-) (limited to 'src/syntax') diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index aa590da2..ecfa9a5b 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -5,8 +5,7 @@ use std::num::NonZeroUsize; use std::ops::Deref; -use super::{NodeData, NodeKind, Span, SyntaxNode}; -use crate::geom::{AngleUnit, LengthUnit}; +use super::{NodeData, NodeKind, RawKind, Span, SyntaxNode, Unit}; use crate::util::EcoString; /// A typed AST node. @@ -25,10 +24,7 @@ pub trait TypedNode: Sized { macro_rules! node { ($(#[$attr:meta])* $name:ident) => { - node!{$(#[$attr])* $name: $name} - }; - ($(#[$attr:meta])* $name:ident: $variant:ident) => { - node!{$(#[$attr])* $name: NodeKind::$variant} + node!{ $(#[$attr])* $name: NodeKind::$name { .. } } }; ($(#[$attr:meta])* $name:ident: $variants:pat) => { #[derive(Debug, Clone, PartialEq, Hash)] @@ -54,254 +50,296 @@ macro_rules! node { node! { /// The syntactical root capable of representing a full parsed document. - MarkupNode: NodeKind::Markup { .. } + Markup } -impl MarkupNode { +impl Markup { /// The children. - pub fn items(&self) -> impl Iterator + '_ { + pub fn children(&self) -> impl Iterator + '_ { self.0.children().filter_map(SyntaxNode::cast) } } /// A single piece of markup. #[derive(Debug, Clone, PartialEq)] -pub enum MarkupItem { +pub enum MarkupNode { /// Whitespace containing less than two newlines. - Space, + Space(Space), /// A forced line break. - Linebreak, - /// A paragraph break: Two or more newlines. - Parbreak, + Linebreak(Linebreak), /// Plain text. - Text(EcoString), + Text(Text), + /// An escape sequence: `\#`, `\u{1F5FA}`. + Escape(Escape), + /// A shorthand for a unicode codepoint. For example, `~` for non-breaking + /// space or `-?` for a soft hyphen. + Shorthand(Shorthand), /// A smart quote: `'` or `"`. - Quote { double: bool }, - /// Strong content: `*Strong*`. - Strong(StrongNode), - /// Emphasized content: `_Emphasized_`. - Emph(EmphNode), - /// A hyperlink: `https://typst.org`. - Link(EcoString), + SmartQuote(SmartQuote), + /// Strong markup: `*Strong*`. + Strong(Strong), + /// Emphasized markup: `_Emphasized_`. + Emph(Emph), /// A raw block with optional syntax highlighting: `` `...` ``. - Raw(RawNode), - /// A math formula: `$x$`, `$ x^2 $`. - Math(MathNode), + Raw(Raw), + /// A hyperlink: `https://typst.org`. + Link(Link), + /// A label: `