1
0

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

View File

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

View File

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

View File

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