Wrap all Expression nodes in Meta<Expression>
This commit is contained in:
parent
95fe1941a1
commit
f041cc17d2
2
TODO.md
2
TODO.md
@ -1,5 +1,7 @@
|
|||||||
#Typechecking Notes
|
#Typechecking Notes
|
||||||
|
|
||||||
|
IS BOX SYNTAX READY????
|
||||||
|
|
||||||
(cf. cardelli paper)
|
(cf. cardelli paper)
|
||||||
|
|
||||||
Given a length function def:
|
Given a length function def:
|
||||||
|
@ -59,7 +59,7 @@ pub enum Declaration {
|
|||||||
name: Rc<String>,
|
name: Rc<String>,
|
||||||
constant: bool,
|
constant: bool,
|
||||||
type_anno: Option<TypeIdentifier>,
|
type_anno: Option<TypeIdentifier>,
|
||||||
expr: Expression,
|
expr: Meta<Expression>,
|
||||||
},
|
},
|
||||||
Impl {
|
Impl {
|
||||||
type_name: TypeIdentifier,
|
type_name: TypeIdentifier,
|
||||||
@ -121,22 +121,22 @@ pub enum ExpressionKind {
|
|||||||
Value(Rc<String>),
|
Value(Rc<String>),
|
||||||
NamedStruct {
|
NamedStruct {
|
||||||
name: Rc<String>,
|
name: Rc<String>,
|
||||||
fields: Vec<(Rc<String>, Expression)>,
|
fields: Vec<(Rc<String>, Meta<Expression>)>,
|
||||||
},
|
},
|
||||||
Call {
|
Call {
|
||||||
f: Box<Expression>,
|
f: Box<Meta<Expression>>,
|
||||||
arguments: Vec<Meta<Expression>>,
|
arguments: Vec<Meta<Expression>>,
|
||||||
},
|
},
|
||||||
Index {
|
Index {
|
||||||
indexee: Box<Expression>,
|
indexee: Box<Meta<Expression>>,
|
||||||
indexers: Vec<Expression>,
|
indexers: Vec<Meta<Expression>>,
|
||||||
},
|
},
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: Box<Discriminator>,
|
discriminator: Box<Discriminator>,
|
||||||
body: Box<IfExpressionBody>,
|
body: Box<IfExpressionBody>,
|
||||||
},
|
},
|
||||||
WhileExpression {
|
WhileExpression {
|
||||||
condition: Option<Box<Expression>>,
|
condition: Option<Box<Meta<Expression>>>,
|
||||||
body: Block,
|
body: Block,
|
||||||
},
|
},
|
||||||
ForExpression {
|
ForExpression {
|
||||||
@ -148,7 +148,7 @@ pub enum ExpressionKind {
|
|||||||
type_anno: Option<TypeIdentifier>,
|
type_anno: Option<TypeIdentifier>,
|
||||||
body: Block,
|
body: Block,
|
||||||
},
|
},
|
||||||
ListLiteral(Vec<Expression>),
|
ListLiteral(Vec<Meta<Expression>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
@ -205,11 +205,11 @@ pub enum PatternLiteral {
|
|||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub struct Enumerator {
|
pub struct Enumerator {
|
||||||
pub id: Rc<String>,
|
pub id: Rc<String>,
|
||||||
pub generator: Expression,
|
pub generator: Meta<Expression>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum ForBody {
|
pub enum ForBody {
|
||||||
MonadicReturn(Expression),
|
MonadicReturn(Meta<Expression>),
|
||||||
StatementBlock(Block),
|
StatementBlock(Block),
|
||||||
}
|
}
|
||||||
|
@ -451,7 +451,7 @@ impl Parser {
|
|||||||
};
|
};
|
||||||
|
|
||||||
expect!(self, Operator(ref o) if **o == "=");
|
expect!(self, Operator(ref o) if **o == "=");
|
||||||
let expr = self.expression()?;
|
let expr = self.expression()?.into();
|
||||||
|
|
||||||
Ok(Declaration::Binding { name, constant, type_anno, expr })
|
Ok(Declaration::Binding { name, constant, type_anno, expr })
|
||||||
}
|
}
|
||||||
@ -590,7 +590,7 @@ impl Parser {
|
|||||||
while let LParen = self.token_handler.peek_kind() {
|
while let LParen = self.token_handler.peek_kind() {
|
||||||
let arguments = delimited!(self, LParen, expression, Comma, RParen);
|
let arguments = delimited!(self, LParen, expression, Comma, RParen);
|
||||||
let arguments = arguments.into_iter().map(|s| Meta::new(s)).collect();
|
let arguments = arguments.into_iter().map(|s| Meta::new(s)).collect();
|
||||||
expr = Expression(ExpressionKind::Call { f: bx!(expr), arguments }, None); //TODO none is incorrect
|
expr = Expression(ExpressionKind::Call { f: bx!(expr.into()), arguments }, None); //TODO none is incorrect
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(expr)
|
Ok(expr)
|
||||||
@ -600,9 +600,10 @@ impl Parser {
|
|||||||
fn index_expr(&mut self) -> ParseResult<Expression> {
|
fn index_expr(&mut self) -> ParseResult<Expression> {
|
||||||
let primary = self.primary()?;
|
let primary = self.primary()?;
|
||||||
Ok(if let LSquareBracket = self.token_handler.peek_kind() {
|
Ok(if let LSquareBracket = self.token_handler.peek_kind() {
|
||||||
let indexers = delimited!(self, LSquareBracket, expression, Comma, RSquareBracket);
|
let indexers = delimited!(self, LSquareBracket, expression, Comma, RSquareBracket)
|
||||||
|
.into_iter().map(|ex| ex.into()).collect();
|
||||||
Expression(ExpressionKind::Index {
|
Expression(ExpressionKind::Index {
|
||||||
indexee: bx!(Expression(primary.0, None)),
|
indexee: bx!(Expression(primary.0, None).into()),
|
||||||
indexers,
|
indexers,
|
||||||
}, None)
|
}, None)
|
||||||
} else {
|
} else {
|
||||||
@ -627,7 +628,8 @@ impl Parser {
|
|||||||
|
|
||||||
#[recursive_descent_method]
|
#[recursive_descent_method]
|
||||||
fn list_expr(&mut self) -> ParseResult<Expression> {
|
fn list_expr(&mut self) -> ParseResult<Expression> {
|
||||||
let exprs = delimited!(self, LSquareBracket, expression, Comma, RSquareBracket);
|
let exprs = delimited!(self, LSquareBracket, expression, Comma, RSquareBracket)
|
||||||
|
.into_iter().map(|ex| ex.into()).collect();
|
||||||
Ok(Expression(ExpressionKind::ListLiteral(exprs), None))
|
Ok(Expression(ExpressionKind::ListLiteral(exprs), None))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -692,8 +694,11 @@ impl Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[recursive_descent_method]
|
#[recursive_descent_method]
|
||||||
fn record_block(&mut self) -> ParseResult<Vec<(Rc<String>, Expression)>> {
|
fn record_block(&mut self) -> ParseResult<Vec<(Rc<String>, Meta<Expression>)>> {
|
||||||
Ok(delimited!(self, LCurlyBrace, record_entry, Comma, RCurlyBrace))
|
Ok(
|
||||||
|
delimited!(self, LCurlyBrace, record_entry, Comma, RCurlyBrace)
|
||||||
|
.into_iter().map(|(s, ex)| (s, ex.into())).collect()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[recursive_descent_method]
|
#[recursive_descent_method]
|
||||||
@ -926,7 +931,7 @@ impl Parser {
|
|||||||
self.restrictions.no_struct_literal = true;
|
self.restrictions.no_struct_literal = true;
|
||||||
let x = self.while_cond();
|
let x = self.while_cond();
|
||||||
self.restrictions.no_struct_literal = false;
|
self.restrictions.no_struct_literal = false;
|
||||||
x?.map(|expr| bx!(expr))
|
x?.map(|expr| bx!(expr.into()))
|
||||||
};
|
};
|
||||||
let body = self.block()?;
|
let body = self.block()?;
|
||||||
Ok(Expression(WhileExpression {condition, body}, None))
|
Ok(Expression(WhileExpression {condition, body}, None))
|
||||||
@ -962,7 +967,7 @@ impl Parser {
|
|||||||
fn enumerator(&mut self) -> ParseResult<Enumerator> {
|
fn enumerator(&mut self) -> ParseResult<Enumerator> {
|
||||||
let id = self.identifier()?;
|
let id = self.identifier()?;
|
||||||
expect!(self, Operator(ref c) if **c == "<-");
|
expect!(self, Operator(ref c) if **c == "<-");
|
||||||
let generator = self.expression()?;
|
let generator = self.expression()?.into();
|
||||||
Ok(Enumerator { id, generator })
|
Ok(Enumerator { id, generator })
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -977,7 +982,7 @@ impl Parser {
|
|||||||
},
|
},
|
||||||
Keyword(Kw::Return) => {
|
Keyword(Kw::Return) => {
|
||||||
self.token_handler.next();
|
self.token_handler.next();
|
||||||
MonadicReturn(self.expression()?)
|
MonadicReturn(self.expression()?.into())
|
||||||
},
|
},
|
||||||
_ => return ParseError::new_with_token("for expressions must end in a block or 'return'", tok),
|
_ => return ParseError::new_with_token("for expressions must end in a block or 'return'", tok),
|
||||||
})
|
})
|
||||||
@ -1157,6 +1162,8 @@ mod parse_tests {
|
|||||||
|
|
||||||
macro_rules! ex {
|
macro_rules! ex {
|
||||||
($expr_type:expr) => { Expression($expr_type, None) };
|
($expr_type:expr) => { Expression($expr_type, None) };
|
||||||
|
(m $expr_type:expr) => { Meta::new(Expression($expr_type, None)) };
|
||||||
|
(m $expr_type:expr, $type_anno:expr) => { Meta::new(Expression($expr_type, Some($type_anno))) };
|
||||||
(s $expr_text:expr) => {
|
(s $expr_text:expr) => {
|
||||||
{
|
{
|
||||||
let tokens: Vec<crate::tokenizing::Token> = tokenize($expr_text);
|
let tokens: Vec<crate::tokenizing::Token> = tokenize($expr_text);
|
||||||
@ -1259,12 +1266,20 @@ mod parse_tests {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
parse_test!("a[b,c]", AST(vec![exst!(Index { indexee: bx!(ex!(val!("a"))), indexers: vec![ex!(val!("b")), ex!(val!("c"))]} )]));
|
parse_test!("a[b,c]", AST(vec![exst!(Index { indexee: bx!(ex!(m val!("a"))), indexers: vec![ex!(m val!("b")), ex!(m val!("c"))]} )]));
|
||||||
|
|
||||||
parse_test!("None", AST(vec![exst!(val!("None"))]));
|
parse_test!("None", AST(vec![exst!(val!("None"))]));
|
||||||
parse_test!("Pandas { a: x + y }", AST(vec![
|
parse_test!("Pandas { a: x + y }", AST(vec![
|
||||||
exst!(NamedStruct { name: rc!(Pandas), fields: vec![(rc!(a), ex!(binexp!("+", val!("x"), val!("y"))))]})
|
exst!(NamedStruct { name: rc!(Pandas), fields: vec![(rc!(a), ex!(m binexp!("+", val!("x"), val!("y"))))]})
|
||||||
]));
|
]));
|
||||||
|
parse_test! { "Pandas { a: n, b: q, }",
|
||||||
|
AST(vec![
|
||||||
|
exst!(NamedStruct { name: rc!(Pandas), fields:
|
||||||
|
vec![(rc!(a), ex!(m val!("n"))), (rc!(b), ex!(m val!("q")))]
|
||||||
|
}
|
||||||
|
)
|
||||||
|
])
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1287,9 +1302,9 @@ mod parse_tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn parsing_functions() {
|
fn parsing_functions() {
|
||||||
parse_test!("fn oi()", AST(vec![Meta::new(Declaration(FuncSig(Signature { name: rc!(oi), operator: false, params: vec![], type_anno: None })))]));
|
parse_test!("fn oi()", AST(vec![Meta::new(Declaration(FuncSig(Signature { name: rc!(oi), operator: false, params: vec![], type_anno: None })))]));
|
||||||
parse_test!("oi()", AST(vec![exst!(Call { f: bx!(ex!(val!("oi"))), arguments: vec![] })]));
|
parse_test!("oi()", AST(vec![exst!(Call { f: bx!(ex!(m val!("oi"))), arguments: vec![] })]));
|
||||||
parse_test!("oi(a, 2 + 2)", AST(vec![exst!(Call
|
parse_test!("oi(a, 2 + 2)", AST(vec![exst!(Call
|
||||||
{ f: bx!(ex!(val!("oi"))),
|
{ f: bx!(ex!(m val!("oi"))),
|
||||||
arguments: vec![ex!(val!("a")).into(), ex!(binexp!("+", NatLiteral(2), NatLiteral(2))).into()]
|
arguments: vec![ex!(val!("a")).into(), ex!(binexp!("+", NatLiteral(2), NatLiteral(2))).into()]
|
||||||
})]));
|
})]));
|
||||||
parse_error!("a(b,,c)");
|
parse_error!("a(b,,c)");
|
||||||
@ -1302,10 +1317,10 @@ mod parse_tests {
|
|||||||
|
|
||||||
parse_test!("fn a(x) { x() }", AST(vec![Meta::new(Declaration(
|
parse_test!("fn a(x) { x() }", AST(vec![Meta::new(Declaration(
|
||||||
FuncDecl(Signature { name: rc!(a), operator: false, params: vec![(rc!(x),None)], type_anno: None },
|
FuncDecl(Signature { name: rc!(a), operator: false, params: vec![(rc!(x),None)], type_anno: None },
|
||||||
vec![exst!(Call { f: bx!(ex!(val!("x"))), arguments: vec![] })])))]));
|
vec![exst!(Call { f: bx!(ex!(m val!("x"))), arguments: vec![] })])))]));
|
||||||
parse_test!("fn a(x) {\n x() }", AST(vec![Meta::new(Declaration(
|
parse_test!("fn a(x) {\n x() }", AST(vec![Meta::new(Declaration(
|
||||||
FuncDecl(Signature { name: rc!(a), operator: false, params: vec![(rc!(x),None)], type_anno: None },
|
FuncDecl(Signature { name: rc!(a), operator: false, params: vec![(rc!(x),None)], type_anno: None },
|
||||||
vec![exst!(Call { f: bx!(ex!(val!("x"))), arguments: vec![] })])))]));
|
vec![exst!(Call { f: bx!(ex!(m val!("x"))), arguments: vec![] })])))]));
|
||||||
|
|
||||||
let multiline = r#"
|
let multiline = r#"
|
||||||
fn a(x) {
|
fn a(x) {
|
||||||
@ -1314,7 +1329,7 @@ fn a(x) {
|
|||||||
"#;
|
"#;
|
||||||
parse_test!(multiline, AST(vec![Meta::new(Declaration(
|
parse_test!(multiline, AST(vec![Meta::new(Declaration(
|
||||||
FuncDecl(Signature { name: rc!(a), operator: false, params: vec![(rc!(x),None)], type_anno: None },
|
FuncDecl(Signature { name: rc!(a), operator: false, params: vec![(rc!(x),None)], type_anno: None },
|
||||||
vec![exst!(Call { f: bx!(ex!(val!("x"))), arguments: vec![] })])))]));
|
vec![exst!(Call { f: bx!(ex!(m val!("x"))), arguments: vec![] })])))]));
|
||||||
let multiline2 = r#"
|
let multiline2 = r#"
|
||||||
fn a(x) {
|
fn a(x) {
|
||||||
|
|
||||||
@ -1374,11 +1389,11 @@ fn a(x) {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parsing_bindings() {
|
fn parsing_bindings() {
|
||||||
parse_test!("let mut a = 10", AST(vec![Meta::new(Declaration(Binding { name: rc!(a), constant: false, type_anno: None, expr: ex!(NatLiteral(10)) } ))]));
|
parse_test!("let mut a = 10", AST(vec![Meta::new(Declaration(Binding { name: rc!(a), constant: false, type_anno: None, expr: ex!(m NatLiteral(10)) } ))]));
|
||||||
parse_test!("let a = 2 + 2", AST(vec![Meta::new(Declaration(Binding { name: rc!(a), constant: true, type_anno: None, expr: ex!(binexp!("+", NatLiteral(2), NatLiteral(2))) }) )]));
|
parse_test!("let a = 2 + 2", AST(vec![Meta::new(Declaration(Binding { name: rc!(a), constant: true, type_anno: None, expr: ex!(m binexp!("+", NatLiteral(2), NatLiteral(2))) }) )]));
|
||||||
parse_test!("let a: Nat = 2 + 2", AST(vec![Meta::new(Declaration(
|
parse_test!("let a: Nat = 2 + 2", AST(vec![Meta::new(Declaration(
|
||||||
Binding { name: rc!(a), constant: true, type_anno: Some(Singleton(TypeSingletonName { name: rc!(Nat), params: vec![] })),
|
Binding { name: rc!(a), constant: true, type_anno: Some(Singleton(TypeSingletonName { name: rc!(Nat), params: vec![] })),
|
||||||
expr: ex!(binexp!("+", NatLiteral(2), NatLiteral(2))) }
|
expr: Meta::new(ex!(binexp!("+", NatLiteral(2), NatLiteral(2)))) }
|
||||||
))]));
|
))]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1388,11 +1403,11 @@ fn a(x) {
|
|||||||
"if a() then { b(); c() }", AST(vec![exst!(
|
"if a() then { b(); c() }", AST(vec![exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx! {
|
discriminator: bx! {
|
||||||
Discriminator::Simple(ex!(Call { f: bx!(ex!(val!("a"))), arguments: vec![]}))
|
Discriminator::Simple(ex!(Call { f: bx!(ex!(m val!("a"))), arguments: vec![]}))
|
||||||
},
|
},
|
||||||
body: bx! {
|
body: bx! {
|
||||||
IfExpressionBody::SimpleConditional(
|
IfExpressionBody::SimpleConditional(
|
||||||
vec![exst!(Call { f: bx!(ex!(val!("b"))), arguments: vec![]}), exst!(Call { f: bx!(ex!(val!("c"))), arguments: vec![] })],
|
vec![exst!(Call { f: bx!(ex!(m val!("b"))), arguments: vec![]}), exst!(Call { f: bx!(ex!(m val!("c"))), arguments: vec![] })],
|
||||||
None
|
None
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -1404,11 +1419,11 @@ fn a(x) {
|
|||||||
"if a() then { b(); c() } else { q }", AST(vec![exst!(
|
"if a() then { b(); c() } else { q }", AST(vec![exst!(
|
||||||
IfExpression {
|
IfExpression {
|
||||||
discriminator: bx! {
|
discriminator: bx! {
|
||||||
Discriminator::Simple(ex!(Call { f: bx!(ex!(val!("a"))), arguments: vec![]}))
|
Discriminator::Simple(ex!(Call { f: bx!(ex!(m val!("a"))), arguments: vec![]}))
|
||||||
},
|
},
|
||||||
body: bx! {
|
body: bx! {
|
||||||
IfExpressionBody::SimpleConditional(
|
IfExpressionBody::SimpleConditional(
|
||||||
vec![exst!(Call { f: bx!(ex!(val!("b"))), arguments: vec![]}), exst!(Call { f: bx!(ex!(val!("c"))), arguments: vec![] })],
|
vec![exst!(Call { f: bx!(ex!(m val!("b"))), arguments: vec![]}), exst!(Call { f: bx!(ex!(m val!("c"))), arguments: vec![] })],
|
||||||
Some(
|
Some(
|
||||||
vec![exst!(val!("q"))],
|
vec![exst!(val!("q"))],
|
||||||
)
|
)
|
||||||
@ -1508,7 +1523,7 @@ fn a(x) {
|
|||||||
parse_test!("let a = b : Int", AST(vec![
|
parse_test!("let a = b : Int", AST(vec![
|
||||||
Meta::new(
|
Meta::new(
|
||||||
Declaration(Binding { name: rc!(a), constant: true, type_anno: None, expr:
|
Declaration(Binding { name: rc!(a), constant: true, type_anno: None, expr:
|
||||||
Expression(val!("b"), Some(ty!("Int"))) }))]));
|
ex!(m val!("b"), ty!("Int")) }))]));
|
||||||
|
|
||||||
parse_test!("a : Int", AST(vec![
|
parse_test!("a : Int", AST(vec![
|
||||||
exst!(val!("a"), ty!("Int"))
|
exst!(val!("a"), ty!("Int"))
|
||||||
@ -1547,7 +1562,7 @@ fn a(x) {
|
|||||||
]));
|
]));
|
||||||
|
|
||||||
parse_test!(r#"\(x){y}(1)"#, AST(vec![
|
parse_test!(r#"\(x){y}(1)"#, AST(vec![
|
||||||
exst!(Call { f: bx!(ex!(
|
exst!(Call { f: bx!(ex!(m
|
||||||
Lambda {
|
Lambda {
|
||||||
params: vec![(rc!(x), None)],
|
params: vec![(rc!(x), None)],
|
||||||
type_anno: None,
|
type_anno: None,
|
||||||
@ -1594,7 +1609,7 @@ fn a(x) {
|
|||||||
exst!(s r"fn wahoo() { let a = 10; \(x) { x + a } }"),
|
exst!(s r"fn wahoo() { let a = 10; \(x) { x + a } }"),
|
||||||
exst! {
|
exst! {
|
||||||
Call {
|
Call {
|
||||||
f: bx!(ex!(Call { f: bx!(ex!(val!("wahoo"))), arguments: vec![] })),
|
f: bx!(ex!(m Call { f: bx!(ex!(m val!("wahoo"))), arguments: vec![] })),
|
||||||
arguments: vec![ex!(s "3").into()],
|
arguments: vec![ex!(s "3").into()],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1606,7 +1621,7 @@ fn a(x) {
|
|||||||
fn list_literals() {
|
fn list_literals() {
|
||||||
parse_test! {
|
parse_test! {
|
||||||
"[1,2]", AST(vec![
|
"[1,2]", AST(vec![
|
||||||
exst!(ListLiteral(vec![ex!(NatLiteral(1)), ex!(NatLiteral(2))]))])
|
exst!(ListLiteral(vec![ex!(m NatLiteral(1)), ex!(m NatLiteral(2))]))])
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1619,7 +1634,7 @@ fn a(x) {
|
|||||||
|
|
||||||
parse_test! {
|
parse_test! {
|
||||||
"while a == b { }", AST(vec![
|
"while a == b { }", AST(vec![
|
||||||
exst!(WhileExpression { condition: Some(bx![ex![binexp!("==", val!("a"), val!("b"))]]), body: vec![] })])
|
exst!(WhileExpression { condition: Some(bx![ex![m binexp!("==", val!("a"), val!("b"))]]), body: vec![] })])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1628,14 +1643,14 @@ fn a(x) {
|
|||||||
parse_test! {
|
parse_test! {
|
||||||
"for { a <- maybeValue } return 1", AST(vec![
|
"for { a <- maybeValue } return 1", AST(vec![
|
||||||
exst!(ForExpression {
|
exst!(ForExpression {
|
||||||
enumerators: vec![Enumerator { id: rc!(a), generator: ex!(val!("maybeValue")) }],
|
enumerators: vec![Enumerator { id: rc!(a), generator: ex!(m val!("maybeValue")) }],
|
||||||
body: bx!(MonadicReturn(ex!(s "1")))
|
body: bx!(MonadicReturn(Meta::new(ex!(s "1"))))
|
||||||
})])
|
})])
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_test! {
|
parse_test! {
|
||||||
"for n <- someRange { f(n); }", AST(vec![
|
"for n <- someRange { f(n); }", AST(vec![
|
||||||
exst!(ForExpression { enumerators: vec![Enumerator { id: rc!(n), generator: ex!(val!("someRange"))}],
|
exst!(ForExpression { enumerators: vec![Enumerator { id: rc!(n), generator: ex!(m val!("someRange"))}],
|
||||||
body: bx!(ForBody::StatementBlock(vec![exst!(s "f(n)")]))
|
body: bx!(ForBody::StatementBlock(vec![exst!(s "f(n)")]))
|
||||||
})])
|
})])
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ impl Expression {
|
|||||||
_ => Expr::Val(name.clone()),
|
_ => Expr::Val(name.clone()),
|
||||||
},
|
},
|
||||||
Call { f, arguments } => Expr::Call {
|
Call { f, arguments } => Expr::Call {
|
||||||
f: Box::new(f.reduce(symbol_table)),
|
f: Box::new(f.node().reduce(symbol_table)),
|
||||||
args: arguments.iter().map(|arg| arg.node().reduce(symbol_table)).collect(),
|
args: arguments.iter().map(|arg| arg.node().reduce(symbol_table)).collect(),
|
||||||
},
|
},
|
||||||
TupleLiteral(exprs) => Expr::Tuple(exprs.iter().map(|e| e.node().reduce(symbol_table)).collect()),
|
TupleLiteral(exprs) => Expr::Tuple(exprs.iter().map(|e| e.node().reduce(symbol_table)).collect()),
|
||||||
@ -358,7 +358,7 @@ impl Declaration {
|
|||||||
use self::Declaration::*;
|
use self::Declaration::*;
|
||||||
use crate::ast::Signature;
|
use crate::ast::Signature;
|
||||||
match self {
|
match self {
|
||||||
Binding {name, constant, expr, .. } => Stmt::Binding { name: name.clone(), constant: *constant, expr: expr.reduce(symbol_table) },
|
Binding {name, constant, expr, .. } => Stmt::Binding { name: name.clone(), constant: *constant, expr: expr.node().reduce(symbol_table) },
|
||||||
FuncDecl(Signature { name, params, .. }, statements) => Stmt::PreBinding {
|
FuncDecl(Signature { name, params, .. }, statements) => Stmt::PreBinding {
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
func: Func::UserDefined {
|
func: Func::UserDefined {
|
||||||
|
@ -227,7 +227,7 @@ impl<'a> TypeContext<'a> {
|
|||||||
use self::Declaration::*;
|
use self::Declaration::*;
|
||||||
match decl {
|
match decl {
|
||||||
Binding { name, expr, .. } => {
|
Binding { name, expr, .. } => {
|
||||||
let ty = self.expr(expr)?;
|
let ty = self.expr(expr.node())?;
|
||||||
self.variable_map.insert(name.clone(), ty);
|
self.variable_map.insert(name.clone(), ty);
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
|
Loading…
Reference in New Issue
Block a user