From 5c952d56d0d602a1dbcf85210ae30fa402219fca Mon Sep 17 00:00:00 2001 From: Martin Haug Date: Thu, 4 Nov 2021 19:36:32 +0100 Subject: New error handling --- src/syntax/ast.rs | 12 +++--------- src/syntax/mod.rs | 7 ++----- 2 files changed, 5 insertions(+), 14 deletions(-) (limited to 'src/syntax') diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index 9ad04be5..b6f64c67 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -156,13 +156,7 @@ impl HeadingNode { /// The section depth (numer of equals signs). pub fn level(&self) -> u8 { - self.0 - .children() - .find_map(|node| match node.kind() { - NodeKind::HeadingLevel(heading) => Some(*heading), - _ => None, - }) - .expect("heading node is missing heading level") + self.0.children().filter(|n| n.kind() == &NodeKind::Eq).count() as u8 } } @@ -743,7 +737,7 @@ impl TypedNode for CallArg { NodeKind::Named => Some(CallArg::Named( node.cast().expect("named call argument is missing name"), )), - NodeKind::ParameterSink => Some(CallArg::Spread( + NodeKind::Spread => Some(CallArg::Spread( node.cast_first_child() .expect("call argument sink is missing expression"), )), @@ -825,7 +819,7 @@ impl TypedNode for ClosureParam { NodeKind::Named => Some(ClosureParam::Named( node.cast().expect("named closure parameter is missing name"), )), - NodeKind::ParameterSink => Some(ClosureParam::Sink( + NodeKind::Spread => Some(ClosureParam::Sink( node.cast_first_child() .expect("closure parameter sink is missing identifier"), )), diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs index 112fc220..db3b0c9a 100644 --- a/src/syntax/mod.rs +++ b/src/syntax/mod.rs @@ -487,8 +487,6 @@ pub enum NodeKind { Emph, /// A section heading: `= Introduction`. Heading, - /// A heading's level: `=`, `==`, `===`, etc. - HeadingLevel(u8), /// An item in an enumeration (ordered list): `1. ...`. Enum, /// A numbering: `23.`. @@ -546,7 +544,7 @@ pub enum NodeKind { /// A closure's parameters: `(x, y)`. ClosureParams, /// A parameter sink: `..x`. - ParameterSink, + Spread, /// A template expression: `[*Hi* there!]`. Template, /// A block expression: `{ let x = 1; x + 2 }`. @@ -709,7 +707,6 @@ impl NodeKind { Self::Strong => "strong", Self::Emph => "emphasis", Self::Heading => "heading", - Self::HeadingLevel(_) => "heading level", Self::Enum => "enumeration item", Self::EnumNumbering(_) => "enumeration item numbering", Self::List => "list item", @@ -735,7 +732,7 @@ impl NodeKind { Self::CallArgs => "call arguments", Self::Closure => "closure", Self::ClosureParams => "closure parameters", - Self::ParameterSink => "parameter sink", + Self::Spread => "parameter sink", Self::Template => "template", Self::Block => "block", Self::ForExpr => "for-loop expression", -- cgit v1.2.3