diff options
| author | Martin Haug <mhaug@live.de> | 2021-11-01 13:03:18 +0100 |
|---|---|---|
| committer | Martin Haug <mhaug@live.de> | 2021-11-05 13:44:50 +0100 |
| commit | 49fb3cd4e2a5d6997ad4046d3514f154d8c866dd (patch) | |
| tree | 4fb2a245a4cb84a6ef238ac1bc71786a0996913d /src/syntax/ast.rs | |
| parent | 7d34a548ccd14debe0668e23454e1ced70e485ec (diff) | |
Code Review: Life is Like a Box of Iterators
Diffstat (limited to 'src/syntax/ast.rs')
| -rw-r--r-- | src/syntax/ast.rs | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index bdd0767d..6ca271a9 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -1,8 +1,39 @@ use super::{Ident, NodeKind, RedNode, RedRef, Span, TypedNode}; use crate::geom::{AngularUnit, LengthUnit}; -use crate::node; use crate::util::EcoString; +macro_rules! node { + ($(#[$attr:meta])* $name:ident) => { + node!{$(#[$attr])* $name => $name} + }; + ($(#[$attr:meta])* $variant:ident => $name:ident) => { + #[derive(Debug, Clone, PartialEq)] + #[repr(transparent)] + $(#[$attr])* + pub struct $name(RedNode); + + impl TypedNode for $name { + fn cast_from(node: RedRef) -> Option<Self> { + if node.kind() != &NodeKind::$variant { + return None; + } + + Some(Self(node.own())) + } + } + + impl $name { + pub fn span(&self) -> Span { + self.0.span() + } + + pub fn underlying(&self) -> RedRef { + self.0.as_ref() + } + } + }; +} + node! { /// The syntactical root capable of representing a full parsed document. Markup |
