Created
September 22, 2020 18:59
-
-
Save Zemnmez/2dcb9277d146d02b63133e8336a0a6a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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