From b3f77076d40c03fe28978c60034542969a365ec0 Mon Sep 17 00:00:00 2001 From: shadow cat Date: Fri, 17 Apr 2026 18:51:12 -0400 Subject: [PATCH] work --- src/io/mod.rs | 16 +++++ src/ir/mod.rs | 4 ++ src/ir/structs/mod.rs | 1 + src/main.rs | 18 +++-- src/parser/cursor/lit.rs | 30 +++++--- src/parser/cursor/mod.rs | 5 +- src/parser/cursor/token.rs | 14 ++-- src/parser/node/ctx.rs | 45 +++++------- src/parser/node/dsp.rs | 15 +--- src/parser/node/mod.rs | 45 +++--------- src/parser/nodes/body.rs | 6 +- src/parser/nodes/expr.rs | 141 ++++++++++++++++++++----------------- src/parser/nodes/func.rs | 30 ++++++-- src/parser/nodes/ident.rs | 15 +++- src/parser/nodes/item.rs | 37 ++++++---- src/parser/nodes/mod.rs | 4 +- src/parser/nodes/param.rs | 4 +- src/parser/nodes/ty.rs | 2 +- test/main.lang | 4 ++ test/other.lang | 0 20 files changed, 244 insertions(+), 192 deletions(-) create mode 100644 src/ir/mod.rs create mode 100644 src/ir/structs/mod.rs create mode 100644 test/other.lang diff --git a/src/io/mod.rs b/src/io/mod.rs index ea80b99..0c161c0 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -90,6 +90,22 @@ impl Span { &text[self.start..=self.end], &text[(self.end + 1)..range.end] )?; + } else if let [(sline, srange), (eline, erange)] = &spans[..] { + writeln!( + w, + " {sline:3} | {}{underline}{underline_color}{}{end}", + &text[srange.start..self.start], + &text[self.start..=srange.end - 1], + )?; + if *eline != *sline + 1 { + writeln!(w, " ...")?; + } + writeln!( + w, + " {eline:3} | {underline}{underline_color}{}{end}{}", + &text[erange.start..=self.end], + &text[(self.end + 1)..=erange.end - 1], + )?; } Ok(()) } diff --git a/src/ir/mod.rs b/src/ir/mod.rs new file mode 100644 index 0000000..eb8118a --- /dev/null +++ b/src/ir/mod.rs @@ -0,0 +1,4 @@ +mod structs; +pub use structs::*; + +pub struct Ir {} diff --git a/src/ir/structs/mod.rs b/src/ir/structs/mod.rs new file mode 100644 index 0000000..29f13b4 --- /dev/null +++ b/src/ir/structs/mod.rs @@ -0,0 +1 @@ +pub struct Module {} diff --git a/src/main.rs b/src/main.rs index b35acf3..622cf50 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,10 @@ -use crate::{io::CompilerOutput, parser::parse_root}; +use crate::{ + io::CompilerOutput, + parser::{Node, parse_root}, +}; mod io; +mod ir; mod parser; fn main() { @@ -10,9 +14,15 @@ fn main() { return; }; let mut output = CompilerOutput::new(); - let nodes = parse_root(&path, &mut output); - if let Some(root) = nodes { - print!("{root}"); + let root = parse_root(&path, &mut output); + if let Some(root) = root { + print!("{}", root.new_dsp()); + // for item in &root.items { + // output.errors.push(io::CompilerMsg { + // spans: vec![item.span], + // msg: format!("hello"), + // }); + // } } output.write(&mut std::io::stdout()); } diff --git a/src/parser/cursor/lit.rs b/src/parser/cursor/lit.rs index ae16f79..1b548b9 100644 --- a/src/parser/cursor/lit.rs +++ b/src/parser/cursor/lit.rs @@ -1,26 +1,38 @@ use super::Token; +use crate::io::Span; + +pub struct Lit { + pub ty: LitTy, + pub span: Span, +} #[derive(PartialEq)] -pub enum Lit { +pub enum LitTy { Number(String), Bool(bool), String(String), Unit, } -impl From for Token { - fn from(value: Lit) -> Self { +impl From for Token { + fn from(value: LitTy) -> Self { Self::Lit(value) } } +impl std::fmt::Display for LitTy { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::Number(n) => write!(f, "{n}"), + Self::Bool(b) => write!(f, "{b}"), + Self::String(s) => write!(f, "\"{s}\""), + Self::Unit => write!(f, "()"), + } + } +} + impl std::fmt::Display for Lit { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Lit::Number(n) => write!(f, "{n}"), - Lit::Bool(b) => write!(f, "{b}"), - Lit::String(s) => write!(f, "\"{s}\""), - Lit::Unit => write!(f, "()"), - } + self.ty.fmt(f) } } diff --git a/src/parser/cursor/mod.rs b/src/parser/cursor/mod.rs index fcdc6ba..cb0c518 100644 --- a/src/parser/cursor/mod.rs +++ b/src/parser/cursor/mod.rs @@ -58,9 +58,10 @@ impl<'a> Cursor<'a> { self.peek().ok_or_else(CompilerMsg::unexpected_eof) } - pub fn expect(&mut self, token: Token) -> Result { + pub fn expect(&mut self, token: impl Borrow) -> Result { + let token = token.borrow(); let next = self.expect_next()?; - if next == token { + if next == *token { Ok(next) } else { self.unexpected(&next, &format!("'{token}'")) diff --git a/src/parser/cursor/token.rs b/src/parser/cursor/token.rs index 127c60b..e450344 100644 --- a/src/parser/cursor/token.rs +++ b/src/parser/cursor/token.rs @@ -1,4 +1,6 @@ -use super::{Lit, Span, Spanned}; +use crate::parser::cursor::LitTy; + +use super::{Span, Spanned}; use std::{iter::Peekable, str::CharIndices}; def_tokens! { @@ -39,7 +41,7 @@ def_tokens! { } other { Ident(String), - Lit(Lit), + Lit(LitTy), } } @@ -128,7 +130,7 @@ impl Iterator for Tokens<'_> { span.end = *i; self.chars.next(); } - Lit::Number(s).into() + LitTy::Number(s).into() } '"' => { let mut s = String::new(); @@ -138,7 +140,7 @@ impl Iterator for Tokens<'_> { s.push(c); span.end = i; } - Lit::String(s).into() + LitTy::String(s).into() } _ => { let mut s = c.to_string(); @@ -150,8 +152,8 @@ impl Iterator for Tokens<'_> { self.chars.next(); } match s.as_str() { - "true" => Lit::Bool(true).into(), - "false" => Lit::Bool(false).into(), + "true" => LitTy::Bool(true).into(), + "false" => LitTy::Bool(false).into(), _ => from_str(s), } } diff --git a/src/parser/node/ctx.rs b/src/parser/node/ctx.rs index e1654fc..2f6f237 100644 --- a/src/parser/node/ctx.rs +++ b/src/parser/node/ctx.rs @@ -1,8 +1,8 @@ use crate::{ io::{CompilerMsg, Span}, parser::{ - Ident, Node, Parsed, - cursor::{Cursor, Lit, Token}, + Ident, Node, + cursor::{Cursor, Lit, LitTy, Token}, }, }; @@ -16,54 +16,45 @@ impl<'a> ParseCtx<'a> { Self { start: 0, cursor } } - pub fn parse_box(&mut self) -> Result>, CompilerMsg> { - self.parse_with(N::parse).map(Parsed::boxed) + pub fn parse_box(&mut self) -> Result, CompilerMsg> { + self.parse_with(N::parse).map(Box::new) } - pub fn parse(&mut self) -> Result, CompilerMsg> { + pub fn parse(&mut self) -> Result { self.parse_with(N::parse) } pub fn parse_with( &mut self, f: impl FnOnce(&mut Self) -> Result, - ) -> Result, CompilerMsg> { + ) -> Result { let old_start = self.start; self.start = self.cursor.peek_start(); - let res = f(self).map(|r| self.push(r)); + let res = f(self).map(|r| r); self.start = old_start; res } - pub fn ident(&mut self, s: String) -> Parsed { + pub fn ident(&mut self, s: String) -> Ident { let span = self.cursor.span; - Parsed::new(Ident(s), span) + Ident { name: s, span } } - pub fn lit(&mut self, lit: Lit) -> Parsed { + pub fn lit(&mut self, ty: LitTy) -> Lit { let span = self.cursor.span; - Parsed::new(lit, span) + Lit { ty, span } } - pub fn push_adv(&mut self, node: N) -> Parsed { - let res = self.push(node); - self.cursor.next(); - res - } - - pub fn push(&mut self, node: N) -> Parsed { + pub fn span(&mut self) -> Span { let end = self.cursor.cur_end(); - Parsed::new( - node, - Span { - file: self.cursor.file(), - start: self.start, - end, - }, - ) + Span { + file: self.cursor.file(), + start: self.start, + end, + } } - pub fn list(&mut self, sep: Token, end: Token) -> Result>, CompilerMsg> { + pub fn list(&mut self, sep: Token, end: Token) -> Result, CompilerMsg> { let mut list = Vec::new(); if self.next_if(&end) { return Ok(list); diff --git a/src/parser/node/dsp.rs b/src/parser/node/dsp.rs index 4648954..149651d 100644 --- a/src/parser/node/dsp.rs +++ b/src/parser/node/dsp.rs @@ -1,4 +1,4 @@ -use crate::parser::{Node, Parsed}; +use crate::parser::Node; #[derive(Clone, Copy)] pub struct DisplayCtx { @@ -17,7 +17,7 @@ impl std::fmt::Display for NodeDsp<'_, N> { } pub struct VecDsp<'a, N> { - list: &'a Vec>, + list: &'a Vec, ctx: DisplayCtx, } @@ -33,22 +33,13 @@ impl std::fmt::Display for VecDsp<'_, N> { } } -impl Parsed { - pub fn dsp(&self, ctx: DisplayCtx) -> NodeDsp<'_, N> - where - N: Node, - { - NodeDsp { node: self, ctx } - } -} - pub trait VecDspT { fn dsp<'a, 'b>(&'a self, ctx: impl Into) -> VecDsp<'b, N> where 'a: 'b; } -impl VecDspT for Vec> { +impl VecDspT for Vec { fn dsp<'a, 'b>(&'a self, ctx: impl Into) -> VecDsp<'b, N> where 'a: 'b, diff --git a/src/parser/node/mod.rs b/src/parser/node/mod.rs index edbfce2..d721606 100644 --- a/src/parser/node/mod.rs +++ b/src/parser/node/mod.rs @@ -1,5 +1,5 @@ use crate::{ - io::{CompilerMsg, CompilerOutput, Span}, + io::{CompilerMsg, CompilerOutput}, parser::{Cursor, nodes::*}, }; @@ -8,17 +8,18 @@ mod dsp; pub use ctx::*; pub use dsp::*; -pub struct Parsed { - pub node: N, - pub span: Span, -} - pub trait Node: Sized { fn parse(ctx: &mut ParseCtx) -> Result; fn fmt(&self, f: &mut std::fmt::Formatter, ctx: DisplayCtx) -> std::fmt::Result; + fn dsp(&self, ctx: DisplayCtx) -> NodeDsp<'_, Self> { + NodeDsp { node: self, ctx } + } + fn new_dsp(&self) -> NodeDsp<'_, Self> { + self.dsp(DisplayCtx { indent: 0 }) + } } -pub fn parse_root(path: &str, output: &mut CompilerOutput) -> Option> { +pub fn parse_root(path: &str, output: &mut CompilerOutput) -> Option { let root_code = match std::fs::read_to_string(path) { Ok(code) => code, Err(err) => { @@ -37,33 +38,3 @@ pub fn parse_root(path: &str, output: &mut CompilerOutput) -> Option Parsed { - pub fn new(node: N, span: Span) -> Self { - Self { node, span } - } - - pub fn boxed(self) -> Box { - Box::new(self) - } -} - -impl std::ops::Deref for Parsed { - type Target = N; - - fn deref(&self) -> &Self::Target { - &self.node - } -} - -impl std::ops::DerefMut for Parsed { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.node - } -} - -impl std::fmt::Display for Parsed { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - self.node.fmt(f, DisplayCtx { indent: 0 }) - } -} diff --git a/src/parser/nodes/body.rs b/src/parser/nodes/body.rs index c395199..2597b38 100644 --- a/src/parser/nodes/body.rs +++ b/src/parser/nodes/body.rs @@ -1,8 +1,9 @@ use super::*; pub struct Body { - pub items: Vec>, + pub items: Vec, pub final_semicolon: bool, + pub span: Span, } impl Node for Body { @@ -15,7 +16,7 @@ impl Node for Body { if at_end(ctx) { break true; } - let item: Parsed = ctx.parse()?; + let item: Item = ctx.parse()?; let needs_semicolon = item.needs_semicolon(); items.push(item); if at_end(ctx) { @@ -29,6 +30,7 @@ impl Node for Body { Ok(Self { items, final_semicolon, + span: ctx.span(), }) } diff --git a/src/parser/nodes/expr.rs b/src/parser/nodes/expr.rs index 3d0d23f..768880b 100644 --- a/src/parser/nodes/expr.rs +++ b/src/parser/nodes/expr.rs @@ -2,57 +2,58 @@ use crate::parser::VecDspT; pub use super::*; -pub type BoxExpr = Box>; +pub struct Expr { + span: Span, + ty: ExprTy, +} -pub enum Expr { - Block(Parsed), - Group(BoxExpr), +pub enum ExprTy { + Block(Body), + Group(Box), Ident(Ident), Lit(Lit), - Negate(BoxExpr), - Call { - target: BoxExpr, - args: Vec>, - }, - Assign { - target: BoxExpr, - val: BoxExpr, - }, - If { - cond: BoxExpr, - body: BoxExpr, - }, - Loop { - body: BoxExpr, - }, - While { - cond: BoxExpr, - body: BoxExpr, - }, - Fn(Box>), + Negate(Box), + Call { target: Box, args: Vec }, + Assign { target: Box, val: Box }, + If { cond: Box, body: Box }, + Loop { body: Box }, + While { cond: Box, body: Box }, + Fn(Box), } impl Node for Expr { fn parse(ctx: &mut ParseCtx) -> Result { let mut res = Self::unit(ctx)?; while let Some(next) = ctx.peek() { - res = match next { + let ty = match next { Token::Equal => { - let target = ctx.push_adv(res).boxed(); - let val = ctx.parse_with(Self::unit)?.boxed(); - Expr::Assign { target, val } + ctx.next(); + let target = Box::new(res); + let val = Box::new(ctx.parse_with(Self::unit)?); + ExprTy::Assign { target, val } } Token::OpenParen => { - let target = ctx.push_adv(res).boxed(); + ctx.next(); + let target = Box::new(res); let args = ctx.list(Token::Comma, Token::CloseParen)?; - Expr::Call { target, args } + ExprTy::Call { target, args } } _ => break, - } + }; + res = Self { + ty, + span: ctx.span(), + }; } Ok(res) } + fn fmt(&self, f: &mut std::fmt::Formatter, ctx: DisplayCtx) -> std::fmt::Result { + self.ty.fmt(f, ctx) + } +} + +impl ExprTy { fn fmt(&self, f: &mut std::fmt::Formatter, mut ctx: DisplayCtx) -> std::fmt::Result { match self { Self::Ident(ident) => ident.fmt(f, ctx), @@ -92,60 +93,77 @@ impl Node for Expr { } impl Expr { + pub fn fmt_body(&self, f: &mut std::fmt::Formatter, ctx: DisplayCtx) -> std::fmt::Result { + match self.ty { + ExprTy::Block(_) => self.fmt(f, ctx), + _ => write!(f, "=> {}", self.dsp(ctx)), + } + } + fn unit(ctx: &mut ParseCtx) -> Result { - Ok(match ctx.expect_next()? { - Token::Dash => Self::Negate(ctx.parse_box()?), - Token::Ident(s) => Self::Ident(Ident(s)), - Token::Lit(l) => Self::Lit(l), - Token::Fn => Self::Fn(ctx.parse_box()?), + let ty = match ctx.expect_next()? { + Token::Dash => ExprTy::Negate(ctx.parse_box()?), + Token::Ident(s) => ExprTy::Ident(ctx.ident(s)), + Token::Lit(l) => ExprTy::Lit(ctx.lit(l)), + Token::Fn => ExprTy::Fn(ctx.parse_box()?), Token::If => { let cond = ctx.parse_box()?; - let body = Self::body(ctx)?.boxed(); - Self::If { cond, body } + let body = Box::new(Self::body(ctx)?); + ExprTy::If { cond, body } } Token::While => { let cond = ctx.parse_box()?; - let body = Self::body(ctx)?.boxed(); - Self::While { cond, body } + let body = Box::new(Self::body(ctx)?); + ExprTy::While { cond, body } } Token::Loop => { let body = ctx.parse_box()?; - Self::Loop { body } + ExprTy::Loop { body } } Token::OpenParen => { if ctx.next_if(Token::CloseParen) { - Self::Lit(Lit::Unit) + ExprTy::Lit(Lit { + ty: LitTy::Unit, + span: ctx.span(), + }) } else { let inner = ctx.parse_box()?; ctx.expect(Token::CloseParen)?; - Self::Group(inner) + ExprTy::Group(inner) } } Token::OpenCurly => { let body = ctx.parse()?; ctx.expect(Token::CloseCurly)?; - Self::Block(body) + ExprTy::Block(body) } other => return ctx.unexpected(&other, "an expression"), + }; + Ok(Self { + ty, + span: ctx.span(), }) } pub fn is_group(&self) -> bool { - matches!(self, Expr::Group(_)) + matches!(self.ty, ExprTy::Group(_)) } pub fn is_block(&self) -> bool { - matches!(self, Expr::Block(_)) + matches!(self.ty, ExprTy::Block(_)) } pub fn block(ctx: &mut ParseCtx) -> Result { ctx.expect(Token::OpenCurly)?; let id = ctx.parse()?; ctx.expect(Token::CloseCurly)?; - Ok(Expr::Block(id)) + Ok(Expr { + ty: ExprTy::Block(id), + span: ctx.span(), + }) } - pub fn body(ctx: &mut ParseCtx) -> Result, CompilerMsg> { + pub fn body(ctx: &mut ParseCtx) -> Result { if ctx.next_if(Token::DoubleArrow) { ctx.parse() } else { @@ -154,24 +172,15 @@ impl Expr { } pub fn ends_with_block(&self) -> bool { - match self { - Expr::Block(..) => true, - Expr::Loop { body } - | Expr::While { body, .. } - | Expr::If { body, .. } - | Expr::Negate(body) - | Expr::Assign { val: body, .. } => body.ends_with_block(), - Expr::Fn(f) => f.ends_with_block(), + match &self.ty { + ExprTy::Block(..) => true, + ExprTy::Loop { body } + | ExprTy::While { body, .. } + | ExprTy::If { body, .. } + | ExprTy::Negate(body) + | ExprTy::Assign { val: body, .. } => body.ends_with_block(), + ExprTy::Fn(f) => f.ends_with_block(), _ => false, } } } - -impl Parsed { - pub fn fmt_body(&self, f: &mut std::fmt::Formatter, ctx: DisplayCtx) -> std::fmt::Result { - match &self.node { - Expr::Block(_) => self.node.fmt(f, ctx), - _ => write!(f, "=> {}", self.dsp(ctx)), - } - } -} diff --git a/src/parser/nodes/func.rs b/src/parser/nodes/func.rs index 41b79ec..589932e 100644 --- a/src/parser/nodes/func.rs +++ b/src/parser/nodes/func.rs @@ -1,13 +1,23 @@ use super::*; pub struct Func { - args: Vec>, - ret: Option>, - body: Parsed, + args: Vec, + name: Option, + ret: Option, + body: Expr, + span: Span, } impl Node for Func { fn parse(ctx: &mut ParseCtx) -> Result { + let mut name = None; + if let Token::Ident(ident) = ctx.expect_peek()? { + // yucky + let ident = ident.to_string(); + ctx.next(); + let ident = ctx.ident(ident); + name = Some(ident); + } ctx.expect(Token::OpenParen)?; let args = ctx.list(Token::Comma, Token::CloseParen)?; let mut ret = None; @@ -15,11 +25,21 @@ impl Node for Func { ret = Some(ctx.parse()?); } let body = Expr::body(ctx)?; - Ok(Self { args, ret, body }) + Ok(Self { + args, + ret, + body, + name, + span: ctx.span(), + }) } fn fmt(&self, f: &mut std::fmt::Formatter, ctx: DisplayCtx) -> std::fmt::Result { - write!(f, "fn(")?; + write!(f, "fn")?; + if let Some(name) = &self.name { + write!(f, " {name}")?; + } + write!(f, "(")?; if let Some((last, rest)) = self.args.split_last() { for arg in rest { write!(f, "{}, ", arg.dsp(ctx))?; diff --git a/src/parser/nodes/ident.rs b/src/parser/nodes/ident.rs index 78ece85..5881fc3 100644 --- a/src/parser/nodes/ident.rs +++ b/src/parser/nodes/ident.rs @@ -1,16 +1,25 @@ use super::*; -pub struct Ident(pub String); +pub struct Ident { + pub name: String, + pub span: Span, +} impl Node for Ident { fn parse(ctx: &mut super::ParseCtx) -> Result { match ctx.expect_next()? { - Token::Ident(ident) => Ok(Self(ident)), + Token::Ident(ident) => Ok(ctx.ident(ident)), t => ctx.unexpected(&t, "an identifier"), } } fn fmt(&self, f: &mut std::fmt::Formatter, _: DisplayCtx) -> std::fmt::Result { - write!(f, "{}", self.0) + write!(f, "{}", self.name) + } +} + +impl std::fmt::Display for Ident { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + self.name.fmt(f) } } diff --git a/src/parser/nodes/item.rs b/src/parser/nodes/item.rs index 1fd2d0b..a2c3165 100644 --- a/src/parser/nodes/item.rs +++ b/src/parser/nodes/item.rs @@ -1,17 +1,22 @@ use super::*; -pub enum Item { +pub struct Item { + pub ty: ItemTy, + pub span: Span, +} + +pub enum ItemTy { Let { - name: Parsed, - ty: Option>, - val: Parsed, + name: Ident, + ty: Option, + val: Expr, }, - Expr(Parsed), + Expr(Expr), } impl Node for Item { fn parse(ctx: &mut ParseCtx) -> Result { - Ok(match ctx.expect_peek()? { + let ty = match ctx.expect_peek()? { Token::Let => { ctx.next(); let name = ctx.parse()?; @@ -21,22 +26,26 @@ impl Node for Item { } ctx.expect(Token::Equal)?; let val = ctx.parse()?; - Self::Let { name, ty, val } + ItemTy::Let { name, ty, val } } - _ => Self::Expr(ctx.parse()?), + _ => ItemTy::Expr(ctx.parse()?), + }; + Ok(Self { + ty, + span: ctx.span(), }) } fn fmt(&self, f: &mut std::fmt::Formatter, ctx: DisplayCtx) -> std::fmt::Result { - match self { - Item::Let { name, ty, val } => { + match &self.ty { + ItemTy::Let { name, ty, val } => { write!(f, "let {}", name.dsp(ctx))?; if let Some(ty) = ty { write!(f, ": {}", ty.dsp(ctx))?; } write!(f, " = {}", val.dsp(ctx))?; } - Item::Expr(id) => id.fmt(f, ctx)?, + ItemTy::Expr(id) => id.fmt(f, ctx)?, } Ok(()) } @@ -44,9 +53,9 @@ impl Node for Item { impl Item { pub fn ends_with_block(&self) -> bool { - match self { - Item::Let { val, .. } => val.ends_with_block(), - Item::Expr(id) => id.ends_with_block(), + match &self.ty { + ItemTy::Let { val, .. } => val.ends_with_block(), + ItemTy::Expr(id) => id.ends_with_block(), } } pub fn needs_semicolon(&self) -> bool { diff --git a/src/parser/nodes/mod.rs b/src/parser/nodes/mod.rs index 278d942..c76c7f5 100644 --- a/src/parser/nodes/mod.rs +++ b/src/parser/nodes/mod.rs @@ -14,5 +14,5 @@ pub use item::*; pub use param::*; pub use ty::*; -use super::{DisplayCtx, Lit, Node, ParseCtx, Parsed, Token}; -use crate::io::CompilerMsg; +use super::{DisplayCtx, Lit, LitTy, Node, ParseCtx, Token}; +use crate::io::{CompilerMsg, Span}; diff --git a/src/parser/nodes/param.rs b/src/parser/nodes/param.rs index 615cfc4..9ee38ad 100644 --- a/src/parser/nodes/param.rs +++ b/src/parser/nodes/param.rs @@ -1,8 +1,8 @@ use super::*; pub struct Param { - name: Parsed, - ty: Option>, + name: Ident, + ty: Option, } impl Node for Param { diff --git a/src/parser/nodes/ty.rs b/src/parser/nodes/ty.rs index 7517669..ea220ab 100644 --- a/src/parser/nodes/ty.rs +++ b/src/parser/nodes/ty.rs @@ -1,7 +1,7 @@ use super::*; pub enum Type { - Ident(Parsed), + Ident(Ident), } impl Node for Type { diff --git a/test/main.lang b/test/main.lang index 5ea17e7..e5b69d5 100644 --- a/test/main.lang +++ b/test/main.lang @@ -7,3 +7,7 @@ while true { let y = true; if y => print("hello"); + +fn thing() { + +} diff --git a/test/other.lang b/test/other.lang new file mode 100644 index 0000000..e69de29