aboutsummaryrefslogtreecommitdiff
path: root/src/ast/parser.rs
diff options
context:
space:
mode:
authorCody <cody@codyq.dev>2023-02-27 12:29:02 -0600
committerCody <cody@codyq.dev>2023-02-27 12:29:02 -0600
commit0c5616a91d7280341dc6aa522daf04d151108d4e (patch)
tree66764fc099073092c0359ddf0d18c12a1f824cd9 /src/ast/parser.rs
parente4199d2837d2179f17e97b8d50366d96c8babded (diff)
downloadsloth-0c5616a91d7280341dc6aa522daf04d151108d4e.tar.gz
Cleaned up some code
Diffstat (limited to 'src/ast/parser.rs')
-rw-r--r--src/ast/parser.rs25
1 files changed, 2 insertions, 23 deletions
diff --git a/src/ast/parser.rs b/src/ast/parser.rs
index bc29f94..85be68c 100644
--- a/src/ast/parser.rs
+++ b/src/ast/parser.rs
@@ -1,5 +1,5 @@
use super::{Expr, Stmt};
-use crate::lexer::{Literal, Token, TokenType};
+use crate::lexer::{Token, TokenType};
pub struct AstParser<'a> {
tokens: Vec<Token<'a>>,
@@ -11,19 +11,10 @@ impl<'a> AstParser<'a> {
pub fn new(tokens: Vec<Token<'a>>) -> Self {
Self { tokens, index: 0 }
}
-
- fn previous(&self) -> Option<&Token> {
- self.tokens.get(self.index - 1)
- }
-
fn peek(&self) -> &Token {
&self.tokens[self.index]
}
- fn peek_nth(&self, nth: usize) -> Option<&Token> {
- self.tokens.get(self.index + nth)
- }
-
fn advance(&mut self) -> Option<&Token> {
if self.eof() {
return None;
@@ -50,16 +41,6 @@ impl<'a> AstParser<'a> {
self.advance_if(|it| it.tt == *next)
}
- fn advance_seq(&mut self, seq: &[TokenType]) -> bool {
- for token in seq {
- if !self.advance_if_eq(token) {
- return false;
- }
- }
-
- true
- }
-
fn consume(&mut self, next: TokenType, error: &str) {
if std::mem::discriminant(&self.peek().tt) != std::mem::discriminant(&next) {
panic!("{error}");
@@ -309,6 +290,7 @@ macro_rules! binary_expr {
}
#[rustfmt::skip]
+#[allow(unused_parens)]
impl<'a> AstParser<'a> {
// Binary expressions in order of precedence from lowest to highest.
binary_expr!(logical_or , logical_and , (TokenType::PipePipe));
@@ -385,9 +367,6 @@ mod tests {
#[test]
fn basic_expression_c() {
- let lexer = Lexer::new("9 > 6 && 5 + 7 == 32 || \"apple\" != \"banana\"");
- let tokens = lexer.collect_vec();
-
// TODO:
}
}