Compare commits

...

2 Commits

Author SHA1 Message Date
bcc3b29fc5 ast: rename Type to Primitive
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
2023-07-30 01:51:13 +05:30
589fa73d7c lexer: add comma and fix newline
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
2023-07-30 01:50:43 +05:30
2 changed files with 18 additions and 14 deletions

View File

@@ -1,16 +1,7 @@
/// A very naive AST definition using recursive enums
/// See the parser for implementation
use std::rc::Rc;
/// Primitives
///
/// TODO: add arrays and pointers maybe
#[derive(Debug)]
pub enum Type {
Int,
Float,
Char,
}
use std::rc::Rc;
pub type Parent = Vec<Entity>;
@@ -54,9 +45,9 @@ pub enum ClassChildren {
#[derive(Debug)]
pub struct Fn {
pub name: Rc<str>,
pub return_typ: Option<Type>,
pub params: Vec<Rc<str>>,
pub block: Vec<Statement>,
pub return_typ: Option<Primitive>,
pub params: Vec<(Rc<str>, Primitive)>,
pub children: Vec<Statement>,
}
#[derive(Debug)]
@@ -69,7 +60,7 @@ pub enum Statement {
#[derive(Debug)]
pub struct Let {
pub name: Rc<str>,
pub typ: Type,
pub typ: Primitive,
pub expr: Option<Expr>,
}
@@ -86,3 +77,13 @@ pub enum Expr {
Break,
Continue,
}
/// Primitives
///
/// TODO: add arrays and pointers maybe
#[derive(Debug)]
pub enum Primitive {
Int,
Float,
Char,
}

View File

@@ -64,6 +64,7 @@ pub enum TokenSymbol {
//misc
Colon,
Dot,
Comma,
Hash,
}
@@ -372,6 +373,7 @@ impl<'a> Lexer<'a> {
'~' => Symbol(Tilde),
':' => Symbol(Colon),
'.' => Symbol(Dot),
',' => Symbol(Comma),
'#' => Symbol(Hash),
_ => {
self.error("Unknown character encountered");
@@ -388,6 +390,7 @@ impl<'a> Lexer<'a> {
let token = if let Some(c) = self.peek() {
match c {
'\n' => {
self.next();
self.line += 1;
self.new_token(TokenKind::Newline)
}