Merge pull request #1126 from aiken-lang/capture_constructors
Allow captures within constructor calls.
This commit is contained in:
commit
38252ef449
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
- **aiken**: New `-S` flag on `check` and `build` that blocks the printing of warnings but it still shows the total warning count. @rvcas
|
- **aiken**: New `-S` flag on `check` and `build` that blocks the printing of warnings but it still shows the total warning count. @rvcas
|
||||||
- **aiken-lang**: Allow types to be used as namespaces for constructors. Importing each constructor variants independently is no longer required in neither pattern-matches nor value construction. One can simply use the type name as a prefix/namespace now. @KtorZ
|
- **aiken-lang**: Allow types to be used as namespaces for constructors. Importing each constructor variants independently is no longer required in neither pattern-matches nor value construction. One can simply use the type name as a prefix/namespace now. @KtorZ
|
||||||
|
- **aiken-lang**: Allow capture on constructor calls. @KtorZ
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|
|
@ -29,24 +29,16 @@ pub fn parser(
|
||||||
.then_ignore(just(Token::Colon))
|
.then_ignore(just(Token::Colon))
|
||||||
.then(choice((
|
.then(choice((
|
||||||
r.clone(),
|
r.clone(),
|
||||||
select! {Token::DiscardName {name} => name }.validate(
|
choice((select! {Token::DiscardName {name} => name }.map_with_span(
|
||||||
|_name, span, emit| {
|
|name, span| UntypedExpr::Var {
|
||||||
emit(ParseError::expected_input_found(
|
location: span,
|
||||||
span,
|
name,
|
||||||
None,
|
|
||||||
Some(error::Pattern::Discard),
|
|
||||||
));
|
|
||||||
|
|
||||||
UntypedExpr::Var {
|
|
||||||
location: span,
|
|
||||||
name: ast::CAPTURE_VARIABLE.to_string(),
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
),
|
),)),
|
||||||
)))
|
)))
|
||||||
.map_with_span(|(label, value), span| ast::CallArg {
|
.map_with_span(|(label, value), span| ast::CallArg {
|
||||||
location: span,
|
location: span,
|
||||||
value,
|
value: Some(value),
|
||||||
label: Some(label),
|
label: Some(label),
|
||||||
}),
|
}),
|
||||||
choice((
|
choice((
|
||||||
|
@ -111,7 +103,7 @@ pub fn parser(
|
||||||
)
|
)
|
||||||
.map(|(value, name)| ast::CallArg {
|
.map(|(value, name)| ast::CallArg {
|
||||||
location: value.location(),
|
location: value.location(),
|
||||||
value,
|
value: Some(value),
|
||||||
label: Some(name),
|
label: Some(name),
|
||||||
}),
|
}),
|
||||||
))
|
))
|
||||||
|
@ -144,24 +136,16 @@ pub fn parser(
|
||||||
.or_not()
|
.or_not()
|
||||||
.then(choice((
|
.then(choice((
|
||||||
r.clone(),
|
r.clone(),
|
||||||
select! {Token::DiscardName {name} => name }.validate(
|
select! {Token::DiscardName {name} => name }.map_with_span(|name, span| {
|
||||||
|_name, span, emit| {
|
UntypedExpr::Var {
|
||||||
emit(ParseError::expected_input_found(
|
location: span,
|
||||||
span,
|
name,
|
||||||
None,
|
}
|
||||||
Some(error::Pattern::Discard),
|
}),
|
||||||
));
|
|
||||||
|
|
||||||
UntypedExpr::Var {
|
|
||||||
location: span,
|
|
||||||
name: ast::CAPTURE_VARIABLE.to_string(),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
)))
|
)))
|
||||||
.map(|(_label, value)| ast::CallArg {
|
.map(|(_label, value)| ast::CallArg {
|
||||||
location: value.location(),
|
location: value.location(),
|
||||||
value,
|
value: Some(value),
|
||||||
label: None,
|
label: None,
|
||||||
})
|
})
|
||||||
.separated_by(just(Token::Comma))
|
.separated_by(just(Token::Comma))
|
||||||
|
@ -208,11 +192,7 @@ pub fn parser(
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
UntypedExpr::Call {
|
fun.call(arguments, span)
|
||||||
arguments,
|
|
||||||
fun: Box::new(fun),
|
|
||||||
location: span,
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
name = "aiken-lang/121"
|
||||||
|
version = "0.0.0"
|
||||||
|
license = "Apache-2.0"
|
||||||
|
description = "Aiken contracts for project 'aiken-lang/121'"
|
||||||
|
|
||||||
|
[repository]
|
||||||
|
user = "aiken-lang"
|
||||||
|
project = "121"
|
||||||
|
platform = "github"
|
|
@ -0,0 +1,34 @@
|
||||||
|
pub type Foo {
|
||||||
|
i: Int,
|
||||||
|
b: Bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
const give_i: fn(Int) -> Foo = Foo { i: _, b: True }
|
||||||
|
|
||||||
|
const give_b: fn(Bool) -> Foo = Foo(1337, _)
|
||||||
|
|
||||||
|
fn foo_i(i: Int) -> fn(Bool) -> Foo {
|
||||||
|
Foo { i: i, b: _bool }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo_b(b: Bool) -> fn(Int) -> Foo {
|
||||||
|
Foo(_, b)
|
||||||
|
}
|
||||||
|
|
||||||
|
test test_1() {
|
||||||
|
let bar = foo_i(14)
|
||||||
|
and {
|
||||||
|
foo_i(42)(True) == Foo(42, True),
|
||||||
|
bar(False) == Foo { i: 14, b: False },
|
||||||
|
give_i(1337) == Foo { i: 1337, b: True },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
test test_2() {
|
||||||
|
let bar = foo_b(False)
|
||||||
|
and {
|
||||||
|
foo_b(True)(42) == Foo(42, True),
|
||||||
|
bar(14) == Foo { i: 14, b: False },
|
||||||
|
give_b(False) == Foo { i: 1337, b: False },
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue