diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index d2eb8da..6cdee72 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -191,6 +191,8 @@ struct ParserRestrictions { struct TokenHandler { tokens: Peekable>, + token_array: Vec, + idx: usize, end_of_file: (usize, usize), } @@ -200,18 +202,22 @@ impl TokenHandler { None => (0, 0), Some(t) => (t.line_num, t.char_num) }; + let token_array = tokens.clone(); let tokens = tokens.into_iter().peekable(); - TokenHandler { tokens, end_of_file } + TokenHandler { idx: 0, token_array, tokens, end_of_file } } fn peek_kind(&mut self) -> TokenKind { - self.tokens.peek().map(|ref t| { t.kind.clone() }).unwrap_or(TokenKind::EOF) + let old = self.tokens.peek().map(|ref t| { t.kind.clone() }).unwrap_or(TokenKind::EOF); + old } fn peek(&mut self) -> Token { - self.tokens.peek().map(|t: &Token| { t.clone()}).unwrap_or(Token { kind: TokenKind::EOF, line_num: self.end_of_file.0, char_num: self.end_of_file.1}) + let old = self.tokens.peek().map(|t: &Token| { t.clone()}).unwrap_or(Token { kind: TokenKind::EOF, line_num: self.end_of_file.0, char_num: self.end_of_file.1}); + old } fn next(&mut self) -> Token { - self.tokens.next().unwrap_or(Token { kind: TokenKind::EOF, line_num: self.end_of_file.0, char_num: self.end_of_file.1}) + let old = self.tokens.next().unwrap_or(Token { kind: TokenKind::EOF, line_num: self.end_of_file.0, char_num: self.end_of_file.1}); + old } }