Use rust-style type parameter syntax

This commit is contained in:
Jeff 2024-06-24 13:54:37 -04:00
parent 37d54499da
commit 97268c272e
4 changed files with 10 additions and 10 deletions

View File

@ -82,8 +82,8 @@ pub fn parser<'src>(
.at_least(1)
.collect()
.delimited_by(
just(Token::Symbol(Symbol::Pipe)),
just(Token::Symbol(Symbol::Pipe)),
just(Token::Symbol(Symbol::Less)),
just(Token::Symbol(Symbol::Greater)),
)
.or_not(),
)
@ -281,8 +281,8 @@ pub fn parser<'src>(
.allow_trailing()
.collect()
.delimited_by(
just(Token::Symbol(Symbol::Pipe)),
just(Token::Symbol(Symbol::Pipe)),
just(Token::Symbol(Symbol::Less)),
just(Token::Symbol(Symbol::Greater)),
)
.or_not(),
)

View File

@ -467,7 +467,7 @@ fn list_of_type() {
#[test]
fn function_type() {
assert_eq!(
parse(&lex("type Foo = fn |T| (x: int)").unwrap()).unwrap()[0],
parse(&lex("type Foo = fn <T> (x: int)").unwrap()).unwrap()[0],
Statement::TypeAlias(
TypeAlias::new(
Identifier::new("Foo").with_position((5, 8)),
@ -493,7 +493,7 @@ fn function_type() {
#[test]
fn function_type_with_return() {
assert_eq!(
parse(&lex("type Foo = fn |T| (x: int) -> T").unwrap()).unwrap()[0],
parse(&lex("type Foo = fn <T> (x: int) -> T").unwrap()).unwrap()[0],
Statement::TypeAlias(
TypeAlias::new(
Identifier::new("Foo").with_position((5, 8)),
@ -537,7 +537,7 @@ fn function_call() {
}
#[test]
fn function_call_with_type_arguments() {
fn function_call_with_arguments() {
assert_eq!(
parse(&lex("foobar::<str>('hi')").unwrap()).unwrap()[0],
Statement::Expression(Expression::FunctionCall(
@ -610,7 +610,7 @@ fn function() {
#[test]
fn function_with_type_arguments() {
assert_eq!(
parse(&lex("fn |T, U| (x: T, y: U) -> T { x }").unwrap()).unwrap()[0],
parse(&lex("fn <T, U> (x: T, y: U) -> T { x }").unwrap()).unwrap()[0],
Statement::Expression(Expression::Value(
ValueNode::function(
Some(vec![Identifier::new("T"), Identifier::new("U"),]),

View File

@ -6,7 +6,7 @@ fn function_call_with_type_argument() {
interpret(
"test",
"
foobar = fn |T| (x: T) -> T { x }
foobar = fn <T> (x: T) -> T { x }
foobar::<int>(42)
",
),

View File

@ -1,5 +1,5 @@
json = {
parse = fn |T| (input: str) -> T {
parse = fn <T> (input: str) -> T {
__JSON_PARSE__::<T>(input)
}
}