diff --git a/examples/src/AnonymousObjects.jetl b/examples/src/AnonymousObjects.jetl new file mode 100644 index 00000000000..1419ef768c1 --- /dev/null +++ b/examples/src/AnonymousObjects.jetl @@ -0,0 +1,21 @@ +addMouseListener(object MouseAdapter() { + + private var clickCount = 0; + + override fun mouseClicked(e : MouseEvent) { + clickCount++; + if (clickCount > 3) GOD.sendMessage(GodMEssages.TOO_MANY_CLICKS); + } +}) + +enum class GodMessages { + TOO_MANY_CLICKS + ONE_MORE_MESSAGE +} + +// Type of this variable is GOD_AnonymousClass +val GOD = object { + fun sendMessage(message : GodMEssage) = throw new RuntimeException(message.name) +}; + +addMouseListener([mouseClicked : {e => doFoo()}]); diff --git a/examples/src/Factories.jetl b/examples/src/Factories.jetl new file mode 100644 index 00000000000..0ab00bd1b0f --- /dev/null +++ b/examples/src/Factories.jetl @@ -0,0 +1,13 @@ +class ConcreteClass { + + this() {} + +} + +// Implicitly generated a factory for ConcreteClass with a no-argument factory method + +interface class IFooBarInterface { + new () { } +} + +factory \ No newline at end of file diff --git a/examples/src/LINQ.jetl b/examples/src/LINQ.jetl new file mode 100644 index 00000000000..71746b49818 --- /dev/null +++ b/examples/src/LINQ.jetl @@ -0,0 +1,2 @@ +l filter {it.x} map {it.foo} aggregate {a, b => a + b} + diff --git a/grammar/src/class.grm b/grammar/src/class.grm index c05779f0d22..3ffb4e870c4 100644 --- a/grammar/src/class.grm +++ b/grammar/src/class.grm @@ -16,7 +16,11 @@ class ("(" defaultConstructorParameter{","} ")")? (":" delegationSpecifier{","})? ("where" typeConstraint{","})? // Syntax is questionable - ("{" memberDeclaration{","} "}"? + classBody? + ; + +classBody + : ("{" memberDeclaration{","} "}" ; classModifier diff --git a/grammar/src/control.grm b/grammar/src/control.grm index b4123115631..d6cb3f0cdf6 100644 --- a/grammar/src/control.grm +++ b/grammar/src/control.grm @@ -8,6 +8,7 @@ match matchEntry : "case" pattern "=>" expression // TODO: Consider other options than "=>" + : "else" "=>" expression // TODO: keyword ; for diff --git a/grammar/src/expressions.grm b/grammar/src/expressions.grm index 7a514975c10..38cda83ca3e 100644 --- a/grammar/src/expressions.grm +++ b/grammar/src/expressions.grm @@ -8,11 +8,7 @@ expression : "null" : "this" : memberAccessExpression - : infixFunctionCall - : binOpExpression - : assignment - : unOpExpression - : castExpression + : expressionWithPrecedences : match : if : "new" constructorInvocation @@ -21,8 +17,21 @@ expression : jump ; -castExpression - : expression "as" type +expressionWithPrecedences // See the precedence table, everything associates to the left + : infixFunctionCall + : binOpExpression + : assignment + : unOpExpression + : castExpression + : typingExpression + ; + +typingExpression + : expression typingOperation type + ; + +typingOperation + : "as" : "is" : "isnot" ; binOpExpression @@ -35,14 +44,18 @@ unOpExpression ; binaryOperation // Decreasing precedence - : "*" : "/" // No % + // . + // unary + : "*" : "/" : "%" : "+" : "-" // No << >> >>> - : "<" : ">" : ">=" : "<=" : "is" : "isnot" : "in" // TODO: Check the precedence for in carefully - : "!=" : "==" : "===" + // named functions in infix form + : "<" : ">" : ">=" : "<=" : "in" // is isnot as // TODO: Check the precedence for in carefully + : "!=" : "==" : "===" : "!==" // No | & ^ ~ : "&&" : "||" + // assignments ; assignmentOperator @@ -144,4 +157,8 @@ fieldOrPropertyAccess arrayAccess : "[" expression "]" + ; + +anonymousInnerClassInstantiation + : "object" delegationSpecifier{","} classBody ; \ No newline at end of file