Matches reorganized
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
class Pair(x : Int, y : Int) {
|
class Pair(x : Int, y : Int) {
|
||||||
class object {
|
class object {
|
||||||
fun copy(from : Pair, x : int = from.x, y : Int = from.y) = new Pair(x, y)
|
fun copy(from : Pair, x : Int = from.x, y : Int = from.y) = new Pair(x, y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// One can say:
|
// One can say:
|
||||||
val p = new Point(1, 2)
|
val p = new Point(1, 2)
|
||||||
val p1 = Point.Copy(p, x : 2)
|
val p1 = Point.Copy(p, x = 2)
|
||||||
val p2 = Point.Copy(p1, y : -1)
|
val p2 = Point.Copy(p1, y = -1)
|
||||||
val p3 = Point.Copy(p)
|
val p3 = Point.Copy(p)
|
||||||
|
|
||||||
// Such copy(...) methods can be automatically generated by the compiler
|
// Such copy(...) methods can be automatically generated by the compiler
|
||||||
|
|||||||
@@ -33,11 +33,16 @@ class Example(a : Foo, i : Int) : Bar(i), Some {
|
|||||||
memberDeclaration
|
memberDeclaration
|
||||||
: classObject
|
: classObject
|
||||||
: constructor
|
: constructor
|
||||||
|
: decomposer
|
||||||
: method
|
: method
|
||||||
: property
|
: property
|
||||||
: class
|
: class
|
||||||
;
|
;
|
||||||
|
|
||||||
|
decomposer // TODO: consider other names
|
||||||
|
: "decomposer" SimpleName "(" SimpleName{","} ")" // Public properties only
|
||||||
|
;
|
||||||
|
|
||||||
classObject
|
classObject
|
||||||
: "class" objectLiteral
|
: "class" objectLiteral
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ expression
|
|||||||
: expressionWithPrecedences
|
: expressionWithPrecedences
|
||||||
: match
|
: match
|
||||||
: if
|
: if
|
||||||
|
: "typeof"
|
||||||
: "new" constructorInvocation // TODO: Do we need "new"?, see factory methods
|
: "new" constructorInvocation // TODO: Do we need "new"?, see factory methods
|
||||||
: objectLiteral
|
: objectLiteral
|
||||||
: jump
|
: jump
|
||||||
@@ -87,7 +88,7 @@ typeArguments
|
|||||||
;
|
;
|
||||||
|
|
||||||
valueArguments
|
valueArguments
|
||||||
: "(" (SimpleName ":")? expression{","} ")"
|
: "(" (SimpleName "=")? expression{","} ")"
|
||||||
;
|
;
|
||||||
|
|
||||||
infixFunctionCall
|
infixFunctionCall
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ extension
|
|||||||
: completeExtension
|
: completeExtension
|
||||||
: extensionMethod
|
: extensionMethod
|
||||||
: extensionProperty
|
: extensionProperty
|
||||||
|
: extensionDecomposer
|
||||||
;
|
;
|
||||||
|
|
||||||
completeExtension
|
completeExtension
|
||||||
@@ -15,3 +16,7 @@ extensionMethod
|
|||||||
extensionProperty
|
extensionProperty
|
||||||
: accessModifier? propertyModifier? ("val" | "var") type "." propertyRest
|
: accessModifier? propertyModifier? ("val" | "var") type "." propertyRest
|
||||||
;
|
;
|
||||||
|
|
||||||
|
extensionDecomposer
|
||||||
|
: "decomposer" (type ".")? SimpleName "(" SimpleName{","} ")" // Public properties only
|
||||||
|
;
|
||||||
+17
-4
@@ -4,11 +4,24 @@ match
|
|||||||
|
|
||||||
matchEntry
|
matchEntry
|
||||||
: "case" pattern "=>" expression // TODO: Consider other options than "=>"
|
: "case" pattern "=>" expression // TODO: Consider other options than "=>"
|
||||||
: "else" "=>" expression // TODO: keyword
|
|
||||||
;
|
;
|
||||||
|
|
||||||
pattern
|
pattern
|
||||||
: SimpleName
|
: constantPattern // literal
|
||||||
: expression
|
: variablePattern // variable from the context
|
||||||
: // TODO: how to write the typeswitch?
|
: tuplePattern
|
||||||
|
: bindingPattern
|
||||||
|
: decomposerPattern // labeled components are allowed
|
||||||
|
;
|
||||||
|
|
||||||
|
tuplePattern
|
||||||
|
: "(" ((SimpleName "=")? pattern{","})? ")"
|
||||||
|
;
|
||||||
|
|
||||||
|
bindingPattern
|
||||||
|
: "?" SimpleName? (":" pattern)?
|
||||||
|
;
|
||||||
|
|
||||||
|
decomposerPattern
|
||||||
|
: userType tuplePattern?
|
||||||
;
|
;
|
||||||
Reference in New Issue
Block a user