mirror of
https://github.com/apple/pkl.git
synced 2026-05-28 01:29:15 +02:00
Initial commit
This commit is contained in:
Vendored
+1
@@ -0,0 +1 @@
|
||||
result = IntSeq(1, 10).fold(0, (result, next) -> result + next)
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
/// module doc comment
|
||||
@MyAnn { text = "module annotation" }
|
||||
open module api.reflect.BaseModule
|
||||
|
||||
/// module property doc comment
|
||||
@MyAnn { text = "module property annotation" }
|
||||
int = 42
|
||||
float = 12.3
|
||||
string = "hello"
|
||||
boolean = true
|
||||
duration = 42.h
|
||||
dataSize = 12.3.gb
|
||||
pair = Pair(42, "hello")
|
||||
list = List(1, 2, 3)
|
||||
set = Set(1, 2, 3)
|
||||
map = Map(1, "one", 2, "two", 3, "three")
|
||||
listing = new Listing { 1; 2; 3 }
|
||||
mapping = new Mapping { [1] = "one"; [2] = "two"; [3] = "three" }
|
||||
dynamic = new Dynamic { name = "Pigeon"; age = 42 }
|
||||
typed = new Person { age = 42 }
|
||||
|
||||
/// module method doc comment
|
||||
@MyAnn { text = "module method annotation" }
|
||||
function sing(person, songs) = "\(person.name) sings \(songs[0])"
|
||||
|
||||
int2: Int = 42
|
||||
float2: Float = 12.3
|
||||
string2: String = "hello"
|
||||
boolean2: Boolean = true
|
||||
duration2: Duration = 42.h
|
||||
dataSize2: DataSize = 12.3.gb
|
||||
pair2: Pair<Int, String> = Pair(42, "hello")
|
||||
list2: List<Int> = List(1, 2, 3)
|
||||
set2: Set<Int> = Set(1, 2, 3)
|
||||
map2: Map<Int, String> = Map(1, "one", 2, "two", 3, "three")
|
||||
listing2: Listing<Int> = new Listing { 1; 2; 3 }
|
||||
mapping2: Mapping<Int, String> = new Mapping { [1] = "one"; [2] = "two"; [3] = "three" }
|
||||
dynamic2: Dynamic = new Dynamic { name = "Pigeon"; age = 42 }
|
||||
typed2: Person = new Person { age = 42 }
|
||||
|
||||
function sing2(person: Person, songs: List<String>): String = "\(person.name) sings \(songs[0])"
|
||||
|
||||
any: Any
|
||||
noth: nothing
|
||||
unkn: unknown
|
||||
union: Int|List<String>|Person
|
||||
nullable: Person?
|
||||
stringLiteral: "yes"
|
||||
constrained: String(length.isBetween(3, 10))
|
||||
aliased: MyMap<Person>
|
||||
|
||||
/// class doc comment
|
||||
@MyAnn { text = "class annotation" }
|
||||
open class Person {
|
||||
name: String = "Pigeon"
|
||||
|
||||
/// class property doc comment
|
||||
@MyAnn { text = "class property annotation"}
|
||||
age: Int = 42
|
||||
|
||||
/// class method doc comment
|
||||
@MyAnn { text = "class method annotation" }
|
||||
function sing(songs: List<String>): String = "\(name) sings \(songs[0])"
|
||||
}
|
||||
|
||||
class MyAnn extends Annotation {
|
||||
text: String
|
||||
}
|
||||
|
||||
/// type alias doc comment
|
||||
@MyAnn { text = "type alias annotation" }
|
||||
typealias MyMap<V> = Map<String, V>(isEmpty)
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
/// extending module doc comment
|
||||
@MyAnn { text = "extending module annotation" }
|
||||
extends "BaseModule.pkl"
|
||||
|
||||
property: Person2
|
||||
|
||||
function method(): Person = new {}
|
||||
|
||||
class Person2 extends Person
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
/// amending module doc comment
|
||||
@MyAnn { text = "amending module annotation" }
|
||||
amends "BaseModule.pkl"
|
||||
|
||||
int = 22
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
import "pkl:reflect"
|
||||
import "BaseModule.pkl"
|
||||
|
||||
referenceModule = "BaseModule.pkl"
|
||||
|
||||
function MyAnn(message: String): List<BaseModule.MyAnn> = List(new BaseModule.MyAnn {
|
||||
text = message
|
||||
})
|
||||
|
||||
function method(m: reflect.Method, paramTypes: List<reflect.Type>, returnType: reflect.Type): Dynamic = new {
|
||||
hasExpectedLocation = m.location.displayUri.contains(referenceModule)
|
||||
docComment = m.docComment
|
||||
annotations = m.annotations
|
||||
modifiers = m.modifiers
|
||||
name = m.name
|
||||
typeParameters = m.typeParameters
|
||||
parameterNames = m.parameters.keys
|
||||
hasExpectedParameterTypes = m.parameters.values.map((it) -> it.type) == paramTypes
|
||||
hasExpectedReturnType = m.returnType == returnType
|
||||
}
|
||||
|
||||
function property(p: reflect.Property, expectedType: reflect.Type): Dynamic = new {
|
||||
hasExpectedLocation = p.location.displayUri.contains(referenceModule)
|
||||
docComment = p.docComment
|
||||
annotations = p.annotations
|
||||
modifiers = p.modifiers
|
||||
name = p.name
|
||||
defaultValue = p.defaultValue
|
||||
hasExpectedType = p.type == expectedType
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
name = "child/moduleC"
|
||||
+1
@@ -0,0 +1 @@
|
||||
child/
|
||||
+1
@@ -0,0 +1 @@
|
||||
name = "moduleA"
|
||||
+1
@@ -0,0 +1 @@
|
||||
name = "moduleB"
|
||||
Reference in New Issue
Block a user