From 4690ea2bc72d896b8f4aaca34d3a64cc76b934c7 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Thu, 25 Nov 2010 21:52:40 +0300 Subject: [PATCH] Matches reorganized --- examples/src/UpdfateOperation.jetl | 6 +++--- grammar/src/class_members.grm | 5 +++++ grammar/src/expressions.grm | 3 ++- grammar/src/extension.grm | 5 +++++ grammar/src/match.grm | 21 +++++++++++++++++---- 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/examples/src/UpdfateOperation.jetl b/examples/src/UpdfateOperation.jetl index f5c05579d8b..4d2aa3586f5 100644 --- a/examples/src/UpdfateOperation.jetl +++ b/examples/src/UpdfateOperation.jetl @@ -1,13 +1,13 @@ class Pair(x : Int, y : Int) { 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: val p = new Point(1, 2) -val p1 = Point.Copy(p, x : 2) -val p2 = Point.Copy(p1, y : -1) +val p1 = Point.Copy(p, x = 2) +val p2 = Point.Copy(p1, y = -1) val p3 = Point.Copy(p) // Such copy(...) methods can be automatically generated by the compiler diff --git a/grammar/src/class_members.grm b/grammar/src/class_members.grm index 7f4a476c372..6aa706f2ed7 100644 --- a/grammar/src/class_members.grm +++ b/grammar/src/class_members.grm @@ -33,11 +33,16 @@ class Example(a : Foo, i : Int) : Bar(i), Some { memberDeclaration : classObject : constructor + : decomposer : method : property : class ; +decomposer // TODO: consider other names + : "decomposer" SimpleName "(" SimpleName{","} ")" // Public properties only + ; + classObject : "class" objectLiteral ; diff --git a/grammar/src/expressions.grm b/grammar/src/expressions.grm index a339a37cb3b..6928ea7ef97 100644 --- a/grammar/src/expressions.grm +++ b/grammar/src/expressions.grm @@ -12,6 +12,7 @@ expression : expressionWithPrecedences : match : if + : "typeof" : "new" constructorInvocation // TODO: Do we need "new"?, see factory methods : objectLiteral : jump @@ -87,7 +88,7 @@ typeArguments ; valueArguments - : "(" (SimpleName ":")? expression{","} ")" + : "(" (SimpleName "=")? expression{","} ")" ; infixFunctionCall diff --git a/grammar/src/extension.grm b/grammar/src/extension.grm index 2e623f7ab15..d79baa79817 100644 --- a/grammar/src/extension.grm +++ b/grammar/src/extension.grm @@ -2,6 +2,7 @@ extension : completeExtension : extensionMethod : extensionProperty + : extensionDecomposer ; completeExtension @@ -15,3 +16,7 @@ extensionMethod extensionProperty : accessModifier? propertyModifier? ("val" | "var") type "." propertyRest ; + +extensionDecomposer + : "decomposer" (type ".")? SimpleName "(" SimpleName{","} ")" // Public properties only + ; \ No newline at end of file diff --git a/grammar/src/match.grm b/grammar/src/match.grm index 4d461ebac11..9a448fed2e1 100644 --- a/grammar/src/match.grm +++ b/grammar/src/match.grm @@ -4,11 +4,24 @@ match matchEntry : "case" pattern "=>" expression // TODO: Consider other options than "=>" - : "else" "=>" expression // TODO: keyword ; pattern - : SimpleName - : expression - : // TODO: how to write the typeswitch? + : constantPattern // literal + : variablePattern // variable from the context + : tuplePattern + : bindingPattern + : decomposerPattern // labeled components are allowed + ; + +tuplePattern + : "(" ((SimpleName "=")? pattern{","})? ")" + ; + +bindingPattern + : "?" SimpleName? (":" pattern)? + ; + +decomposerPattern + : userType tuplePattern? ; \ No newline at end of file