mirror of https://codeberg.org/topola/topola.git
refactor(specctra-core/read): inline expect_* functions from ListToken into InputToken
This commit is contained in:
parent
81c0de1f91
commit
ca012a8c13
|
|
@ -17,30 +17,6 @@ impl ListToken {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn expect_any_start(self) -> Result<String, ParseError> {
|
||||
if let Self::Start { name } = self {
|
||||
Ok(name.to_ascii_lowercase())
|
||||
} else {
|
||||
Err(ParseError::ExpectedStartOfList(""))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_leaf(self) -> Result<String, ParseError> {
|
||||
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(),
|
||||
|
|
|
|||
|
|
@ -14,21 +14,27 @@ impl InputToken {
|
|||
}
|
||||
|
||||
pub fn expect_any_start(self) -> Result<String, ParseErrorContext> {
|
||||
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<String, ParseErrorContext> {
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue