From ccdc02bbd0d185dd2beb1d227d6ca1815a157530 Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 14 Jun 2019 01:30:53 -0700 Subject: [PATCH] Peek multiple tokens ahead --- schala-lang/language/src/parsing.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/schala-lang/language/src/parsing.rs b/schala-lang/language/src/parsing.rs index 74c773f..4841041 100644 --- a/schala-lang/language/src/parsing.rs +++ b/schala-lang/language/src/parsing.rs @@ -205,9 +205,16 @@ impl TokenHandler { fn peek_kind(&mut self) -> TokenKind { self.peek().kind } + + fn peek_kind_n(&mut self, n: usize) -> TokenKind { + self.peek_n(n).kind + } fn peek(&mut self) -> Token { self.tokens.get(self.idx).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}) } + fn peek_n(&mut self, n: usize) -> Token { + self.tokens.get(self.idx + n).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}) + } fn next(&mut self) -> Token { self.idx += 1; self.tokens.get(self.idx - 1).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})