diff options
| author | Laurenz <laurmaedje@gmail.com> | 2021-06-11 14:00:06 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2021-06-11 14:00:06 +0200 |
| commit | 4dbd9285c91d59d527f4324df4aaf239ecb007ca (patch) | |
| tree | 561a9a18a1eea6a2e598157f305667c4ea8e3e08 /src/syntax | |
| parent | 3330767c20e14a05176902a93dcefb08cb509173 (diff) | |
Basic enums
Diffstat (limited to 'src/syntax')
| -rw-r--r-- | src/syntax/node.rs | 21 | ||||
| -rw-r--r-- | src/syntax/token.rs | 5 | ||||
| -rw-r--r-- | src/syntax/visit.rs | 7 |
3 files changed, 28 insertions, 5 deletions
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<Tree>, } -/// 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<usize>, + /// 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<usize>), /// 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); } |
