Compare commits
2 Commits
32484b3d6a
...
bcc3b29fc5
| Author | SHA1 | Date | |
|---|---|---|---|
| bcc3b29fc5 | |||
| 589fa73d7c |
29
src/ast.rs
29
src/ast.rs
@@ -1,16 +1,7 @@
|
|||||||
/// A very naive AST definition using recursive enums
|
/// A very naive AST definition using recursive enums
|
||||||
/// See the parser for implementation
|
/// See the parser for implementation
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
/// Primitives
|
use std::rc::Rc;
|
||||||
///
|
|
||||||
/// TODO: add arrays and pointers maybe
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum Type {
|
|
||||||
Int,
|
|
||||||
Float,
|
|
||||||
Char,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type Parent = Vec<Entity>;
|
pub type Parent = Vec<Entity>;
|
||||||
|
|
||||||
@@ -54,9 +45,9 @@ pub enum ClassChildren {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Fn {
|
pub struct Fn {
|
||||||
pub name: Rc<str>,
|
pub name: Rc<str>,
|
||||||
pub return_typ: Option<Type>,
|
pub return_typ: Option<Primitive>,
|
||||||
pub params: Vec<Rc<str>>,
|
pub params: Vec<(Rc<str>, Primitive)>,
|
||||||
pub block: Vec<Statement>,
|
pub children: Vec<Statement>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -69,7 +60,7 @@ pub enum Statement {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Let {
|
pub struct Let {
|
||||||
pub name: Rc<str>,
|
pub name: Rc<str>,
|
||||||
pub typ: Type,
|
pub typ: Primitive,
|
||||||
pub expr: Option<Expr>,
|
pub expr: Option<Expr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,3 +77,13 @@ pub enum Expr {
|
|||||||
Break,
|
Break,
|
||||||
Continue,
|
Continue,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Primitives
|
||||||
|
///
|
||||||
|
/// TODO: add arrays and pointers maybe
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Primitive {
|
||||||
|
Int,
|
||||||
|
Float,
|
||||||
|
Char,
|
||||||
|
}
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ pub enum TokenSymbol {
|
|||||||
//misc
|
//misc
|
||||||
Colon,
|
Colon,
|
||||||
Dot,
|
Dot,
|
||||||
|
Comma,
|
||||||
Hash,
|
Hash,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,6 +373,7 @@ impl<'a> Lexer<'a> {
|
|||||||
'~' => Symbol(Tilde),
|
'~' => Symbol(Tilde),
|
||||||
':' => Symbol(Colon),
|
':' => Symbol(Colon),
|
||||||
'.' => Symbol(Dot),
|
'.' => Symbol(Dot),
|
||||||
|
',' => Symbol(Comma),
|
||||||
'#' => Symbol(Hash),
|
'#' => Symbol(Hash),
|
||||||
_ => {
|
_ => {
|
||||||
self.error("Unknown character encountered");
|
self.error("Unknown character encountered");
|
||||||
@@ -388,6 +390,7 @@ impl<'a> Lexer<'a> {
|
|||||||
let token = if let Some(c) = self.peek() {
|
let token = if let Some(c) = self.peek() {
|
||||||
match c {
|
match c {
|
||||||
'\n' => {
|
'\n' => {
|
||||||
|
self.next();
|
||||||
self.line += 1;
|
self.line += 1;
|
||||||
self.new_token(TokenKind::Newline)
|
self.new_token(TokenKind::Newline)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user