-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(parser): new kind of ast node
Item
closes #84
- Loading branch information
1 parent
3821fc3
commit b7be439
Showing
13 changed files
with
333 additions
and
260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use super::{Block, Expr}; | ||
use crate::types::Type; | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub enum Item { | ||
Variable(ItemVariable), | ||
Struct(ItemStruct), | ||
Fn(ItemFn), | ||
ForeignFn(ItemForeignFn), | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct ItemVariable { | ||
pub type_: Type, | ||
pub name: String, | ||
pub value: Option<Expr>, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct ItemStruct { | ||
pub name: String, | ||
pub fields: Vec<(String, Type)>, | ||
pub methods: Vec<Method>, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub enum MethodKind { | ||
Static, | ||
Instance, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct Method { | ||
pub kind: MethodKind, | ||
pub signature: Signature, | ||
pub block: Block, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct Signature { | ||
pub name: String, | ||
pub params: Vec<(String, Type)>, | ||
pub return_type: Type, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct ItemFn { | ||
pub signature: Signature, | ||
pub block: Block, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct ItemForeignFn(pub Signature); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
mod error; | ||
pub mod expr; | ||
mod item; | ||
mod op; | ||
mod parser; | ||
mod precedence; | ||
mod stmt; | ||
|
||
pub mod expr; | ||
|
||
pub use error::ParserError; | ||
pub use expr::*; | ||
pub use item::{Item, ItemFn, ItemForeignFn, ItemStruct, ItemVariable, Signature}; | ||
pub use op::{BinOp, BitwiseOp, CmpOp, OpParseError, UnOp}; | ||
pub use parser::Parser; | ||
pub use precedence::Precedence; | ||
pub use stmt::{Block, Stmt, StmtFor, StmtFunction, StmtIf, StmtReturn, StmtVarDecl, StmtWhile}; | ||
pub use stmt::{Stmt, StmtFor, StmtIf, StmtReturn, StmtWhile}; | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct Block(pub Vec<Stmt>); |
Oops, something went wrong.