Default parameters, function type examples fixed, tuples with named entries
This commit is contained in:
@@ -64,7 +64,7 @@ functionRest
|
||||
;
|
||||
|
||||
functionParameters
|
||||
: "(" (parameter{","})? ")"
|
||||
: "(" ((parameter ("=" expression)?){","})? ")" // default values
|
||||
;
|
||||
|
||||
block
|
||||
|
||||
@@ -5,6 +5,7 @@ expression
|
||||
: tupleLiteral
|
||||
: listLiteral
|
||||
: mapLiteral
|
||||
: range
|
||||
: "null"
|
||||
: "this"
|
||||
: memberAccessExpression
|
||||
@@ -86,7 +87,7 @@ typeArguments
|
||||
;
|
||||
|
||||
valueArguments
|
||||
: "(" expression{","} ")"
|
||||
: "(" (SimpleName ":")? expression{","} ")"
|
||||
;
|
||||
|
||||
infixFunctionCall
|
||||
@@ -107,10 +108,10 @@ tupleLiteral // Ambiguity when after a SimpleName (infix call). In this case (e)
|
||||
: "(" expression{","} ")"
|
||||
;
|
||||
|
||||
functionLiteral
|
||||
functionLiteral // one can use "it" as a parameter name
|
||||
: "{" SimpleName "=>" expression "}"
|
||||
: "{" functionTypeContents "=>" expression "}"
|
||||
: "{" "(" parameter{","} ")" "=>" expression "}"
|
||||
: "{" "(" SimpleName{","} ")" "=>" expression "}"
|
||||
: "{" "(" parameter{","} ")" (":" type)? "=>" expression "}"
|
||||
;
|
||||
|
||||
constructorInvocation
|
||||
@@ -141,6 +142,10 @@ literalConstant
|
||||
: MultiLineStringTemplate
|
||||
;
|
||||
|
||||
range
|
||||
: "[" expression ".." expression "]"
|
||||
;
|
||||
|
||||
memberAccessExpression
|
||||
: (expression ".")? memberAccess
|
||||
;
|
||||
@@ -178,4 +183,4 @@ factoryMethod
|
||||
: accessModifier? SimpleName typeParameters? functionParameters functionBody
|
||||
;
|
||||
|
||||
*/
|
||||
*/
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
/*
|
||||
|
||||
Foo<Bar<X>, T, Object> // user type
|
||||
{A, Object => Foo} // function type
|
||||
{ => Foo} // function with no arguments
|
||||
{(A, Object) : Foo} // function type
|
||||
{ () : Foo} // function with no arguments
|
||||
(A, B, C) // tuple type
|
||||
(a : A, b : B) // tuple type with named entries
|
||||
() // 0-ary tuple type (Unit)
|
||||
|
||||
*/
|
||||
@@ -33,7 +34,8 @@ functionTypeContents
|
||||
;
|
||||
|
||||
tupleType
|
||||
: "(" type{","} ")"
|
||||
: "(" type{","}? ")"
|
||||
: "(" parameter{","} ")" // tuple with named entries, the names do not affect assignment compatibility
|
||||
;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user