Projections & Initial grammar
This commit is contained in:
Generated
+1
@@ -3,6 +3,7 @@
|
|||||||
<component name="ProjectModuleManager">
|
<component name="ProjectModuleManager">
|
||||||
<modules>
|
<modules>
|
||||||
<module fileurl="file://$PROJECT_DIR$/examples.iml" filepath="$PROJECT_DIR$/examples.iml" />
|
<module fileurl="file://$PROJECT_DIR$/examples.iml" filepath="$PROJECT_DIR$/examples.iml" />
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/../grammar/grammar.iml" filepath="$PROJECT_DIR$/../grammar/grammar.iml" />
|
||||||
</modules>
|
</modules>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -2,16 +2,16 @@ interface class IIterator<out T> {
|
|||||||
fun next() : T
|
fun next() : T
|
||||||
val hasNext : Boolean
|
val hasNext : Boolean
|
||||||
|
|
||||||
fun toArray(buffer : WriteOnlyArray<T>) : Int { // T is still an in-parameter
|
fun toArray(buffer : MutableArray<in T>) : Int { // T is still an in-parameter
|
||||||
return fillBuffer(buffer, 0, buffer.size)
|
return fillBuffer(buffer, 0, buffer.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toArray(buffer : WriteOnlyArray<T>, from : Int, length : Int) : Int { // T is still an in-parameter
|
fun toArray(buffer : MutableArray<in T>, from : Int, length : Int) : Int { // T is still an in-parameter
|
||||||
if (from < 0 || from > buffer.lastIndex || length < 0 || length > buffer.size - from) {
|
if (from < 0 || from > buffer.lastIndex || length < 0 || length > buffer.size - from) {
|
||||||
throw IndexOutOfBoundsException();
|
throw IndexOutOfBoundsException();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len == 0) return 0;
|
if (len == 0) return 0
|
||||||
|
|
||||||
var count = 0;
|
var count = 0;
|
||||||
for (i in [from .. from + length - 1]) {
|
for (i in [from .. from + length - 1]) {
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
|
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
internal class Example<X, T : Comparable<X>>(protected val x : Foo<X, T>, y : Some)
|
||||||
|
: Bar(x), Foo<X, T> by x, IAbstractSome by y.asAbstract()
|
||||||
|
where
|
||||||
|
T : Function<Object, Object>
|
||||||
|
{
|
||||||
|
// members
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
class
|
||||||
|
: classModifier* "class" SimpleName
|
||||||
|
("<" typeParameter{","} ">")?
|
||||||
|
("(" defaultConstructorParameter{","} ")")?
|
||||||
|
(":" delegationSpecifier{","})?
|
||||||
|
("where" typeConstraint{","})? // Syntax is questionable
|
||||||
|
("{" memberDeclaration{","} "}"?
|
||||||
|
;
|
||||||
|
|
||||||
|
classModifier
|
||||||
|
: accessModifier
|
||||||
|
: "abstract"
|
||||||
|
: "sealed"
|
||||||
|
;
|
||||||
|
|
||||||
|
delegationSpecifier
|
||||||
|
: constructorInvocation // type and constructor arguments
|
||||||
|
: explicitDelegation
|
||||||
|
;
|
||||||
|
|
||||||
|
explicitDelegation
|
||||||
|
: userType "by" expression // Syntax is questionable
|
||||||
|
;
|
||||||
|
|
||||||
|
typeParameter
|
||||||
|
: varianceAnnotation? SimpleName (":" userType)?
|
||||||
|
;
|
||||||
|
|
||||||
|
typeConstraint
|
||||||
|
: userType ":" userType
|
||||||
|
// other constraints, maybe
|
||||||
|
;
|
||||||
|
|
||||||
|
defaultConstructorParameter
|
||||||
|
: accessModifier? ("val" | "var")? parameter
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
class Example(a : Foo, i : Int) : Bar(i), Some {
|
||||||
|
// constrtuctors:
|
||||||
|
public this(a : Foo) : this(a, 0)
|
||||||
|
|
||||||
|
public this(a : Foo) : Bar(5), Some(a) {
|
||||||
|
// code
|
||||||
|
}
|
||||||
|
|
||||||
|
// functions
|
||||||
|
abstract fun foo(a : Bar)
|
||||||
|
|
||||||
|
fun foo(a : Bar) = 0
|
||||||
|
|
||||||
|
fun foo(a : Bar) = {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
fun foo(a : Bar) { // return type is Unit
|
||||||
|
|
||||||
|
// properties
|
||||||
|
val x : Int = 5
|
||||||
|
var y : Double = 7.0d
|
||||||
|
var z : String = "SDfsdf" {
|
||||||
|
get() = $z + "sdfsd"
|
||||||
|
private set(s : String) { $z = s } // TODO: allow to omit the type here?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// h5. Grammar
|
||||||
|
|
||||||
|
memberDeclaration
|
||||||
|
: constructor
|
||||||
|
: method
|
||||||
|
: property
|
||||||
|
: class //TODO : static
|
||||||
|
// : constant ???
|
||||||
|
;
|
||||||
|
|
||||||
|
constructor
|
||||||
|
: accessModifier? "this" functionParameters (":" initializers) block
|
||||||
|
;
|
||||||
|
|
||||||
|
initializers
|
||||||
|
: "this" functionArguments
|
||||||
|
: constructorInvocation // type parameters may (must?) be omitted
|
||||||
|
;
|
||||||
|
|
||||||
|
super
|
||||||
|
: "super" "<" name ">"
|
||||||
|
;
|
||||||
|
|
||||||
|
method
|
||||||
|
: methodModifier* "fun" SimpleName functionParameters (":" type)? functionBody?
|
||||||
|
;
|
||||||
|
|
||||||
|
functionParameters
|
||||||
|
: "(" (parameter{","})? ")"
|
||||||
|
;
|
||||||
|
|
||||||
|
block
|
||||||
|
: "{" statements "}"
|
||||||
|
;
|
||||||
|
|
||||||
|
functionBody
|
||||||
|
: block
|
||||||
|
: "=" expression
|
||||||
|
;
|
||||||
|
|
||||||
|
property
|
||||||
|
: propertyModifier* ("val" | "var") SimpleName (":" type)? ("=" expression)?
|
||||||
|
"{" getter? setter? "}"
|
||||||
|
;
|
||||||
|
|
||||||
|
getter
|
||||||
|
: methodModifier* "get" "(" ")" functionBody
|
||||||
|
;
|
||||||
|
|
||||||
|
setter
|
||||||
|
: methodModifier* "set" "(" parameter ")" functionBody
|
||||||
|
;
|
||||||
|
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
expression
|
||||||
|
: "new" constructorInvocation
|
||||||
|
: literalConstant
|
||||||
|
: functionLiteral
|
||||||
|
: tupleLiteral
|
||||||
|
: "null"
|
||||||
|
: binOpExpression
|
||||||
|
: unOpExpression
|
||||||
|
: name functionParameters? // ambiguity here
|
||||||
|
: FieldName
|
||||||
|
: if
|
||||||
|
// list comprehension
|
||||||
|
: jump
|
||||||
|
;
|
||||||
|
|
||||||
|
jump
|
||||||
|
: "throw" expression
|
||||||
|
: "return" expression
|
||||||
|
: "continue" SimpleName
|
||||||
|
: "break" SimpleName
|
||||||
|
// yield ?
|
||||||
|
;
|
||||||
|
|
||||||
|
tupleLiteral
|
||||||
|
: "(" expression{","} ")"
|
||||||
|
;
|
||||||
|
|
||||||
|
functionLiteral
|
||||||
|
: "{" (parameter | SimpleName)* "=>" expression "}"
|
||||||
|
;
|
||||||
|
|
||||||
|
constructorInvocation
|
||||||
|
: userType "(" expression{","} ")"
|
||||||
|
;
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
|
||||||
|
SimpleName : /*java identifier*/;
|
||||||
|
FieldName : "$" SimpleName;
|
||||||
|
name : /*possibly qualified name*/;
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
accessModifier
|
||||||
|
: "private"
|
||||||
|
: "protected"
|
||||||
|
: "public"
|
||||||
|
: "internal"
|
||||||
|
;
|
||||||
|
|
||||||
|
parameter
|
||||||
|
: SimpleName ":" type
|
||||||
|
// TODO: lazy, out, ref ...
|
||||||
|
;
|
||||||
|
|
||||||
|
functionArguments
|
||||||
|
: "(" (expression{","})* ")"
|
||||||
|
;
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Foo<Bar<X>, T, Object> // user type
|
||||||
|
{A, Object => Foo} // function type
|
||||||
|
{ => Foo} // function with no arguments
|
||||||
|
(A, B, C) // tuple type
|
||||||
|
() // 0-ary tuple type (Unit)
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
type
|
||||||
|
: userType
|
||||||
|
: functionType
|
||||||
|
: tupleType
|
||||||
|
;
|
||||||
|
|
||||||
|
userType
|
||||||
|
: name ("<" type{","} ">")?
|
||||||
|
;
|
||||||
|
|
||||||
|
functionType
|
||||||
|
: "{" type{","} "=>" type "}"
|
||||||
|
;
|
||||||
|
|
||||||
|
tupleType
|
||||||
|
: "(" type"{","} ")"
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user