From 4dbd9285c91d59d527f4324df4aaf239ecb007ca Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 11 Jun 2021 14:00:06 +0200 Subject: Basic enums --- src/syntax/node.rs | 21 +++++++++++++++++---- src/syntax/token.rs | 5 +++++ src/syntax/visit.rs | 7 ++++++- 3 files changed, 28 insertions(+), 5 deletions(-) (limited to 'src/syntax') diff --git a/src/syntax/node.rs b/src/syntax/node.rs index b4684d0b..a97430b6 100644 --- a/src/syntax/node.rs +++ b/src/syntax/node.rs @@ -21,8 +21,10 @@ pub enum Node { Raw(RawNode), /// A section heading: `= Introduction`. Heading(HeadingNode), - /// A single list item: `- ...`. - List(ListNode), + /// An item in an unordered list: `- ...`. + List(ListItem), + /// An item in an enumeration (ordered list): `1. ...`. + Enum(EnumItem), /// An expression. Expr(Expr), } @@ -115,11 +117,22 @@ pub struct HeadingNode { pub body: Rc, } -/// A single list item: `- ...`. +/// An item in an unordered list: `- ...`. #[derive(Debug, Clone, PartialEq)] -pub struct ListNode { +pub struct ListItem { /// The source code location. pub span: Span, /// The contents of the list item. pub body: Tree, } + +/// An item in an enumeration (ordered list): `1. ...`. +#[derive(Debug, Clone, PartialEq)] +pub struct EnumItem { + /// The source code location. + pub span: Span, + /// The number, if any. + pub number: Option, + /// The contents of the list item. + pub body: Tree, +} diff --git a/src/syntax/token.rs b/src/syntax/token.rs index 2263f806..254a56a2 100644 --- a/src/syntax/token.rs +++ b/src/syntax/token.rs @@ -118,6 +118,10 @@ pub enum Token<'s> { /// One or two dollar signs followed by inner contents, terminated with the /// same number of dollar signs. Math(MathToken<'s>), + /// A numbering: `23.`. + /// + /// Can also exist without the number: `.`. + Numbering(Option), /// An identifier: `center`. Ident(&'s str), /// A boolean: `true`, `false`. @@ -256,6 +260,7 @@ impl<'s> Token<'s> { Self::UnicodeEscape(_) => "unicode escape sequence", Self::Raw(_) => "raw block", Self::Math(_) => "math formula", + Self::Numbering(_) => "numbering", Self::Ident(_) => "identifier", Self::Bool(_) => "boolean", Self::Int(_) => "integer", diff --git a/src/syntax/visit.rs b/src/syntax/visit.rs index 97e8d4ed..a1a848ef 100644 --- a/src/syntax/visit.rs +++ b/src/syntax/visit.rs @@ -59,6 +59,7 @@ visit! { Node::Raw(_) => {} Node::Heading(n) => v.visit_heading(n), Node::List(n) => v.visit_list(n), + Node::Enum(n) => v.visit_enum(n), Node::Expr(n) => v.visit_expr(n), } } @@ -67,7 +68,11 @@ visit! { v.visit_tree(&node.body); } - fn visit_list(v, node: &ListNode) { + fn visit_list(v, node: &ListItem) { + v.visit_tree(&node.body); + } + + fn visit_enum(v, node: &EnumItem) { v.visit_tree(&node.body); } -- cgit v1.2.3