remove warnings
This commit is contained in:
+3
-20
@@ -5,6 +5,7 @@ pub trait NodeTrait {
|
|||||||
fn string(&self) -> String;
|
fn string(&self) -> String;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
pub trait StatementTrait: NodeTrait {
|
pub trait StatementTrait: NodeTrait {
|
||||||
fn statement_node(&self);
|
fn statement_node(&self);
|
||||||
}
|
}
|
||||||
@@ -15,7 +16,6 @@ pub enum Expression {
|
|||||||
PrefixExpression(PrefixExpression),
|
PrefixExpression(PrefixExpression),
|
||||||
InfixExpression(InfixExpression),
|
InfixExpression(InfixExpression),
|
||||||
Boolean(Boolean),
|
Boolean(Boolean),
|
||||||
BlockStatement(BlockStatement),
|
|
||||||
IfExpression(IfExpression),
|
IfExpression(IfExpression),
|
||||||
FunctionLiteral(FunctionLiteral),
|
FunctionLiteral(FunctionLiteral),
|
||||||
CallExpression(CallExpression),
|
CallExpression(CallExpression),
|
||||||
@@ -29,7 +29,6 @@ impl NodeTrait for Expression {
|
|||||||
Expression::PrefixExpression(i) => i.token_literal(),
|
Expression::PrefixExpression(i) => i.token_literal(),
|
||||||
Expression::InfixExpression(i) => i.token_literal(),
|
Expression::InfixExpression(i) => i.token_literal(),
|
||||||
Expression::Boolean(i) => i.token_literal(),
|
Expression::Boolean(i) => i.token_literal(),
|
||||||
Expression::BlockStatement(i) => i.token_literal(),
|
|
||||||
Expression::IfExpression(i) => i.token_literal(),
|
Expression::IfExpression(i) => i.token_literal(),
|
||||||
Expression::FunctionLiteral(i) => i.token_literal(),
|
Expression::FunctionLiteral(i) => i.token_literal(),
|
||||||
Expression::CallExpression(i) => i.token_literal(),
|
Expression::CallExpression(i) => i.token_literal(),
|
||||||
@@ -43,7 +42,6 @@ impl NodeTrait for Expression {
|
|||||||
Expression::PrefixExpression(i) => i.string(),
|
Expression::PrefixExpression(i) => i.string(),
|
||||||
Expression::InfixExpression(i) => i.string(),
|
Expression::InfixExpression(i) => i.string(),
|
||||||
Expression::Boolean(i) => i.string(),
|
Expression::Boolean(i) => i.string(),
|
||||||
Expression::BlockStatement(i) => i.string(),
|
|
||||||
Expression::IfExpression(i) => i.string(),
|
Expression::IfExpression(i) => i.string(),
|
||||||
Expression::FunctionLiteral(i) => i.string(),
|
Expression::FunctionLiteral(i) => i.string(),
|
||||||
Expression::CallExpression(i) => i.string(),
|
Expression::CallExpression(i) => i.string(),
|
||||||
@@ -51,21 +49,6 @@ impl NodeTrait for Expression {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Statement;
|
|
||||||
impl NodeTrait for Statement {
|
|
||||||
fn token_literal(&self) -> String {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn string(&self) -> String {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl StatementTrait for Statement {
|
|
||||||
fn statement_node(&self) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Program {
|
pub struct Program {
|
||||||
pub statements: Vec<Box<dyn StatementTrait>>,
|
pub statements: Vec<Box<dyn StatementTrait>>,
|
||||||
}
|
}
|
||||||
@@ -186,7 +169,7 @@ impl NodeTrait for IntegerLiteral {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn string(&self) -> String {
|
fn string(&self) -> String {
|
||||||
self.token.literal.clone()
|
self.value.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,7 +228,7 @@ impl NodeTrait for Boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn string(&self) -> String {
|
fn string(&self) -> String {
|
||||||
self.token.literal.clone()
|
self.value.to_string()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+20
-26
@@ -47,46 +47,40 @@ impl LexerTraits for Lexer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn next_token(&mut self) -> Token {
|
fn next_token(&mut self) -> Token {
|
||||||
let mut tok = Token {
|
|
||||||
type_: TokenType::Illegal,
|
|
||||||
literal: String::new(),
|
|
||||||
};
|
|
||||||
self.skip_whitespace();
|
self.skip_whitespace();
|
||||||
let lit = self.ch.unwrap();
|
let lit = self.ch.unwrap();
|
||||||
let c = char::from(lit);
|
let c = char::from(lit);
|
||||||
|
|
||||||
match c {
|
let tok = match c {
|
||||||
'\0' => tok = new_token(TokenType::Eof, lit),
|
'\0' => new_token(TokenType::Eof, lit),
|
||||||
'=' => {
|
'=' => {
|
||||||
if char::from(self.peek_char()) == '=' {
|
if char::from(self.peek_char()) == '=' {
|
||||||
self.read_char();
|
self.read_char();
|
||||||
let lit = String::from("==");
|
new_token_from_str(TokenType::Eq, String::from("=="))
|
||||||
tok = new_token_from_str(TokenType::Eq, lit);
|
|
||||||
} else {
|
} else {
|
||||||
tok = new_token(TokenType::Assign, lit);
|
new_token(TokenType::Assign, lit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
';' => tok = new_token(TokenType::Semicolon, lit),
|
';' => new_token(TokenType::Semicolon, lit),
|
||||||
'(' => tok = new_token(TokenType::Lparen, lit),
|
'(' => new_token(TokenType::Lparen, lit),
|
||||||
')' => tok = new_token(TokenType::Rparen, lit),
|
')' => new_token(TokenType::Rparen, lit),
|
||||||
',' => tok = new_token(TokenType::Comma, lit),
|
',' => new_token(TokenType::Comma, lit),
|
||||||
'+' => tok = new_token(TokenType::Plus, lit),
|
'+' => new_token(TokenType::Plus, lit),
|
||||||
'-' => tok = new_token(TokenType::Minus, lit),
|
'-' => new_token(TokenType::Minus, lit),
|
||||||
'!' => {
|
'!' => {
|
||||||
if char::from(self.peek_char()) == '=' {
|
if char::from(self.peek_char()) == '=' {
|
||||||
self.read_char();
|
self.read_char();
|
||||||
let lit = String::from("!=");
|
new_token_from_str(TokenType::Neq, String::from("!="))
|
||||||
tok = new_token_from_str(TokenType::Neq, lit);
|
|
||||||
} else {
|
} else {
|
||||||
tok = new_token(TokenType::Bang, lit);
|
new_token(TokenType::Bang, lit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'/' => tok = new_token(TokenType::Slash, lit),
|
'/' => new_token(TokenType::Slash, lit),
|
||||||
'*' => tok = new_token(TokenType::Asterisk, lit),
|
'*' => new_token(TokenType::Asterisk, lit),
|
||||||
'<' => tok = new_token(TokenType::Lt, lit),
|
'<' => new_token(TokenType::Lt, lit),
|
||||||
'>' => tok = new_token(TokenType::Gt, lit),
|
'>' => new_token(TokenType::Gt, lit),
|
||||||
'{' => tok = new_token(TokenType::Lbrace, lit),
|
'{' => new_token(TokenType::Lbrace, lit),
|
||||||
'}' => tok = new_token(TokenType::Rbrace, lit),
|
'}' => new_token(TokenType::Rbrace, lit),
|
||||||
_ => {
|
_ => {
|
||||||
if c.is_alphabetic() {
|
if c.is_alphabetic() {
|
||||||
let lit = self.read_identifier();
|
let lit = self.read_identifier();
|
||||||
@@ -96,10 +90,10 @@ impl LexerTraits for Lexer {
|
|||||||
let lit = self.read_number();
|
let lit = self.read_number();
|
||||||
return new_token_from_str(TokenType::Int, lit);
|
return new_token_from_str(TokenType::Int, lit);
|
||||||
} else {
|
} else {
|
||||||
tok = new_token(TokenType::Illegal, lit);
|
new_token(TokenType::Illegal, lit)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
self.read_char();
|
self.read_char();
|
||||||
tok
|
tok
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user