diff --git a/crates/specctra-core/src/common.rs b/crates/specctra-core/src/common.rs index 3accd60..8538666 100644 --- a/crates/specctra-core/src/common.rs +++ b/crates/specctra-core/src/common.rs @@ -17,30 +17,6 @@ impl ListToken { } } - pub fn expect_any_start(self) -> Result { - if let Self::Start { name } = self { - Ok(name.to_ascii_lowercase()) - } else { - Err(ParseError::ExpectedStartOfList("")) - } - } - - pub fn expect_leaf(self) -> Result { - if let Self::Leaf { value } = self { - Ok(value) - } else { - Err(ParseError::ExpectedLeaf) - } - } - - pub fn expect_end(self) -> Result<(), ParseError> { - if let Self::End = self { - Ok(()) - } else { - Err(ParseError::ExpectedEndOfList) - } - } - pub fn len(&self) -> usize { match &self { Self::Start { name } => 1 + name.len(), diff --git a/crates/specctra-core/src/read.rs b/crates/specctra-core/src/read.rs index b442f60..61138f0 100644 --- a/crates/specctra-core/src/read.rs +++ b/crates/specctra-core/src/read.rs @@ -14,21 +14,27 @@ impl InputToken { } pub fn expect_any_start(self) -> Result { - self.token - .expect_any_start() - .map_err(|err| err.add_context(self.context)) + if let ListToken::Start { name } = self.token { + Ok(name.to_ascii_lowercase()) + } else { + Err(ParseError::ExpectedStartOfList("").add_context(self.context)) + } } pub fn expect_leaf(self) -> Result { - self.token - .expect_leaf() - .map_err(|err| err.add_context(self.context)) + if let ListToken::Leaf { value } = self.token { + Ok(value) + } else { + Err(ParseError::ExpectedLeaf.add_context(self.context)) + } } pub fn expect_end(self) -> Result<(), ParseErrorContext> { - self.token - .expect_end() - .map_err(|err| err.add_context(self.context)) + if let ListToken::End = self.token { + Ok(()) + } else { + Err(ParseError::ExpectedEndOfList.add_context(self.context)) + } } }