Replaced all the *Box with a generic LocBox<T>
This commit is contained in:
parent
b8728b8f8d
commit
d5f02cf1d5
|
@ -1,6 +1,4 @@
|
||||||
use std::fmt::Display;
|
use std::fmt::{Debug, Display};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Ord, Eq)]
|
#[derive(Debug, Clone, PartialEq, PartialOrd, Ord, Eq)]
|
||||||
pub struct Loc {
|
pub struct Loc {
|
||||||
|
@ -9,6 +7,7 @@ pub struct Loc {
|
||||||
col: usize,
|
col: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
impl Loc {
|
impl Loc {
|
||||||
pub fn new(s: impl ToString, line: usize, col: usize) -> Self {
|
pub fn new(s: impl ToString, line: usize, col: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -27,6 +26,28 @@ impl Loc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct LocBox<T: Clone + Debug> {
|
||||||
|
inner: T,
|
||||||
|
loc: Loc
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Clone + Debug> LocBox<T> {
|
||||||
|
pub fn new(loc: &Loc, inner: T) -> Self {
|
||||||
|
Self { loc: loc.clone(), inner }
|
||||||
|
}
|
||||||
|
pub fn inner(&self) -> &T {
|
||||||
|
&self.inner
|
||||||
|
}
|
||||||
|
pub fn inner_mut(&mut self) -> &mut T {
|
||||||
|
&mut self.inner
|
||||||
|
}
|
||||||
|
pub fn loc(&self) -> &Loc {
|
||||||
|
&self.loc
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Display for Loc {
|
impl Display for Loc {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
write!(f, "{}:{}:{}", self.file, self.line, self.col)
|
write!(f, "{}:{}:{}", self.file, self.line, self.col)
|
||||||
|
|
|
@ -1,76 +1,55 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::{common::Loc, tokeniser::tokentype::*};
|
use crate::{common::loc::LocBox, tokeniser::tokentype::*};
|
||||||
|
|
||||||
use super::{typ::{Type, TypeBox}, Ast};
|
use super::{typ::Type, Ast};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct ExprBox {
|
|
||||||
inner: Expr,
|
|
||||||
loc: Loc
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ExprBox {
|
|
||||||
pub fn new(loc: &Loc, expr: Expr) -> Self {
|
|
||||||
Self { loc: loc.clone(), inner: expr }
|
|
||||||
}
|
|
||||||
pub fn inner(&self) -> &Expr {
|
|
||||||
&self.inner
|
|
||||||
}
|
|
||||||
pub fn inner_mut(&mut self) -> &mut Expr {
|
|
||||||
&mut self.inner
|
|
||||||
}
|
|
||||||
pub fn loc(&self) -> &Loc {
|
|
||||||
&self.loc
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Expr {
|
pub enum Expr {
|
||||||
// Comment(Comment),
|
// Comment(Comment),
|
||||||
Group(Box<ExprBox>),
|
Group(Box<LocBox<Expr>>),
|
||||||
UnOp {
|
UnOp {
|
||||||
typ: Punctuation,
|
typ: Punctuation,
|
||||||
right: Box<ExprBox>,
|
right: Box<LocBox<Expr>>,
|
||||||
},
|
},
|
||||||
BinOp {
|
BinOp {
|
||||||
typ: Punctuation,
|
typ: Punctuation,
|
||||||
left: Box<ExprBox>,
|
left: Box<LocBox<Expr>>,
|
||||||
right: Box<ExprBox>,
|
right: Box<LocBox<Expr>>,
|
||||||
},
|
},
|
||||||
Literal(super::literal::Literal),
|
Literal(super::literal::Literal),
|
||||||
ArrayIndex {
|
ArrayIndex {
|
||||||
name: Box<ExprBox>,
|
name: Box<LocBox<Expr>>,
|
||||||
index: Box<ExprBox>,
|
index: Box<LocBox<Expr>>,
|
||||||
},
|
},
|
||||||
Path(Path),
|
Path(Path),
|
||||||
Call {
|
Call {
|
||||||
path: Box<ExprBox>,
|
path: Box<LocBox<Expr>>,
|
||||||
params: CallParams, // ExprBox ~ (, Expr)*
|
params: CallParams, // LocBox<Expr> ~ (, Expr)*
|
||||||
},
|
},
|
||||||
//MethodCall {
|
//MethodCall {
|
||||||
// var_name: Box<ExprBox>,
|
// var_name: Box<LocBox<Expr>>,
|
||||||
// method_name: Ident,
|
// method_name: Ident,
|
||||||
// params: CallParams,
|
// params: CallParams,
|
||||||
//},
|
//},
|
||||||
|
|
||||||
/// the left side only exists on the /.|->/ chain
|
/// the left side only exists on the /.|->/ chain
|
||||||
FieldAccess {
|
FieldAccess {
|
||||||
left: Box<Option<ExprBox>>,
|
left: Box<Option<LocBox<Expr>>>,
|
||||||
right: Box<ExprBox>,
|
right: Box<LocBox<Expr>>,
|
||||||
},
|
},
|
||||||
PtrFieldAccess {
|
PtrFieldAccess {
|
||||||
left: Box<Option<ExprBox>>,
|
left: Box<Option<LocBox<Expr>>>,
|
||||||
right: Box<ExprBox>,
|
right: Box<LocBox<Expr>>,
|
||||||
},
|
},
|
||||||
ForLoop {
|
ForLoop {
|
||||||
init: Box<Ast>,
|
init: Box<Ast>,
|
||||||
test: Box<ExprBox>,
|
test: Box<LocBox<Expr>>,
|
||||||
on_loop: Box<ExprBox>,
|
on_loop: Box<LocBox<Expr>>,
|
||||||
body: Block,
|
body: Block,
|
||||||
},
|
},
|
||||||
WhileLoop {
|
WhileLoop {
|
||||||
test: Box<ExprBox>,
|
test: Box<LocBox<Expr>>,
|
||||||
body: Block,
|
body: Block,
|
||||||
},
|
},
|
||||||
InfLoop {
|
InfLoop {
|
||||||
|
@ -79,20 +58,20 @@ pub enum Expr {
|
||||||
If(IfExpr),
|
If(IfExpr),
|
||||||
Struct {
|
Struct {
|
||||||
path: Path,
|
path: Path,
|
||||||
fields: HashMap<Ident, ExprBox>,
|
fields: HashMap<Ident, LocBox<Expr>>,
|
||||||
},
|
},
|
||||||
Return(Box<Option<ExprBox>>),
|
Return(Box<Option<LocBox<Expr>>>),
|
||||||
Break,
|
Break,
|
||||||
Continue,
|
Continue,
|
||||||
Cast {
|
Cast {
|
||||||
left: Box<ExprBox>,
|
left: Box<LocBox<Expr>>,
|
||||||
right: Box<TypeBox>
|
right: Box<LocBox<Type>>
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExprBox {
|
impl Expr {
|
||||||
pub fn unwrap_path(&self) -> Path {
|
pub fn unwrap_path(&self) -> Path {
|
||||||
let Expr::Path(p) = self.inner.clone() else {panic!("Unwrapping")};
|
let Expr::Path(p) = self else {panic!("Unwrapping")};
|
||||||
p.clone()
|
p.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,7 +79,7 @@ impl ExprBox {
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct CallParams(pub Vec<ExprBox>);
|
pub struct CallParams(pub Vec<LocBox<Expr>>);
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Block(pub Vec<Ast>);
|
pub struct Block(pub Vec<Ast>);
|
||||||
|
@ -111,7 +90,7 @@ pub struct Path(pub Vec<Ident>);
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct IfExpr {
|
pub struct IfExpr {
|
||||||
pub test: Box<ExprBox>,
|
pub test: Box<LocBox<Expr>>,
|
||||||
pub body: Block,
|
pub body: Block,
|
||||||
pub else_if: Option<IfBranchExpr>
|
pub else_if: Option<IfBranchExpr>
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::tokeniser::tokentype::*;
|
use crate::{common::loc::LocBox, tokeniser::tokentype::*};
|
||||||
|
|
||||||
use super::{expr::ExprBox, typ::TypeBox, Ast};
|
use super::{expr::Expr, typ::Type, Ast};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Literal {
|
pub enum Literal {
|
||||||
|
@ -10,10 +10,10 @@ pub enum Literal {
|
||||||
Ident(Ident),
|
Ident(Ident),
|
||||||
String(TString),
|
String(TString),
|
||||||
Char(Char),
|
Char(Char),
|
||||||
Array(Vec<ExprBox>),
|
Array(Vec<LocBox<Expr>>),
|
||||||
ArrayRepeat {
|
ArrayRepeat {
|
||||||
typ: Box<TypeBox>,
|
typ: Box<LocBox<Type>>,
|
||||||
count: Box<ExprBox>,
|
count: Box<LocBox<Expr>>,
|
||||||
},
|
},
|
||||||
Struct {
|
Struct {
|
||||||
name: Ident,
|
name: Ident,
|
||||||
|
|
|
@ -2,6 +2,7 @@ use std::collections::HashMap;
|
||||||
|
|
||||||
use statement::{Enum, Function, Struct, TypeAlias};
|
use statement::{Enum, Function, Struct, TypeAlias};
|
||||||
|
|
||||||
|
use crate::common::loc::LocBox;
|
||||||
pub use crate::tokeniser::tokentype::*;
|
pub use crate::tokeniser::tokentype::*;
|
||||||
|
|
||||||
pub mod expr;
|
pub mod expr;
|
||||||
|
@ -21,8 +22,8 @@ pub struct Program {
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Ast {
|
pub enum Ast {
|
||||||
Expr(expr::ExprBox),
|
Expr(LocBox<expr::Expr>),
|
||||||
Statement(statement::StatementBox),
|
Statement(LocBox<statement::Statement>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,28 +1,7 @@
|
||||||
|
|
||||||
use crate::common::Loc;
|
use crate::common::{loc::LocBox, Loc};
|
||||||
|
|
||||||
use super::{expr::{Block, ExprBox}, typ::{Type, TypeBox}, Ident, TString};
|
use super::{expr::{Block, Expr}, typ::Type, Ident, TString};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct StatementBox {
|
|
||||||
inner: Statement,
|
|
||||||
loc: Loc
|
|
||||||
}
|
|
||||||
|
|
||||||
impl StatementBox {
|
|
||||||
pub fn new(loc: &Loc, stat: Statement) -> Self {
|
|
||||||
Self { loc: loc.clone(), inner: stat }
|
|
||||||
}
|
|
||||||
pub fn inner(&self) -> &Statement {
|
|
||||||
&self.inner
|
|
||||||
}
|
|
||||||
pub fn inner_mut(&mut self) -> &mut Statement {
|
|
||||||
&mut self.inner
|
|
||||||
}
|
|
||||||
pub fn loc(&self) -> &Loc {
|
|
||||||
&self.loc
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Statement {
|
pub enum Statement {
|
||||||
|
@ -32,31 +11,31 @@ pub enum Statement {
|
||||||
Enum(Enum),
|
Enum(Enum),
|
||||||
ConstVar {
|
ConstVar {
|
||||||
name: Ident,
|
name: Ident,
|
||||||
typ: TypeBox,
|
typ: LocBox<Type>,
|
||||||
val: ExprBox
|
val: LocBox<Expr>
|
||||||
},
|
},
|
||||||
StaticVar {
|
StaticVar {
|
||||||
name: Ident,
|
name: Ident,
|
||||||
typ: TypeBox,
|
typ: LocBox<Type>,
|
||||||
val: ExprBox,
|
val: LocBox<Expr>,
|
||||||
},
|
},
|
||||||
Let {
|
Let {
|
||||||
name: Ident,
|
name: Ident,
|
||||||
typ: Option<TypeBox>,
|
typ: Option<LocBox<Type>>,
|
||||||
val: Option<ExprBox>,
|
val: Option<LocBox<Expr>>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct TypeAlias {
|
pub struct TypeAlias {
|
||||||
pub name: Ident,
|
pub name: Ident,
|
||||||
pub typ: TypeBox,
|
pub typ: LocBox<Type>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Struct {
|
pub struct Struct {
|
||||||
pub name: Ident,
|
pub name: Ident,
|
||||||
pub fields: Vec<(Ident, TypeBox)>,
|
pub fields: Vec<(Ident, LocBox<Type>)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -69,8 +48,8 @@ pub struct Enum {
|
||||||
pub struct Function {
|
pub struct Function {
|
||||||
pub struct_name: Option<Ident>,
|
pub struct_name: Option<Ident>,
|
||||||
pub name: Ident,
|
pub name: Ident,
|
||||||
pub params: Vec<(Ident, TypeBox)>,
|
pub params: Vec<(Ident, LocBox<Type>)>,
|
||||||
pub ret_type: Option<TypeBox>,
|
pub ret_type: Option<LocBox<Type>>,
|
||||||
pub qual_const: bool,
|
pub qual_const: bool,
|
||||||
pub qual_extern: Option<TString>, // abi
|
pub qual_extern: Option<TString>, // abi
|
||||||
pub body: Option<Block>, // If None then its a type declaration
|
pub body: Option<Block>, // If None then its a type declaration
|
||||||
|
|
|
@ -1,27 +1,6 @@
|
||||||
use crate::common::Loc;
|
use crate::common::{loc::LocBox, Loc};
|
||||||
|
|
||||||
use super::{expr::ExprBox, Ident};
|
use super::{expr::Expr, Ident};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct TypeBox {
|
|
||||||
inner: Type,
|
|
||||||
loc: Loc
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TypeBox {
|
|
||||||
pub fn new(loc: &Loc, stat: Type) -> Self {
|
|
||||||
Self { loc: loc.clone(), inner: stat }
|
|
||||||
}
|
|
||||||
pub fn inner(&self) -> &Type {
|
|
||||||
&self.inner
|
|
||||||
}
|
|
||||||
pub fn inner_mut(&mut self) -> &mut Type {
|
|
||||||
&mut self.inner
|
|
||||||
}
|
|
||||||
pub fn loc(&self) -> &Loc {
|
|
||||||
&self.loc
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Type {
|
pub enum Type {
|
||||||
|
@ -34,7 +13,7 @@ pub enum Type {
|
||||||
},
|
},
|
||||||
ArrayRepeat {
|
ArrayRepeat {
|
||||||
inner: Box<Type>,
|
inner: Box<Type>,
|
||||||
count: ExprBox,
|
count: LocBox<Expr>,
|
||||||
},
|
},
|
||||||
Owned(Ident),
|
Owned(Ident),
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,9 @@ use std::collections::HashMap;
|
||||||
|
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Result};
|
||||||
|
|
||||||
use crate::{debug, error, lerror, parser::{typ::parse_type, Punctuation}, tokeniser::Token};
|
use crate::{common::loc::LocBox, debug, error, lerror, parser::{typ::parse_type, Punctuation}, tokeniser::Token};
|
||||||
|
|
||||||
use super::{ast::{expr::{Block, CallParams, Expr, ExprBox, IfBranchExpr, IfExpr, Path}, literal::Literal, TokenType}, parse_item, utils, Delimiter, Keyword};
|
use super::{ast::{expr::{Block, CallParams, Expr, IfBranchExpr, IfExpr, Path}, literal::Literal, TokenType}, parse_item, utils, Delimiter, Keyword};
|
||||||
|
|
||||||
const BINOP_LIST: &[TokenType] = &[
|
const BINOP_LIST: &[TokenType] = &[
|
||||||
TokenType::Punct(Punctuation::Plus),
|
TokenType::Punct(Punctuation::Plus),
|
||||||
|
@ -37,14 +37,14 @@ const BINOP_LIST: &[TokenType] = &[
|
||||||
TokenType::Punct(Punctuation::Ge),
|
TokenType::Punct(Punctuation::Ge),
|
||||||
];
|
];
|
||||||
|
|
||||||
pub fn parse_expr(tokens: &mut Vec<Token>, precedence: usize, consume_semi: bool) -> Result<Option<ExprBox>> {
|
pub fn parse_expr(tokens: &mut Vec<Token>, precedence: usize, consume_semi: bool) -> Result<Option<LocBox<Expr>>> {
|
||||||
let res = if let Some(_) = utils::check(tokens, TokenType::Delim(Delimiter::ParenL)) {
|
let res = if let Some(_) = utils::check(tokens, TokenType::Delim(Delimiter::ParenL)) {
|
||||||
Some(parse_group(tokens)?)
|
Some(parse_group(tokens)?)
|
||||||
} else
|
} else
|
||||||
if let Some(_) = utils::check(tokens, TokenType::ident("")) {
|
if let Some(_) = utils::check(tokens, TokenType::ident("")) {
|
||||||
let p = parse_path(tokens)?;
|
let p = parse_path(tokens)?;
|
||||||
if let Some(_) = utils::check(tokens, TokenType::Delim(Delimiter::CurlyL)) {
|
if let Some(_) = utils::check(tokens, TokenType::Delim(Delimiter::CurlyL)) {
|
||||||
Some(parse_struct_literal(tokens, p.unwrap_path())?)
|
Some(parse_struct_literal(tokens, p.inner().unwrap_path())?)
|
||||||
} else {
|
} else {
|
||||||
Some(p)
|
Some(p)
|
||||||
}
|
}
|
||||||
|
@ -74,11 +74,11 @@ pub fn parse_expr(tokens: &mut Vec<Token>, precedence: usize, consume_semi: bool
|
||||||
} else if let Some(_) = utils::check(tokens, TokenType::Keyword(Keyword::Return)) {
|
} else if let Some(_) = utils::check(tokens, TokenType::Keyword(Keyword::Return)) {
|
||||||
return Ok(Some(parse_return(tokens)?));
|
return Ok(Some(parse_return(tokens)?));
|
||||||
} else if let Some(kw) = utils::check_consume(tokens, TokenType::Keyword(Keyword::Break)) {
|
} else if let Some(kw) = utils::check_consume(tokens, TokenType::Keyword(Keyword::Break)) {
|
||||||
return Ok(Some(ExprBox::new(kw.loc(), Expr::Break)));
|
return Ok(Some(LocBox::new(kw.loc(), Expr::Break)));
|
||||||
} else if let Some(kw) = utils::check_consume(tokens, TokenType::Keyword(Keyword::Continue)) {
|
} else if let Some(kw) = utils::check_consume(tokens, TokenType::Keyword(Keyword::Continue)) {
|
||||||
return Ok(Some(ExprBox::new(kw.loc(), Expr::Continue)));
|
return Ok(Some(LocBox::new(kw.loc(), Expr::Continue)));
|
||||||
} else if let Some(kw) = utils::check(tokens, TokenType::Keyword(Keyword::If)) {
|
} else if let Some(kw) = utils::check(tokens, TokenType::Keyword(Keyword::If)) {
|
||||||
return Ok(Some(ExprBox::new(&kw.loc().clone(), Expr::If(parse_if(tokens)?))));
|
return Ok(Some(LocBox::new(&kw.loc().clone(), Expr::If(parse_if(tokens)?))));
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
@ -113,16 +113,16 @@ pub fn parse_expr(tokens: &mut Vec<Token>, precedence: usize, consume_semi: bool
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_return(tokens: &mut Vec<Token>) -> Result<ExprBox> {
|
fn parse_return(tokens: &mut Vec<Token>) -> Result<LocBox<Expr>> {
|
||||||
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::Return), "")?;
|
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::Return), "")?;
|
||||||
let item = parse_expr(tokens, 0, true)?;
|
let item = parse_expr(tokens, 0, true)?;
|
||||||
Ok(ExprBox::new(kw.loc(), Expr::Return(Box::new(item))))
|
Ok(LocBox::new(kw.loc(), Expr::Return(Box::new(item))))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_cast(tokens: &mut Vec<Token>, left: ExprBox) -> Result<ExprBox> {
|
fn parse_cast(tokens: &mut Vec<Token>, left: LocBox<Expr>) -> Result<LocBox<Expr>> {
|
||||||
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::As), "")?;
|
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::As), "")?;
|
||||||
let typ = parse_type(tokens)?;
|
let typ = parse_type(tokens)?;
|
||||||
Ok(ExprBox::new(kw.loc(), Expr::Cast {
|
Ok(LocBox::new(kw.loc(), Expr::Cast {
|
||||||
left: Box::new(left),
|
left: Box::new(left),
|
||||||
right: Box::new(typ)
|
right: Box::new(typ)
|
||||||
}))
|
}))
|
||||||
|
@ -168,19 +168,19 @@ fn parse_if(tokens: &mut Vec<Token>) -> Result<IfExpr> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn parse_while_loop(tokens: &mut Vec<Token>) -> Result<ExprBox> {
|
fn parse_while_loop(tokens: &mut Vec<Token>) -> Result<LocBox<Expr>> {
|
||||||
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::While), "")?;
|
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::While), "")?;
|
||||||
let Some(test) = parse_expr(tokens, 0, false)? else {
|
let Some(test) = parse_expr(tokens, 0, false)? else {
|
||||||
lerror!(kw.loc(), "Expected test comparrison for while loop, got nothing");
|
lerror!(kw.loc(), "Expected test comparrison for while loop, got nothing");
|
||||||
bail!("")
|
bail!("")
|
||||||
};
|
};
|
||||||
let block = parse_block(tokens)?;
|
let block = parse_block(tokens)?;
|
||||||
Ok(ExprBox::new(kw.loc(), Expr::WhileLoop {
|
Ok(LocBox::new(kw.loc(), Expr::WhileLoop {
|
||||||
test: Box::new(test),
|
test: Box::new(test),
|
||||||
body: block
|
body: block
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
fn parse_for_loop(tokens: &mut Vec<Token>) -> Result<ExprBox> {
|
fn parse_for_loop(tokens: &mut Vec<Token>) -> Result<LocBox<Expr>> {
|
||||||
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::For), "")?;
|
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::For), "")?;
|
||||||
let Some(pre) = parse_item(tokens)? else {
|
let Some(pre) = parse_item(tokens)? else {
|
||||||
lerror!(kw.loc(), "Expected init stat for a for loop, got nothing");
|
lerror!(kw.loc(), "Expected init stat for a for loop, got nothing");
|
||||||
|
@ -198,19 +198,19 @@ fn parse_for_loop(tokens: &mut Vec<Token>) -> Result<ExprBox> {
|
||||||
};
|
};
|
||||||
let block = parse_block(tokens)?;
|
let block = parse_block(tokens)?;
|
||||||
|
|
||||||
Ok(ExprBox::new(kw.loc(), Expr::ForLoop {
|
Ok(LocBox::new(kw.loc(), Expr::ForLoop {
|
||||||
init: Box::new(pre),
|
init: Box::new(pre),
|
||||||
test: Box::new(test),
|
test: Box::new(test),
|
||||||
on_loop: Box::new(post),
|
on_loop: Box::new(post),
|
||||||
body: block
|
body: block
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
fn parse_inf_loop(tokens: &mut Vec<Token>) -> Result<ExprBox> {
|
fn parse_inf_loop(tokens: &mut Vec<Token>) -> Result<LocBox<Expr>> {
|
||||||
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::Loop), "")?;
|
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::Loop), "")?;
|
||||||
let block = parse_block(tokens)?;
|
let block = parse_block(tokens)?;
|
||||||
Ok(ExprBox::new(kw.loc(), Expr::InfLoop { body: block }))
|
Ok(LocBox::new(kw.loc(), Expr::InfLoop { body: block }))
|
||||||
}
|
}
|
||||||
fn parse_fn_call(tokens: &mut Vec<Token>, left: ExprBox) -> Result<ExprBox> {
|
fn parse_fn_call(tokens: &mut Vec<Token>, left: LocBox<Expr>) -> Result<LocBox<Expr>> {
|
||||||
let start = utils::check_consume_or_err(tokens, TokenType::Delim(Delimiter::ParenL), "")?;
|
let start = utils::check_consume_or_err(tokens, TokenType::Delim(Delimiter::ParenL), "")?;
|
||||||
let mut params = Vec::new();
|
let mut params = Vec::new();
|
||||||
|
|
||||||
|
@ -228,22 +228,22 @@ fn parse_fn_call(tokens: &mut Vec<Token>, left: ExprBox) -> Result<ExprBox> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ = utils::check_consume_or_err(tokens, TokenType::Delim(Delimiter::ParenR), "");
|
_ = utils::check_consume_or_err(tokens, TokenType::Delim(Delimiter::ParenR), "");
|
||||||
Ok(ExprBox::new(start.loc(), Expr::Call { path: Box::new(left), params: CallParams(params) }))
|
Ok(LocBox::new(start.loc(), Expr::Call { path: Box::new(left), params: CallParams(params) }))
|
||||||
}
|
}
|
||||||
fn parse_array_index(tokens: &mut Vec<Token>, left: ExprBox) -> Result<ExprBox> {
|
fn parse_array_index(tokens: &mut Vec<Token>, left: LocBox<Expr>) -> Result<LocBox<Expr>> {
|
||||||
let start = utils::check_consume_or_err(tokens, TokenType::Delim(Delimiter::SquareL), "")?;
|
let start = utils::check_consume_or_err(tokens, TokenType::Delim(Delimiter::SquareL), "")?;
|
||||||
let Some(idx) = parse_expr(tokens, 0, false)? else {
|
let Some(idx) = parse_expr(tokens, 0, false)? else {
|
||||||
lerror!(start.loc(), "Expected index for in array index but found nothing.");
|
lerror!(start.loc(), "Expected index for in array index but found nothing.");
|
||||||
bail!("")
|
bail!("")
|
||||||
};
|
};
|
||||||
_ = utils::check_consume_or_err(tokens, TokenType::Delim(Delimiter::SquareR), "");
|
_ = utils::check_consume_or_err(tokens, TokenType::Delim(Delimiter::SquareR), "");
|
||||||
Ok(ExprBox::new(start.loc(), Expr::ArrayIndex {
|
Ok(LocBox::new(start.loc(), Expr::ArrayIndex {
|
||||||
name: Box::new(left),
|
name: Box::new(left),
|
||||||
index: Box::new(idx)
|
index: Box::new(idx)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_field_access(tokens: &mut Vec<Token>, left: ExprBox) -> Result<ExprBox> {
|
fn parse_field_access(tokens: &mut Vec<Token>, left: LocBox<Expr>) -> Result<LocBox<Expr>> {
|
||||||
let start = utils::check_consume_or_err(tokens, TokenType::Punct(Punctuation::Fieldaccess), "unreachable")?;
|
let start = utils::check_consume_or_err(tokens, TokenType::Punct(Punctuation::Fieldaccess), "unreachable")?;
|
||||||
|
|
||||||
let right = if let Some(_) = utils::check_2_last(tokens, TokenType::Punct(Punctuation::Arrow)) {
|
let right = if let Some(_) = utils::check_2_last(tokens, TokenType::Punct(Punctuation::Arrow)) {
|
||||||
|
@ -255,13 +255,13 @@ fn parse_field_access(tokens: &mut Vec<Token>, left: ExprBox) -> Result<ExprBox>
|
||||||
} else {
|
} else {
|
||||||
parse_path(tokens)?
|
parse_path(tokens)?
|
||||||
};
|
};
|
||||||
Ok(ExprBox::new(start.loc(), Expr::FieldAccess {
|
Ok(LocBox::new(start.loc(), Expr::FieldAccess {
|
||||||
left: Box::new(Some(left)),
|
left: Box::new(Some(left)),
|
||||||
right: Box::new(right)
|
right: Box::new(right)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_ptr_field_access(tokens: &mut Vec<Token>, left: ExprBox) -> Result<ExprBox> {
|
fn parse_ptr_field_access(tokens: &mut Vec<Token>, left: LocBox<Expr>) -> Result<LocBox<Expr>> {
|
||||||
let start = utils::check_consume_or_err(tokens, TokenType::Punct(Punctuation::Arrow), "unreachable")?;
|
let start = utils::check_consume_or_err(tokens, TokenType::Punct(Punctuation::Arrow), "unreachable")?;
|
||||||
let right = if let Some(_) = utils::check_2_last(tokens, TokenType::Punct(Punctuation::Arrow)) {
|
let right = if let Some(_) = utils::check_2_last(tokens, TokenType::Punct(Punctuation::Arrow)) {
|
||||||
let right = parse_path(tokens)?;
|
let right = parse_path(tokens)?;
|
||||||
|
@ -272,28 +272,28 @@ fn parse_ptr_field_access(tokens: &mut Vec<Token>, left: ExprBox) -> Result<Expr
|
||||||
} else {
|
} else {
|
||||||
parse_path(tokens)?
|
parse_path(tokens)?
|
||||||
};
|
};
|
||||||
Ok(ExprBox::new(start.loc(), Expr::PtrFieldAccess {
|
Ok(LocBox::new(start.loc(), Expr::PtrFieldAccess {
|
||||||
left: Box::new(Some(left)),
|
left: Box::new(Some(left)),
|
||||||
right: Box::new(right)
|
right: Box::new(right)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_literal(tokens: &mut Vec<Token>) -> Result<ExprBox> {
|
fn parse_literal(tokens: &mut Vec<Token>) -> Result<LocBox<Expr>> {
|
||||||
if let Some(tkn) = utils::check_consume(tokens, TokenType::string("", false)) {
|
if let Some(tkn) = utils::check_consume(tokens, TokenType::string("", false)) {
|
||||||
let TokenType::String(str) = tkn.tt() else {unreachable!()};
|
let TokenType::String(str) = tkn.tt() else {unreachable!()};
|
||||||
return Ok(ExprBox::new(tkn.loc(), Expr::Literal(Literal::String(str.clone()))));
|
return Ok(LocBox::new(tkn.loc(), Expr::Literal(Literal::String(str.clone()))));
|
||||||
} else
|
} else
|
||||||
if let Some(tkn) = utils::check_consume(tokens, TokenType::number(0, 0, false)) {
|
if let Some(tkn) = utils::check_consume(tokens, TokenType::number(0, 0, false)) {
|
||||||
let TokenType::Number(val) = tkn.tt() else {unreachable!()};
|
let TokenType::Number(val) = tkn.tt() else {unreachable!()};
|
||||||
return Ok(ExprBox::new(tkn.loc(), Expr::Literal(Literal::Number(val.clone()))));
|
return Ok(LocBox::new(tkn.loc(), Expr::Literal(Literal::Number(val.clone()))));
|
||||||
} else
|
} else
|
||||||
if let Some(tkn) = utils::check_consume(tokens, TokenType::char('\0')) {
|
if let Some(tkn) = utils::check_consume(tokens, TokenType::char('\0')) {
|
||||||
let TokenType::Char(val) = tkn.tt() else {unreachable!()};
|
let TokenType::Char(val) = tkn.tt() else {unreachable!()};
|
||||||
return Ok(ExprBox::new(tkn.loc(), Expr::Literal(Literal::Char(val.clone()))));
|
return Ok(LocBox::new(tkn.loc(), Expr::Literal(Literal::Char(val.clone()))));
|
||||||
} else
|
} else
|
||||||
if let Some(start) = utils::check_consume(tokens, TokenType::Delim(Delimiter::SquareL)) {
|
if let Some(start) = utils::check_consume(tokens, TokenType::Delim(Delimiter::SquareL)) {
|
||||||
if let Some(_) = utils::check_consume(tokens, TokenType::Delim(Delimiter::SquareR)) {
|
if let Some(_) = utils::check_consume(tokens, TokenType::Delim(Delimiter::SquareR)) {
|
||||||
return Ok(ExprBox::new(start.loc(), Expr::Literal(Literal::Array(Vec::new()))));
|
return Ok(LocBox::new(start.loc(), Expr::Literal(Literal::Array(Vec::new()))));
|
||||||
}
|
}
|
||||||
if *tokens[tokens.len()-2].tt() == TokenType::Punct(Punctuation::Comma) {
|
if *tokens[tokens.len()-2].tt() == TokenType::Punct(Punctuation::Comma) {
|
||||||
let first = parse_expr(tokens, 0, false)?;
|
let first = parse_expr(tokens, 0, false)?;
|
||||||
|
@ -310,12 +310,12 @@ fn parse_literal(tokens: &mut Vec<Token>) -> Result<ExprBox> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
utils::check_consume_or_err(tokens, TokenType::Delim(Delimiter::SquareR), "")?;
|
utils::check_consume_or_err(tokens, TokenType::Delim(Delimiter::SquareR), "")?;
|
||||||
return Ok(ExprBox::new(start.loc(), Expr::Literal(Literal::Array(values))));
|
return Ok(LocBox::new(start.loc(), Expr::Literal(Literal::Array(values))));
|
||||||
} else if *tokens[tokens.len()-2].tt() == TokenType::Punct(Punctuation::Semi) {
|
} else if *tokens[tokens.len()-2].tt() == TokenType::Punct(Punctuation::Semi) {
|
||||||
let typ = parse_type(tokens)?;
|
let typ = parse_type(tokens)?;
|
||||||
let count = parse_expr(tokens, 0, false)?.unwrap();
|
let count = parse_expr(tokens, 0, false)?.unwrap();
|
||||||
utils::check_consume_or_err(tokens, TokenType::Delim(Delimiter::SquareR), "")?;
|
utils::check_consume_or_err(tokens, TokenType::Delim(Delimiter::SquareR), "")?;
|
||||||
return Ok(ExprBox::new(start.loc(), Expr::Literal(Literal::ArrayRepeat {
|
return Ok(LocBox::new(start.loc(), Expr::Literal(Literal::ArrayRepeat {
|
||||||
typ: Box::new(typ),
|
typ: Box::new(typ),
|
||||||
count: Box::new(count)
|
count: Box::new(count)
|
||||||
})));
|
})));
|
||||||
|
@ -331,7 +331,7 @@ fn parse_literal(tokens: &mut Vec<Token>) -> Result<ExprBox> {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_struct_literal(tokens: &mut Vec<Token>, name: Path) -> Result<ExprBox> {
|
fn parse_struct_literal(tokens: &mut Vec<Token>, name: Path) -> Result<LocBox<Expr>> {
|
||||||
let start = utils::check_consume_or_err(tokens, TokenType::Delim(Delimiter::CurlyL), "")?;
|
let start = utils::check_consume_or_err(tokens, TokenType::Delim(Delimiter::CurlyL), "")?;
|
||||||
let mut fields = HashMap::new();
|
let mut fields = HashMap::new();
|
||||||
while !tokens.is_empty() {
|
while !tokens.is_empty() {
|
||||||
|
@ -348,10 +348,10 @@ fn parse_struct_literal(tokens: &mut Vec<Token>, name: Path) -> Result<ExprBox>
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(ExprBox::new(start.loc(), Expr::Struct { path: name, fields }))
|
Ok(LocBox::new(start.loc(), Expr::Struct { path: name, fields }))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_group(tokens: &mut Vec<Token>) -> Result<ExprBox> {
|
fn parse_group(tokens: &mut Vec<Token>) -> Result<LocBox<Expr>> {
|
||||||
let start = utils::check_consume_or_err(tokens, TokenType::Delim(Delimiter::ParenL), "")?;
|
let start = utils::check_consume_or_err(tokens, TokenType::Delim(Delimiter::ParenL), "")?;
|
||||||
let Some(expr) = parse_expr(tokens, 0, false)? else {
|
let Some(expr) = parse_expr(tokens, 0, false)? else {
|
||||||
lerror!(start.loc(), "Expected expr found nothing");
|
lerror!(start.loc(), "Expected expr found nothing");
|
||||||
|
@ -359,10 +359,10 @@ fn parse_group(tokens: &mut Vec<Token>) -> Result<ExprBox> {
|
||||||
};
|
};
|
||||||
|
|
||||||
utils::check_consume_or_err(tokens, TokenType::Delim(Delimiter::ParenR), "")?;
|
utils::check_consume_or_err(tokens, TokenType::Delim(Delimiter::ParenR), "")?;
|
||||||
Ok(ExprBox::new(start.loc(), Expr::Group(Box::new(expr))))
|
Ok(LocBox::new(start.loc(), Expr::Group(Box::new(expr))))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_path(tokens: &mut Vec<Token>) -> Result<ExprBox> {
|
fn parse_path(tokens: &mut Vec<Token>) -> Result<LocBox<Expr>> {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
let part = utils::check_consume(tokens, TokenType::ident("")).unwrap();
|
let part = utils::check_consume(tokens, TokenType::ident("")).unwrap();
|
||||||
|
|
||||||
|
@ -375,10 +375,10 @@ fn parse_path(tokens: &mut Vec<Token>) -> Result<ExprBox> {
|
||||||
buf.push(part.tt().unwrap_ident());
|
buf.push(part.tt().unwrap_ident());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(ExprBox::new(part.loc(), Expr::Path(Path(buf))))
|
Ok(LocBox::new(part.loc(), Expr::Path(Path(buf))))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_unop(tokens: &mut Vec<Token>) -> Result<ExprBox> {
|
fn parse_unop(tokens: &mut Vec<Token>) -> Result<LocBox<Expr>> {
|
||||||
let typ = utils::check_consume_or_err_from_many(tokens, &[
|
let typ = utils::check_consume_or_err_from_many(tokens, &[
|
||||||
TokenType::Punct(Punctuation::Not),
|
TokenType::Punct(Punctuation::Not),
|
||||||
TokenType::Punct(Punctuation::Plus),
|
TokenType::Punct(Punctuation::Plus),
|
||||||
|
@ -393,13 +393,13 @@ fn parse_unop(tokens: &mut Vec<Token>) -> Result<ExprBox> {
|
||||||
lerror!(&loc, "Expected expression after unary token, found nothing");
|
lerror!(&loc, "Expected expression after unary token, found nothing");
|
||||||
bail!("")
|
bail!("")
|
||||||
};
|
};
|
||||||
Ok(ExprBox::new(&loc, Expr::UnOp {
|
Ok(LocBox::new(&loc, Expr::UnOp {
|
||||||
typ,
|
typ,
|
||||||
right: Box::new(right)
|
right: Box::new(right)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_binop(tokens: &mut Vec<Token>, mut lhs: ExprBox, precedence: usize) -> Result<ExprBox> {
|
fn parse_binop(tokens: &mut Vec<Token>, mut lhs: LocBox<Expr>, precedence: usize) -> Result<LocBox<Expr>> {
|
||||||
// TODO: https://en.wikipedia.org/wiki/Operator-precedence_parser#Pseudocode
|
// TODO: https://en.wikipedia.org/wiki/Operator-precedence_parser#Pseudocode
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
@ -431,7 +431,7 @@ fn parse_binop(tokens: &mut Vec<Token>, mut lhs: ExprBox, precedence: usize) ->
|
||||||
|
|
||||||
_ = tokens.pop();
|
_ = tokens.pop();
|
||||||
let Some(rhs) = parse_expr(tokens, rp, false)? else {break;};
|
let Some(rhs) = parse_expr(tokens, rp, false)? else {break;};
|
||||||
lhs = ExprBox::new(&op_loc, Expr::BinOp {
|
lhs = LocBox::new(&op_loc, Expr::BinOp {
|
||||||
typ: op,
|
typ: op,
|
||||||
left: Box::new(lhs),
|
left: Box::new(lhs),
|
||||||
right: Box::new(rhs)
|
right: Box::new(rhs)
|
||||||
|
|
|
@ -1,19 +1,20 @@
|
||||||
use anyhow::bail;
|
use anyhow::bail;
|
||||||
|
|
||||||
|
use crate::common::loc::LocBox;
|
||||||
use crate::lerror;
|
use crate::lerror;
|
||||||
use crate::parser::ast::TokenType;
|
use crate::parser::ast::TokenType;
|
||||||
use crate::parser::expr::parse_expr;
|
use crate::parser::expr::parse_expr;
|
||||||
use crate::parser::{Delimiter, Ident, Keyword, Punctuation};
|
use crate::parser::{Delimiter, Ident, Keyword, Punctuation};
|
||||||
use crate::tokeniser::Token;
|
use crate::tokeniser::Token;
|
||||||
use super::ast::typ::{Type, TypeBox};
|
use super::ast::typ::Type;
|
||||||
use super::expr::parse_block;
|
use super::expr::parse_block;
|
||||||
use super::typ::parse_type;
|
use super::typ::parse_type;
|
||||||
use super::utils;
|
use super::utils;
|
||||||
use super::ast::statement::{Enum, Function, Statement, StatementBox, Struct, TypeAlias};
|
use super::ast::statement::{Enum, Function, Statement, Struct, TypeAlias};
|
||||||
|
|
||||||
type Result<T> = anyhow::Result<T>;
|
type Result<T> = anyhow::Result<T>;
|
||||||
|
|
||||||
pub fn parse_statement(tokens: &mut Vec<Token>) -> Result<Option<StatementBox>> {
|
pub fn parse_statement(tokens: &mut Vec<Token>) -> Result<Option<LocBox<Statement>>> {
|
||||||
if let Some(_) = utils::check(tokens, TokenType::Keyword(Keyword::Fn)) {
|
if let Some(_) = utils::check(tokens, TokenType::Keyword(Keyword::Fn)) {
|
||||||
Ok(Some(parse_fn(tokens)?))
|
Ok(Some(parse_fn(tokens)?))
|
||||||
} else
|
} else
|
||||||
|
@ -39,7 +40,7 @@ pub fn parse_statement(tokens: &mut Vec<Token>) -> Result<Option<StatementBox>>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_enum(tokens: &mut Vec<Token>) -> Result<StatementBox> {
|
fn parse_enum(tokens: &mut Vec<Token>) -> Result<LocBox<Statement>> {
|
||||||
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::Enum), "")?;
|
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::Enum), "")?;
|
||||||
let name = utils::check_consume_or_err(tokens, TokenType::ident(""), "")?.tt().unwrap_ident();
|
let name = utils::check_consume_or_err(tokens, TokenType::ident(""), "")?.tt().unwrap_ident();
|
||||||
_ = utils::check_consume(tokens, TokenType::Delim(Delimiter::CurlyL));
|
_ = utils::check_consume(tokens, TokenType::Delim(Delimiter::CurlyL));
|
||||||
|
@ -60,10 +61,10 @@ fn parse_enum(tokens: &mut Vec<Token>) -> Result<StatementBox> {
|
||||||
fields.push(field_name);
|
fields.push(field_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(StatementBox::new(kw.loc(), Statement::Enum(Enum { name, fields })))
|
Ok(LocBox::new(kw.loc(), Statement::Enum(Enum { name, fields })))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_struct(tokens: &mut Vec<Token>) -> Result<StatementBox> {
|
fn parse_struct(tokens: &mut Vec<Token>) -> Result<LocBox<Statement>> {
|
||||||
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::Struct), "")?;
|
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::Struct), "")?;
|
||||||
let name = utils::check_consume_or_err(tokens, TokenType::ident(""), "")?.tt().unwrap_ident();
|
let name = utils::check_consume_or_err(tokens, TokenType::ident(""), "")?.tt().unwrap_ident();
|
||||||
_ = utils::check_consume(tokens, TokenType::Delim(Delimiter::CurlyL));
|
_ = utils::check_consume(tokens, TokenType::Delim(Delimiter::CurlyL));
|
||||||
|
@ -86,10 +87,10 @@ fn parse_struct(tokens: &mut Vec<Token>) -> Result<StatementBox> {
|
||||||
fields.push((field_name, typ));
|
fields.push((field_name, typ));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(StatementBox::new(kw.loc(), Statement::Struct(Struct { name, fields })))
|
Ok(LocBox::new(kw.loc(), Statement::Struct(Struct { name, fields })))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_static(tokens: &mut Vec<Token>) -> Result<StatementBox> {
|
fn parse_static(tokens: &mut Vec<Token>) -> Result<LocBox<Statement>> {
|
||||||
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::Static), "")?;
|
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::Static), "")?;
|
||||||
|
|
||||||
let name = utils::check_consume_or_err(tokens, TokenType::ident(""), "")?.tt().unwrap_ident();
|
let name = utils::check_consume_or_err(tokens, TokenType::ident(""), "")?.tt().unwrap_ident();
|
||||||
|
@ -101,10 +102,10 @@ fn parse_static(tokens: &mut Vec<Token>) -> Result<StatementBox> {
|
||||||
bail!("")
|
bail!("")
|
||||||
};
|
};
|
||||||
_ = utils::check_consume_or_err(tokens, TokenType::Punct(Punctuation::Semi), "")?;
|
_ = utils::check_consume_or_err(tokens, TokenType::Punct(Punctuation::Semi), "")?;
|
||||||
Ok(StatementBox::new(kw.loc(), Statement::StaticVar { name, typ, val }))
|
Ok(LocBox::new(kw.loc(), Statement::StaticVar { name, typ, val }))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_let(tokens: &mut Vec<Token>) -> Result<StatementBox> {
|
fn parse_let(tokens: &mut Vec<Token>) -> Result<LocBox<Statement>> {
|
||||||
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::Let), "")?;
|
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::Let), "")?;
|
||||||
let name = utils::check_consume_or_err(tokens, TokenType::ident(""), "")?.tt().unwrap_ident();
|
let name = utils::check_consume_or_err(tokens, TokenType::ident(""), "")?.tt().unwrap_ident();
|
||||||
let mut typ = None;
|
let mut typ = None;
|
||||||
|
@ -120,9 +121,9 @@ fn parse_let(tokens: &mut Vec<Token>) -> Result<StatementBox> {
|
||||||
val = Some(_val);
|
val = Some(_val);
|
||||||
}
|
}
|
||||||
_ = utils::check_consume_or_err(tokens, TokenType::Punct(Punctuation::Semi), "")?;
|
_ = utils::check_consume_or_err(tokens, TokenType::Punct(Punctuation::Semi), "")?;
|
||||||
Ok(StatementBox::new(kw.loc(), Statement::Let { name, typ, val }))
|
Ok(LocBox::new(kw.loc(), Statement::Let { name, typ, val }))
|
||||||
}
|
}
|
||||||
fn parse_constant(tokens: &mut Vec<Token>) -> Result<StatementBox> {
|
fn parse_constant(tokens: &mut Vec<Token>) -> Result<LocBox<Statement>> {
|
||||||
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::Const), "")?;
|
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::Const), "")?;
|
||||||
|
|
||||||
if let Some(_) = utils::check(tokens, TokenType::Keyword(Keyword::Fn)) {
|
if let Some(_) = utils::check(tokens, TokenType::Keyword(Keyword::Fn)) {
|
||||||
|
@ -137,20 +138,20 @@ fn parse_constant(tokens: &mut Vec<Token>) -> Result<StatementBox> {
|
||||||
bail!("")
|
bail!("")
|
||||||
};
|
};
|
||||||
_ = utils::check_consume_or_err(tokens, TokenType::Punct(Punctuation::Semi), "")?;
|
_ = utils::check_consume_or_err(tokens, TokenType::Punct(Punctuation::Semi), "")?;
|
||||||
Ok(StatementBox::new(kw.loc(), Statement::ConstVar { name, typ, val }))
|
Ok(LocBox::new(kw.loc(), Statement::ConstVar { name, typ, val }))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_type_alias(tokens: &mut Vec<Token>) -> Result<StatementBox> {
|
fn parse_type_alias(tokens: &mut Vec<Token>) -> Result<LocBox<Statement>> {
|
||||||
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::Type), "")?;
|
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::Type), "")?;
|
||||||
let name = utils::check_consume_or_err(tokens, TokenType::ident(""), "")?.tt().unwrap_ident();
|
let name = utils::check_consume_or_err(tokens, TokenType::ident(""), "")?.tt().unwrap_ident();
|
||||||
_ = utils::check_consume_or_err(tokens, TokenType::Punct(Punctuation::Eq), "")?;
|
_ = utils::check_consume_or_err(tokens, TokenType::Punct(Punctuation::Eq), "")?;
|
||||||
let typ = parse_type(tokens)?;
|
let typ = parse_type(tokens)?;
|
||||||
_ = utils::check_consume_or_err(tokens, TokenType::Punct(Punctuation::Semi), "")?;
|
_ = utils::check_consume_or_err(tokens, TokenType::Punct(Punctuation::Semi), "")?;
|
||||||
|
|
||||||
Ok(StatementBox::new(kw.loc(), Statement::TypeAlias(TypeAlias { name, typ })))
|
Ok(LocBox::new(kw.loc(), Statement::TypeAlias(TypeAlias { name, typ })))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_fn(tokens: &mut Vec<Token>) -> Result<StatementBox> {
|
fn parse_fn(tokens: &mut Vec<Token>) -> Result<LocBox<Statement>> {
|
||||||
// Just remove the kw since we checked it before
|
// Just remove the kw since we checked it before
|
||||||
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::Fn), "")?;
|
let kw = utils::check_consume_or_err(tokens, TokenType::Keyword(Keyword::Fn), "")?;
|
||||||
|
|
||||||
|
@ -177,7 +178,7 @@ fn parse_fn(tokens: &mut Vec<Token>) -> Result<StatementBox> {
|
||||||
body = None;
|
body = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(StatementBox::new(kw.loc(), Statement::Fn(Function{
|
Ok(LocBox::new(kw.loc(), Statement::Fn(Function{
|
||||||
struct_name,
|
struct_name,
|
||||||
name,
|
name,
|
||||||
params,
|
params,
|
||||||
|
@ -190,7 +191,7 @@ fn parse_fn(tokens: &mut Vec<Token>) -> Result<StatementBox> {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fn parse_fn_params(tokens: &mut Vec<Token>) -> Result<Vec<(Ident, TypeBox)>> {
|
fn parse_fn_params(tokens: &mut Vec<Token>) -> Result<Vec<(Ident, LocBox<Type>)>> {
|
||||||
let mut args = Vec::new();
|
let mut args = Vec::new();
|
||||||
utils::check_consume_or_err(tokens, TokenType::Delim(Delimiter::ParenL), "")?;
|
utils::check_consume_or_err(tokens, TokenType::Delim(Delimiter::ParenL), "")?;
|
||||||
while !tokens.is_empty() {
|
while !tokens.is_empty() {
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
use crate::{parser::Delimiter, tokeniser::Token};
|
use crate::{common::loc::LocBox, parser::Delimiter, tokeniser::Token};
|
||||||
|
|
||||||
use super::{ast::{typ::{Type, TypeBox}, TokenType}, expr::parse_expr, utils, Keyword, Punctuation};
|
use super::{ast::{typ::Type, TokenType}, expr::parse_expr, utils, Keyword, Punctuation};
|
||||||
|
|
||||||
pub fn parse_type(tokens: &mut Vec<Token>) -> Result<TypeBox> {
|
pub fn parse_type(tokens: &mut Vec<Token>) -> Result<LocBox<Type>> {
|
||||||
let mut ref_cnt = Vec::new();
|
let mut ref_cnt = Vec::new();
|
||||||
let mut loc = None;
|
let mut loc = None;
|
||||||
while let Some(tok) = utils::check_consume(tokens, TokenType::Punct(Punctuation::Ampersand)) {
|
while let Some(tok) = utils::check_consume(tokens, TokenType::Punct(Punctuation::Ampersand)) {
|
||||||
|
@ -60,5 +60,5 @@ pub fn parse_type(tokens: &mut Vec<Token>) -> Result<TypeBox> {
|
||||||
_ => unreachable!()
|
_ => unreachable!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(TypeBox::new(&loc.unwrap(), typ))
|
Ok(LocBox::new(&loc.unwrap(), typ))
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ Program {
|
||||||
ast: Block(
|
ast: Block(
|
||||||
[
|
[
|
||||||
Statement(
|
Statement(
|
||||||
StatementBox {
|
LocBox {
|
||||||
inner: Enum(
|
inner: Enum(
|
||||||
Enum {
|
Enum {
|
||||||
name: Ident(
|
name: Ident(
|
||||||
|
@ -19,7 +19,7 @@ Program {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Statement(
|
Statement(
|
||||||
StatementBox {
|
LocBox {
|
||||||
inner: Enum(
|
inner: Enum(
|
||||||
Enum {
|
Enum {
|
||||||
name: Ident(
|
name: Ident(
|
||||||
|
|
|
@ -2,20 +2,20 @@ Program {
|
||||||
ast: Block(
|
ast: Block(
|
||||||
[
|
[
|
||||||
Statement(
|
Statement(
|
||||||
StatementBox {
|
LocBox {
|
||||||
inner: Let {
|
inner: Let {
|
||||||
name: Ident(
|
name: Ident(
|
||||||
"a",
|
"a",
|
||||||
),
|
),
|
||||||
typ: None,
|
typ: None,
|
||||||
val: Some(
|
val: Some(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: BinOp {
|
inner: BinOp {
|
||||||
typ: EqEq,
|
typ: EqEq,
|
||||||
left: ExprBox {
|
left: LocBox {
|
||||||
inner: BinOp {
|
inner: BinOp {
|
||||||
typ: Star,
|
typ: Star,
|
||||||
left: ExprBox {
|
left: LocBox {
|
||||||
inner: Literal(
|
inner: Literal(
|
||||||
Number(
|
Number(
|
||||||
Number {
|
Number {
|
||||||
|
@ -31,7 +31,7 @@ Program {
|
||||||
col: 10,
|
col: 10,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: Literal(
|
inner: Literal(
|
||||||
Number(
|
Number(
|
||||||
Number {
|
Number {
|
||||||
|
@ -54,7 +54,7 @@ Program {
|
||||||
col: 12,
|
col: 12,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: Literal(
|
inner: Literal(
|
||||||
Number(
|
Number(
|
||||||
Number {
|
Number {
|
||||||
|
@ -87,20 +87,20 @@ Program {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Statement(
|
Statement(
|
||||||
StatementBox {
|
LocBox {
|
||||||
inner: Let {
|
inner: Let {
|
||||||
name: Ident(
|
name: Ident(
|
||||||
"b",
|
"b",
|
||||||
),
|
),
|
||||||
typ: None,
|
typ: None,
|
||||||
val: Some(
|
val: Some(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: BinOp {
|
inner: BinOp {
|
||||||
typ: EqEq,
|
typ: EqEq,
|
||||||
left: ExprBox {
|
left: LocBox {
|
||||||
inner: BinOp {
|
inner: BinOp {
|
||||||
typ: Div,
|
typ: Div,
|
||||||
left: ExprBox {
|
left: LocBox {
|
||||||
inner: Literal(
|
inner: Literal(
|
||||||
Number(
|
Number(
|
||||||
Number {
|
Number {
|
||||||
|
@ -116,7 +116,7 @@ Program {
|
||||||
col: 10,
|
col: 10,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: Literal(
|
inner: Literal(
|
||||||
Number(
|
Number(
|
||||||
Number {
|
Number {
|
||||||
|
@ -139,10 +139,10 @@ Program {
|
||||||
col: 11,
|
col: 11,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: UnOp {
|
inner: UnOp {
|
||||||
typ: Star,
|
typ: Star,
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -182,22 +182,22 @@ Program {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Statement(
|
Statement(
|
||||||
StatementBox {
|
LocBox {
|
||||||
inner: Let {
|
inner: Let {
|
||||||
name: Ident(
|
name: Ident(
|
||||||
"c",
|
"c",
|
||||||
),
|
),
|
||||||
typ: None,
|
typ: None,
|
||||||
val: Some(
|
val: Some(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: BinOp {
|
inner: BinOp {
|
||||||
typ: Div,
|
typ: Div,
|
||||||
left: ExprBox {
|
left: LocBox {
|
||||||
inner: Group(
|
inner: Group(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: PtrFieldAccess {
|
inner: PtrFieldAccess {
|
||||||
left: Some(
|
left: Some(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -214,10 +214,10 @@ Program {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: FieldAccess {
|
inner: FieldAccess {
|
||||||
left: Some(
|
left: Some(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -234,10 +234,10 @@ Program {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: PtrFieldAccess {
|
inner: PtrFieldAccess {
|
||||||
left: Some(
|
left: Some(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -254,7 +254,7 @@ Program {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -298,7 +298,7 @@ Program {
|
||||||
col: 10,
|
col: 10,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: Literal(
|
inner: Literal(
|
||||||
Number(
|
Number(
|
||||||
Number {
|
Number {
|
||||||
|
@ -331,17 +331,17 @@ Program {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Statement(
|
Statement(
|
||||||
StatementBox {
|
LocBox {
|
||||||
inner: Let {
|
inner: Let {
|
||||||
name: Ident(
|
name: Ident(
|
||||||
"d",
|
"d",
|
||||||
),
|
),
|
||||||
typ: None,
|
typ: None,
|
||||||
val: Some(
|
val: Some(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: BinOp {
|
inner: BinOp {
|
||||||
typ: Div,
|
typ: Div,
|
||||||
left: ExprBox {
|
left: LocBox {
|
||||||
inner: Literal(
|
inner: Literal(
|
||||||
Number(
|
Number(
|
||||||
Number {
|
Number {
|
||||||
|
@ -357,10 +357,10 @@ Program {
|
||||||
col: 10,
|
col: 10,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: PtrFieldAccess {
|
inner: PtrFieldAccess {
|
||||||
left: Some(
|
left: Some(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -377,10 +377,10 @@ Program {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: FieldAccess {
|
inner: FieldAccess {
|
||||||
left: Some(
|
left: Some(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -397,10 +397,10 @@ Program {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: PtrFieldAccess {
|
inner: PtrFieldAccess {
|
||||||
left: Some(
|
left: Some(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -417,7 +417,7 @@ Program {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -471,20 +471,20 @@ Program {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Statement(
|
Statement(
|
||||||
StatementBox {
|
LocBox {
|
||||||
inner: Let {
|
inner: Let {
|
||||||
name: Ident(
|
name: Ident(
|
||||||
"e",
|
"e",
|
||||||
),
|
),
|
||||||
typ: None,
|
typ: None,
|
||||||
val: Some(
|
val: Some(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: BinOp {
|
inner: BinOp {
|
||||||
typ: Div,
|
typ: Div,
|
||||||
left: ExprBox {
|
left: LocBox {
|
||||||
inner: PtrFieldAccess {
|
inner: PtrFieldAccess {
|
||||||
left: Some(
|
left: Some(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -501,10 +501,10 @@ Program {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: FieldAccess {
|
inner: FieldAccess {
|
||||||
left: Some(
|
left: Some(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -521,10 +521,10 @@ Program {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: PtrFieldAccess {
|
inner: PtrFieldAccess {
|
||||||
left: Some(
|
left: Some(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -541,7 +541,7 @@ Program {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -578,7 +578,7 @@ Program {
|
||||||
col: 11,
|
col: 11,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: Literal(
|
inner: Literal(
|
||||||
Number(
|
Number(
|
||||||
Number {
|
Number {
|
||||||
|
@ -611,20 +611,20 @@ Program {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Statement(
|
Statement(
|
||||||
StatementBox {
|
LocBox {
|
||||||
inner: Let {
|
inner: Let {
|
||||||
name: Ident(
|
name: Ident(
|
||||||
"f",
|
"f",
|
||||||
),
|
),
|
||||||
typ: None,
|
typ: None,
|
||||||
val: Some(
|
val: Some(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: BinOp {
|
inner: BinOp {
|
||||||
typ: Div,
|
typ: Div,
|
||||||
left: ExprBox {
|
left: LocBox {
|
||||||
inner: FieldAccess {
|
inner: FieldAccess {
|
||||||
left: Some(
|
left: Some(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -641,10 +641,10 @@ Program {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: FieldAccess {
|
inner: FieldAccess {
|
||||||
left: Some(
|
left: Some(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -661,10 +661,10 @@ Program {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: FieldAccess {
|
inner: FieldAccess {
|
||||||
left: Some(
|
left: Some(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -681,7 +681,7 @@ Program {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -718,7 +718,7 @@ Program {
|
||||||
col: 11,
|
col: 11,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: Literal(
|
inner: Literal(
|
||||||
Number(
|
Number(
|
||||||
Number {
|
Number {
|
||||||
|
@ -751,22 +751,22 @@ Program {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Statement(
|
Statement(
|
||||||
StatementBox {
|
LocBox {
|
||||||
inner: Let {
|
inner: Let {
|
||||||
name: Ident(
|
name: Ident(
|
||||||
"g",
|
"g",
|
||||||
),
|
),
|
||||||
typ: None,
|
typ: None,
|
||||||
val: Some(
|
val: Some(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: BinOp {
|
inner: BinOp {
|
||||||
typ: Star,
|
typ: Star,
|
||||||
left: ExprBox {
|
left: LocBox {
|
||||||
inner: ArrayIndex {
|
inner: ArrayIndex {
|
||||||
name: ExprBox {
|
name: LocBox {
|
||||||
inner: FieldAccess {
|
inner: FieldAccess {
|
||||||
left: Some(
|
left: Some(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -783,7 +783,7 @@ Program {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -806,13 +806,13 @@ Program {
|
||||||
col: 11,
|
col: 11,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
index: ExprBox {
|
index: LocBox {
|
||||||
inner: UnOp {
|
inner: UnOp {
|
||||||
typ: Star,
|
typ: Star,
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: FieldAccess {
|
inner: FieldAccess {
|
||||||
left: Some(
|
left: Some(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -829,7 +829,7 @@ Program {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -866,7 +866,7 @@ Program {
|
||||||
col: 13,
|
col: 13,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: Literal(
|
inner: Literal(
|
||||||
Number(
|
Number(
|
||||||
Number {
|
Number {
|
||||||
|
|
|
@ -2,7 +2,7 @@ Program {
|
||||||
ast: Block(
|
ast: Block(
|
||||||
[
|
[
|
||||||
Statement(
|
Statement(
|
||||||
StatementBox {
|
LocBox {
|
||||||
inner: Fn(
|
inner: Fn(
|
||||||
Function {
|
Function {
|
||||||
struct_name: None,
|
struct_name: None,
|
||||||
|
@ -14,7 +14,7 @@ Program {
|
||||||
Ident(
|
Ident(
|
||||||
"argc",
|
"argc",
|
||||||
),
|
),
|
||||||
TypeBox {
|
LocBox {
|
||||||
inner: Owned(
|
inner: Owned(
|
||||||
Ident(
|
Ident(
|
||||||
"i32",
|
"i32",
|
||||||
|
@ -31,7 +31,7 @@ Program {
|
||||||
Ident(
|
Ident(
|
||||||
"argv",
|
"argv",
|
||||||
),
|
),
|
||||||
TypeBox {
|
LocBox {
|
||||||
inner: Ref {
|
inner: Ref {
|
||||||
inner: Array {
|
inner: Array {
|
||||||
inner: Owned(
|
inner: Owned(
|
||||||
|
@ -51,7 +51,7 @@ Program {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
ret_type: Some(
|
ret_type: Some(
|
||||||
TypeBox {
|
LocBox {
|
||||||
inner: Owned(
|
inner: Owned(
|
||||||
Ident(
|
Ident(
|
||||||
"i32",
|
"i32",
|
||||||
|
@ -70,10 +70,10 @@ Program {
|
||||||
Block(
|
Block(
|
||||||
[
|
[
|
||||||
Expr(
|
Expr(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: Return(
|
inner: Return(
|
||||||
Some(
|
Some(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: Literal(
|
inner: Literal(
|
||||||
Number(
|
Number(
|
||||||
Number {
|
Number {
|
||||||
|
@ -111,7 +111,7 @@ Program {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Statement(
|
Statement(
|
||||||
StatementBox {
|
LocBox {
|
||||||
inner: Fn(
|
inner: Fn(
|
||||||
Function {
|
Function {
|
||||||
struct_name: Some(
|
struct_name: Some(
|
||||||
|
@ -127,7 +127,7 @@ Program {
|
||||||
Ident(
|
Ident(
|
||||||
"self",
|
"self",
|
||||||
),
|
),
|
||||||
TypeBox {
|
LocBox {
|
||||||
inner: Ref {
|
inner: Ref {
|
||||||
inner: Owned(
|
inner: Owned(
|
||||||
Ident(
|
Ident(
|
||||||
|
@ -147,7 +147,7 @@ Program {
|
||||||
Ident(
|
Ident(
|
||||||
"a",
|
"a",
|
||||||
),
|
),
|
||||||
TypeBox {
|
LocBox {
|
||||||
inner: Ref {
|
inner: Ref {
|
||||||
inner: Owned(
|
inner: Owned(
|
||||||
Ident(
|
Ident(
|
||||||
|
@ -167,7 +167,7 @@ Program {
|
||||||
Ident(
|
Ident(
|
||||||
"b",
|
"b",
|
||||||
),
|
),
|
||||||
TypeBox {
|
LocBox {
|
||||||
inner: Ref {
|
inner: Ref {
|
||||||
inner: Owned(
|
inner: Owned(
|
||||||
Ident(
|
Ident(
|
||||||
|
@ -185,7 +185,7 @@ Program {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
ret_type: Some(
|
ret_type: Some(
|
||||||
TypeBox {
|
LocBox {
|
||||||
inner: Ref {
|
inner: Ref {
|
||||||
inner: Owned(
|
inner: Owned(
|
||||||
Ident(
|
Ident(
|
||||||
|
@ -214,7 +214,7 @@ Program {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Statement(
|
Statement(
|
||||||
StatementBox {
|
LocBox {
|
||||||
inner: Fn(
|
inner: Fn(
|
||||||
Function {
|
Function {
|
||||||
struct_name: Some(
|
struct_name: Some(
|
||||||
|
@ -230,7 +230,7 @@ Program {
|
||||||
Ident(
|
Ident(
|
||||||
"a",
|
"a",
|
||||||
),
|
),
|
||||||
TypeBox {
|
LocBox {
|
||||||
inner: Ref {
|
inner: Ref {
|
||||||
inner: Owned(
|
inner: Owned(
|
||||||
Ident(
|
Ident(
|
||||||
|
@ -250,7 +250,7 @@ Program {
|
||||||
Ident(
|
Ident(
|
||||||
"b",
|
"b",
|
||||||
),
|
),
|
||||||
TypeBox {
|
LocBox {
|
||||||
inner: Ref {
|
inner: Ref {
|
||||||
inner: Owned(
|
inner: Owned(
|
||||||
Ident(
|
Ident(
|
||||||
|
@ -268,7 +268,7 @@ Program {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
ret_type: Some(
|
ret_type: Some(
|
||||||
TypeBox {
|
LocBox {
|
||||||
inner: Ref {
|
inner: Ref {
|
||||||
inner: Owned(
|
inner: Owned(
|
||||||
Ident(
|
Ident(
|
||||||
|
|
|
@ -2,13 +2,13 @@ Program {
|
||||||
ast: Block(
|
ast: Block(
|
||||||
[
|
[
|
||||||
Expr(
|
Expr(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: If(
|
inner: If(
|
||||||
IfExpr {
|
IfExpr {
|
||||||
test: ExprBox {
|
test: LocBox {
|
||||||
inner: BinOp {
|
inner: BinOp {
|
||||||
typ: Gt,
|
typ: Gt,
|
||||||
left: ExprBox {
|
left: LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -24,7 +24,7 @@ Program {
|
||||||
col: 5,
|
col: 5,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: Literal(
|
inner: Literal(
|
||||||
Number(
|
Number(
|
||||||
Number {
|
Number {
|
||||||
|
|
|
@ -2,17 +2,17 @@ Program {
|
||||||
ast: Block(
|
ast: Block(
|
||||||
[
|
[
|
||||||
Expr(
|
Expr(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: ForLoop {
|
inner: ForLoop {
|
||||||
init: Statement(
|
init: Statement(
|
||||||
StatementBox {
|
LocBox {
|
||||||
inner: Let {
|
inner: Let {
|
||||||
name: Ident(
|
name: Ident(
|
||||||
"i",
|
"i",
|
||||||
),
|
),
|
||||||
typ: None,
|
typ: None,
|
||||||
val: Some(
|
val: Some(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: Literal(
|
inner: Literal(
|
||||||
Number(
|
Number(
|
||||||
Number {
|
Number {
|
||||||
|
@ -37,10 +37,10 @@ Program {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
test: ExprBox {
|
test: LocBox {
|
||||||
inner: BinOp {
|
inner: BinOp {
|
||||||
typ: Lt,
|
typ: Lt,
|
||||||
left: ExprBox {
|
left: LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -56,7 +56,7 @@ Program {
|
||||||
col: 17,
|
col: 17,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: Literal(
|
inner: Literal(
|
||||||
Number(
|
Number(
|
||||||
Number {
|
Number {
|
||||||
|
@ -79,10 +79,10 @@ Program {
|
||||||
col: 19,
|
col: 19,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
on_loop: ExprBox {
|
on_loop: LocBox {
|
||||||
inner: BinOp {
|
inner: BinOp {
|
||||||
typ: AddEq,
|
typ: AddEq,
|
||||||
left: ExprBox {
|
left: LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -98,7 +98,7 @@ Program {
|
||||||
col: 25,
|
col: 25,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: Literal(
|
inner: Literal(
|
||||||
Number(
|
Number(
|
||||||
Number {
|
Number {
|
||||||
|
@ -133,12 +133,12 @@ Program {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Expr(
|
Expr(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: WhileLoop {
|
inner: WhileLoop {
|
||||||
test: ExprBox {
|
test: LocBox {
|
||||||
inner: BinOp {
|
inner: BinOp {
|
||||||
typ: Gt,
|
typ: Gt,
|
||||||
left: ExprBox {
|
left: LocBox {
|
||||||
inner: Path(
|
inner: Path(
|
||||||
Path(
|
Path(
|
||||||
[
|
[
|
||||||
|
@ -154,7 +154,7 @@ Program {
|
||||||
col: 8,
|
col: 8,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
right: ExprBox {
|
right: LocBox {
|
||||||
inner: Literal(
|
inner: Literal(
|
||||||
Number(
|
Number(
|
||||||
Number {
|
Number {
|
||||||
|
@ -189,7 +189,7 @@ Program {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Expr(
|
Expr(
|
||||||
ExprBox {
|
LocBox {
|
||||||
inner: InfLoop {
|
inner: InfLoop {
|
||||||
body: Block(
|
body: Block(
|
||||||
[],
|
[],
|
||||||
|
|
|
@ -2,7 +2,7 @@ Program {
|
||||||
ast: Block(
|
ast: Block(
|
||||||
[
|
[
|
||||||
Statement(
|
Statement(
|
||||||
StatementBox {
|
LocBox {
|
||||||
inner: Struct(
|
inner: Struct(
|
||||||
Struct {
|
Struct {
|
||||||
name: Ident(
|
name: Ident(
|
||||||
|
@ -19,7 +19,7 @@ Program {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Statement(
|
Statement(
|
||||||
StatementBox {
|
LocBox {
|
||||||
inner: Struct(
|
inner: Struct(
|
||||||
Struct {
|
Struct {
|
||||||
name: Ident(
|
name: Ident(
|
||||||
|
@ -30,7 +30,7 @@ Program {
|
||||||
Ident(
|
Ident(
|
||||||
"a",
|
"a",
|
||||||
),
|
),
|
||||||
TypeBox {
|
LocBox {
|
||||||
inner: Ref {
|
inner: Ref {
|
||||||
inner: Owned(
|
inner: Owned(
|
||||||
Ident(
|
Ident(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user