Hey there!
For learning purposes, I wanted to make my own data format. It's called huan. What is it? Slightly opinionated yaml. For example:
name: "John"
age: 33
adult: true
address:
house: "Abyss"
postal: 33333
Now, I already built a tokenizer/lexer.
The type looks like:
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum TokenType<'a> {
Identifier(&'a str),
IdentifierSpace,
Str(&'a str),
Int(i64),
NewLine,
WhiteSpace(usize),
Boolean(bool),
}
```I get a `Vec<TokenType>` from the tokenizer. I tested it, it works.
I wanted to plug it into serde, but I have no idea how.
```rs
pub struct Deserializer<'de> {
pub input: &'de [TokenType<'de>],
cursor: usize,
}
impl<'de> Deserializer<'de> {
pub fn new(input: &'de [TokenType<'de>]) -> Self {
Self { input, cursor: 0 }
}
pub fn peek(&self) -> Result<&'de TokenType<'de>> {
self.input.get(self.cursor).ok_or(Error::Eof)
}
pub fn advance(&mut self) -> Result<&'de TokenType<'de>> {
let token = self.peek()?;
self.cursor += 1;
Ok(token)
}
}
impl<'de> de::Deserializer<'de> for &mut Deserializer<'de> {
type Error = Error;
This is what I currently have, but I have no idea how to continue. My biggest question: how does it parse/visit identifiers? I don't get it. I can't get a grip on the documentation, every time I read it I end up with more questions. A little guidance would be highly appreciated.
Thanks in advance