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 {
|
pub fn len(&self) -> usize {
|
||||||
match &self {
|
match &self {
|
||||||
Self::Start { name } => 1 + name.len(),
|
Self::Start { name } => 1 + name.len(),
|
||||||
|
|
|
||||||
|
|
@ -14,21 +14,27 @@ impl InputToken {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expect_any_start(self) -> Result<String, ParseErrorContext> {
|
pub fn expect_any_start(self) -> Result<String, ParseErrorContext> {
|
||||||
self.token
|
if let ListToken::Start { name } = self.token {
|
||||||
.expect_any_start()
|
Ok(name.to_ascii_lowercase())
|
||||||
.map_err(|err| err.add_context(self.context))
|
} else {
|
||||||
|
Err(ParseError::ExpectedStartOfList("").add_context(self.context))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expect_leaf(self) -> Result<String, ParseErrorContext> {
|
pub fn expect_leaf(self) -> Result<String, ParseErrorContext> {
|
||||||
self.token
|
if let ListToken::Leaf { value } = self.token {
|
||||||
.expect_leaf()
|
Ok(value)
|
||||||
.map_err(|err| err.add_context(self.context))
|
} else {
|
||||||
|
Err(ParseError::ExpectedLeaf.add_context(self.context))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expect_end(self) -> Result<(), ParseErrorContext> {
|
pub fn expect_end(self) -> Result<(), ParseErrorContext> {
|
||||||
self.token
|
if let ListToken::End = self.token {
|
||||||
.expect_end()
|
Ok(())
|
||||||
.map_err(|err| err.add_context(self.context))
|
} else {
|
||||||
|
Err(ParseError::ExpectedEndOfList.add_context(self.context))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue