Skip to content

Instantly share code, notes, and snippets.

@Zemnmez
Created September 22, 2020 18:59
Show Gist options
  • Select an option

  • Save Zemnmez/2dcb9277d146d02b63133e8336a0a6a4 to your computer and use it in GitHub Desktop.

Select an option

Save Zemnmez/2dcb9277d146d02b63133e8336a0a6a4 to your computer and use it in GitHub Desktop.
struct TokenizationStep(fn(
runes: dyn Iterator<Item=io::Result<String>>,
stack: dyn Iterator<Item=TokenizationStep>) -> io::Result<Box<dyn Iterator<Item=Box<dyn Token>>>>);
fn parseFile(runes: impl Iterator<Item=io::Result<String>>, stack: Box<dyn Iterator<Item=TokenizationStep>>) -> io::Result<Box<impl Iterator<Item=Box<impl Token>>>> {
return parseText(runes, stack)
}
struct Text(String);
fn parseText(runes: impl Iterator<Item=io::Result<String>>, stack: Box<dyn Iterator<Item=TokenizationStep>>) -> io::Result<Box<impl Iterator<Item=Box<impl Token>>>> {
let mut text: Vec<String> = Vec::new();
for rune in runes {
match rune {
Ok(v) => match v {
'[' => match text.len() {
0 => text.return parseTag([v].iter().chain(runes), [parseFile].iter().chain(stack)),
_ => [Text(text)].chain(text.return parseTag([v].iter().chain(runes), [parseFile].iter().chain(stack))
_ => text.push(v)
},
Err(e) => e
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment