Start creating new TokenHandler infra

on top of old stuff
This commit is contained in:
greg 2019-06-14 07:21:32 +00:00
parent 4c688ce8b2
commit 53ce31ea8c

View File

@ -191,6 +191,8 @@ struct ParserRestrictions {
struct TokenHandler {
tokens: Peekable<IntoIter<Token>>,
token_array: Vec<Token>,
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
}
}