Skip to content

Commit

Permalink
lalrpop error
Browse files Browse the repository at this point in the history
  • Loading branch information
Storyyeller committed May 12, 2024
1 parent d09c203 commit 502da7a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ pub enum Expr {
Record(Option<Box<Expr>>, Vec<(Spanned<String>, Box<Expr>)>, Span),
RefGet(Spanned<Box<Expr>>),
RefSet(Spanned<Box<Expr>>, Box<Expr>),
Seq(Box<Expr>, Box<Expr>),
Typed(Box<Expr>, TypeExpr),
Variable(Spanned<String>),
}
Expand Down
5 changes: 5 additions & 0 deletions src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ fn compile(ctx: &mut ModuleBuilder, expr: &ast::Expr) -> js::Expr {
let rhs = compile(ctx, rhs_expr);
js::assign(js::field(lhs, "$p".to_string()), rhs)
}
ast::Expr::Seq(lhs_expr, rhs_expr) => {
let lhs = compile(ctx, lhs_expr);
let rhs = compile(ctx, rhs_expr);
js::comma_pair(lhs, rhs)
}
ast::Expr::Typed(expr, _) => compile(ctx, expr),
ast::Expr::Variable((name, _)) => ctx.bindings.get(name).unwrap().clone(),
}
Expand Down
30 changes: 17 additions & 13 deletions src/grammar.lalr
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ NewRef: ast::Expr = {

CallExpr = {
RefExpr,
Call,
Case,
NewRef,
//Call,
//Case,
//NewRef,
}
//////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -275,15 +275,15 @@ CmpOp: ast::Expr = {

MultExpr = {
CallExpr,
MultOp,
//MultOp,
}
AddExpr = {
MultExpr,
AddOp,
//AddOp,
}
CompareExpr = {
AddExpr,
CmpOp,
//CmpOp,
}
//////////////////////////////////////////////////////////////////////

Expand All @@ -296,22 +296,22 @@ LetPattern: ast::LetPattern = {
<Ident> => ast::LetPattern::Var(<>),
"{" <SepList<KeyPairPattern, ";">> "}" => ast::LetPattern::Record(<>),
}
FuncSub = "fun" <LetPattern> "->" <Box<Expr>>;
FuncSub = "fun" <LetPattern> "->" <Box<NoSemiExpr>>;
FuncDef: ast::Expr = {
Spanned<FuncSub> => ast::Expr::FuncDef(<>),
}


If: ast::Expr = {
"if" <Spanned<Box<Expr>>> "then" <Box<Expr>> "else" <Box<Expr>> => ast::Expr::If(<>),
"if" <Spanned<Box<Expr>>> "then" <Box<Expr>> "else" <Box<NoSemiExpr>> => ast::Expr::If(<>),
}


LetLHS = {
"let" <Ident> "=" <Box<Expr>>,
"let" <Ident> "=" <Box<NoSemiExpr>>,
}
LetRHS = {
"in" <Box<Expr>>,
"in" <Box<NoSemiExpr>>,
}
Let: ast::Expr = {
<LetLHS> <LetRHS> => ast::Expr::Let(<>),
Expand Down Expand Up @@ -346,12 +346,12 @@ Match: ast::Expr = {


RefSet: ast::Expr = {
<Spanned<Box<CallExpr>>> ":=" <Box<Expr>> => ast::Expr::RefSet(<>)
<Spanned<Box<CallExpr>>> ":=" <Box<NoSemiExpr>> => ast::Expr::RefSet(<>)
}



Expr = {
NoSemiExpr = {
CompareExpr,
FuncDef,
If,
Expand All @@ -360,14 +360,18 @@ Expr = {
Match,
RefSet,
}
Expr = {
<Box<NoSemiExpr>> ";" <Box<NoSemiExpr>> => ast::Expr::Seq(<>),
<NoSemiExpr>,
}
//////////////////////////////////////////////////////////////////////



TopLevelItem: ast::TopLevel = {
<LetLHS> => ast::TopLevel::LetDef(<>),
<LetRecLHS> => ast::TopLevel::LetRecDef(<>),
<Expr> => ast::TopLevel::Expr(<>),
<NoSemiExpr> => ast::TopLevel::Expr(<>),
}

pub Script = {
Expand Down
5 changes: 5 additions & 0 deletions src/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,11 @@ fn check_expr(engine: &mut TypeCheckerCore, bindings: &mut Bindings, expr: &ast:
engine.flow(lhs_type, bound)?;
Ok(rhs_type)
}
Seq(lhs_expr, rhs_expr) => {
let _lhs_type = check_expr(engine, bindings, lhs_expr)?;
let rhs_type = check_expr(engine, bindings, rhs_expr)?;
Ok(rhs_type)
}
Typed(expr, sig) => {
let expr_type = check_expr(engine, bindings, expr)?;
let sig_type = parse_type_signature(engine, sig)?;
Expand Down

0 comments on commit 502da7a

Please sign in to comment.