Default parameters, function type examples fixed, tuples with named entries

This commit is contained in:
Andrey Breslav
2010-11-25 16:51:30 +03:00
parent 73b12271c0
commit dd49fc6ce2
8 changed files with 84 additions and 18 deletions
+1 -1
View File
@@ -64,7 +64,7 @@ functionRest
;
functionParameters
: "(" (parameter{","})? ")"
: "(" ((parameter ("=" expression)?){","})? ")" // default values
;
block
+10 -5
View File
@@ -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
;
*/
*/
+5 -3
View File
@@ -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
;