mirror of
https://github.com/Noratrieb/dilaria.git
synced 2026-01-15 18:05:03 +01:00
lol
This commit is contained in:
parent
3f62892500
commit
930955590d
105 changed files with 22 additions and 3766 deletions
51
src/ast.rs
51
src/ast.rs
|
|
@ -7,8 +7,7 @@ use crate::errors::Span;
|
|||
|
||||
type Symbol = usize;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
|
||||
#[cfg_attr(feature = "_debug", derive(dbg_pls::DebugPls))]
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, dbg_pls::DebugPls)]
|
||||
pub struct Ident {
|
||||
pub sym: Symbol,
|
||||
pub span: Span,
|
||||
|
|
@ -16,15 +15,13 @@ pub struct Ident {
|
|||
|
||||
pub type Program<'ast> = Block<'ast>;
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "_debug", derive(dbg_pls::DebugPls))]
|
||||
#[derive(Debug, PartialEq, dbg_pls::DebugPls)]
|
||||
pub struct Block<'ast> {
|
||||
pub stmts: &'ast [Stmt<'ast>],
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "_debug", derive(dbg_pls::DebugPls))]
|
||||
#[derive(Debug, PartialEq, dbg_pls::DebugPls)]
|
||||
pub enum Stmt<'ast> {
|
||||
Declaration(Declaration<'ast>),
|
||||
Assignment(Assignment<'ast>),
|
||||
|
|
@ -39,24 +36,21 @@ pub enum Stmt<'ast> {
|
|||
Print(Expr<'ast>, Span),
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "_debug", derive(dbg_pls::DebugPls))]
|
||||
#[derive(Debug, PartialEq, dbg_pls::DebugPls)]
|
||||
pub struct Declaration<'ast> {
|
||||
pub span: Span,
|
||||
pub name: Ident,
|
||||
pub init: Expr<'ast>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "_debug", derive(dbg_pls::DebugPls))]
|
||||
#[derive(Debug, PartialEq, dbg_pls::DebugPls)]
|
||||
pub struct Assignment<'ast> {
|
||||
pub span: Span,
|
||||
pub lhs: Expr<'ast>,
|
||||
pub rhs: Expr<'ast>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "_debug", derive(dbg_pls::DebugPls))]
|
||||
#[derive(Debug, PartialEq, dbg_pls::DebugPls)]
|
||||
pub struct FnDecl<'ast> {
|
||||
pub span: Span,
|
||||
pub name: Ident,
|
||||
|
|
@ -64,8 +58,7 @@ pub struct FnDecl<'ast> {
|
|||
pub body: Block<'ast>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "_debug", derive(dbg_pls::DebugPls))]
|
||||
#[derive(Debug, PartialEq, dbg_pls::DebugPls)]
|
||||
pub struct IfStmt<'ast> {
|
||||
pub span: Span,
|
||||
pub cond: Expr<'ast>,
|
||||
|
|
@ -73,8 +66,7 @@ pub struct IfStmt<'ast> {
|
|||
pub else_part: Option<&'ast ElsePart<'ast>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "_debug", derive(dbg_pls::DebugPls))]
|
||||
#[derive(Debug, PartialEq, dbg_pls::DebugPls)]
|
||||
pub enum ElsePart<'ast> {
|
||||
Else(Block<'ast>, Span),
|
||||
ElseIf(IfStmt<'ast>, Span),
|
||||
|
|
@ -88,16 +80,14 @@ impl ElsePart<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "_debug", derive(dbg_pls::DebugPls))]
|
||||
#[derive(Debug, PartialEq, dbg_pls::DebugPls)]
|
||||
pub struct WhileStmt<'ast> {
|
||||
pub span: Span,
|
||||
pub cond: Expr<'ast>,
|
||||
pub body: Block<'ast>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "_debug", derive(dbg_pls::DebugPls))]
|
||||
#[derive(Debug, PartialEq, dbg_pls::DebugPls)]
|
||||
pub enum Expr<'ast> {
|
||||
Ident(Ident),
|
||||
Literal(Literal<'ast>),
|
||||
|
|
@ -118,8 +108,7 @@ impl Expr<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "_debug", derive(dbg_pls::DebugPls))]
|
||||
#[derive(Debug, PartialEq, dbg_pls::DebugPls)]
|
||||
pub enum Literal<'ast> {
|
||||
String(Symbol, Span),
|
||||
Number(f64, Span),
|
||||
|
|
@ -142,23 +131,20 @@ impl Literal<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "_debug", derive(dbg_pls::DebugPls))]
|
||||
#[derive(Debug, PartialEq, dbg_pls::DebugPls)]
|
||||
pub struct UnaryOp<'ast> {
|
||||
pub span: Span,
|
||||
pub expr: Expr<'ast>,
|
||||
pub kind: UnaryOpKind,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "_debug", derive(dbg_pls::DebugPls))]
|
||||
#[derive(Debug, PartialEq, dbg_pls::DebugPls)]
|
||||
pub enum UnaryOpKind {
|
||||
Not,
|
||||
Neg,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "_debug", derive(dbg_pls::DebugPls))]
|
||||
#[derive(Debug, PartialEq, dbg_pls::DebugPls)]
|
||||
pub struct BinaryOp<'ast> {
|
||||
pub span: Span,
|
||||
pub lhs: Expr<'ast>,
|
||||
|
|
@ -166,8 +152,7 @@ pub struct BinaryOp<'ast> {
|
|||
pub kind: BinaryOpKind,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "_debug", derive(dbg_pls::DebugPls))]
|
||||
#[derive(Debug, PartialEq, dbg_pls::DebugPls)]
|
||||
pub enum BinaryOpKind {
|
||||
And,
|
||||
Or,
|
||||
|
|
@ -184,16 +169,14 @@ pub enum BinaryOpKind {
|
|||
Mod,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "_debug", derive(dbg_pls::DebugPls))]
|
||||
#[derive(Debug, PartialEq, dbg_pls::DebugPls)]
|
||||
pub struct Call<'ast> {
|
||||
pub callee: Expr<'ast>,
|
||||
pub span: Span,
|
||||
pub kind: CallKind<'ast>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[cfg_attr(feature = "_debug", derive(dbg_pls::DebugPls))]
|
||||
#[derive(Debug, PartialEq, dbg_pls::DebugPls)]
|
||||
pub enum CallKind<'ast> {
|
||||
Field(Ident),
|
||||
Fn(&'ast [Expr<'ast>]),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue