introduce TokenHandler

used for saving anything `TokenSerializable` to disk

Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
kernelkind
2025-04-06 17:01:28 -04:00
parent 31b3316d9c
commit 4522920939
3 changed files with 90 additions and 0 deletions

View File

@@ -4,6 +4,12 @@ pub struct UnexpectedToken<'fnd, 'exp> {
pub found: &'fnd str,
}
#[derive(Debug, Clone)]
pub struct UnexpectedTokenOwned {
pub expected: String,
pub found: String,
}
#[derive(Debug, Clone)]
pub enum ParseError<'a> {
/// Not done parsing yet
@@ -24,6 +30,34 @@ pub enum ParseError<'a> {
EOF,
}
#[derive(Debug, Clone)]
pub enum ParseErrorOwned {
Incomplete,
AltAllFailed,
DecodeFailed,
HexDecodeFailed,
UnexpectedToken(UnexpectedTokenOwned),
EOF,
}
impl From<ParseError<'_>> for ParseErrorOwned {
fn from(value: ParseError) -> Self {
match value {
ParseError::Incomplete => Self::Incomplete,
ParseError::AltAllFailed => Self::AltAllFailed,
ParseError::DecodeFailed => Self::DecodeFailed,
ParseError::HexDecodeFailed => Self::HexDecodeFailed,
ParseError::UnexpectedToken(unexpected_token) => {
Self::UnexpectedToken(UnexpectedTokenOwned {
expected: unexpected_token.expected.to_owned(),
found: unexpected_token.found.to_owned(),
})
}
ParseError::EOF => Self::EOF,
}
}
}
pub struct TokenWriter {
delim: &'static str,
tokens_written: usize,