Add parser and AST, remove some stuff from lexer

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-04-27 20:17:16 -04:00
parent ce97d90f9d
commit 28d29c2270
8 changed files with 340 additions and 56 deletions

52
src/syn/ast.rs Normal file
View File

@@ -0,0 +1,52 @@
use crate::syn::{op::*, span::*};
pub enum Expr {
Base(BaseExpr),
Bin(Box<BinExpr>),
Un(Box<UnExpr>),
}
impl From<UnExpr> for Expr {
fn from(un: UnExpr) -> Self {
Expr::Un(Box::new(un))
}
}
impl From<BinExpr> for Expr {
fn from(bin: BinExpr) -> Self {
Expr::Bin(Box::new(bin))
}
}
impl From<BaseExpr> for Expr {
fn from(base: BaseExpr) -> Self {
Expr::Base(base)
}
}
pub struct BinExpr {
pub lhs: Expr,
pub op: BinOp,
pub rhs: Expr,
}
pub struct UnExpr {
pub op: UnOp,
pub expr: Expr,
pub span: Span,
}
pub enum BaseExprKind {
Ident,
Num,
Str,
Sym,
List(Vec<Expr>),
Object(Vec<(Expr, Expr)>),
Tuple(Vec<Expr>),
}
pub struct BaseExpr {
pub kind: BaseExprKind,
pub span: Span,
}