parser
This commit is contained in:
+46
-1
@@ -1,3 +1,5 @@
|
||||
use crate::token;
|
||||
|
||||
trait NodeTrait {
|
||||
fn token_literal(&self) -> String;
|
||||
}
|
||||
@@ -9,6 +11,14 @@ trait StatementTrait: NodeTrait {
|
||||
trait ExpressionTrait: NodeTrait {
|
||||
fn expression_node(&self);
|
||||
}
|
||||
struct Expression {
|
||||
//
|
||||
}
|
||||
impl NodeTrait for Expression {
|
||||
fn token_literal(&self) -> String {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
struct Statement {
|
||||
//
|
||||
@@ -23,7 +33,7 @@ impl StatementTrait for Statement {
|
||||
fn statement_node(&self) {}
|
||||
}
|
||||
|
||||
struct Program {
|
||||
pub struct Program {
|
||||
statements: Vec<Statement>,
|
||||
}
|
||||
|
||||
@@ -36,3 +46,38 @@ impl NodeTrait for Program {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct LetStatement {
|
||||
token: token::Token,
|
||||
name: Identifier,
|
||||
value: Expression,
|
||||
}
|
||||
|
||||
impl NodeTrait for LetStatement {
|
||||
fn token_literal(&self) -> String {
|
||||
String::from(&self.token.literal)
|
||||
}
|
||||
}
|
||||
|
||||
impl StatementTrait for LetStatement {
|
||||
fn statement_node(&self) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
struct Identifier {
|
||||
token: token::Token,
|
||||
value: String,
|
||||
}
|
||||
|
||||
impl NodeTrait for Identifier {
|
||||
fn token_literal(&self) -> String {
|
||||
String::from(&self.token.literal)
|
||||
}
|
||||
}
|
||||
|
||||
impl ExpressionTrait for Identifier {
|
||||
fn expression_node(&self) {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user