├── VERSION.txt ├── codegen ├── src │ ├── resources │ │ └── VERSION.txt │ ├── PklProject.deps.json │ ├── tests │ │ ├── fixtures │ │ │ ├── types3.pkl │ │ │ ├── types4.pkl │ │ │ ├── types2.pkl │ │ │ ├── ClassGen.pkl │ │ │ └── types.pkl │ │ ├── utils.pkl │ │ └── gatherer.pkl │ ├── internal │ │ └── Gen.pkl │ └── PklProject └── snippet-tests │ ├── input │ ├── support │ │ ├── NoMapping.pkl │ │ ├── OpenModule.pkl │ │ ├── lib3.pkl │ │ ├── lib2.pkl │ │ ├── lib4.pkl │ │ └── lib.pkl │ ├── NoMappingHidden.pkl │ ├── Pairs.pkl │ ├── EmptyOpenModule.pkl │ ├── ExtendModule.pkl │ ├── InvalidPackageName.err.pkl │ ├── UnionNameKeyword.pkl │ ├── ConflictingNames2.err.pkl │ ├── HiddenProperties.pkl │ ├── CyclicModule.pkl │ ├── IllegalOverride.err.pkl │ ├── Override.pkl │ ├── ModuleType.pkl │ ├── Override2.pkl │ ├── ModuleUsingLib.pkl │ ├── ConflictingNames.err.pkl │ ├── ExplicitName.pkl │ ├── ExtendAbstractClass.pkl │ ├── ExtendOpenClass.pkl │ ├── Unions.pkl │ └── StructTags.pkl │ ├── output │ ├── override │ │ ├── Foo.pkl.go │ │ ├── init.pkl.go │ │ ├── Bar.pkl.go │ │ └── Override.pkl.go │ ├── support │ │ ├── lib4 │ │ │ ├── MyLib4.pkl.go │ │ │ ├── init.pkl.go │ │ │ └── Lib4.pkl.go │ │ ├── openmodule │ │ │ ├── init.pkl.go │ │ │ └── MyModule.pkl.go │ │ ├── lib │ │ │ ├── init.pkl.go │ │ │ ├── MyClass.pkl.go │ │ │ ├── myenum │ │ │ │ └── MyEnum.pkl.go │ │ │ └── Lib.pkl.go │ │ ├── lib3 │ │ │ ├── init.pkl.go │ │ │ ├── GoGoGo.pkl.go │ │ │ └── Lib3.pkl.go │ │ └── lib2 │ │ │ └── cities │ │ │ └── Cities.pkl.go │ ├── bugholder │ │ ├── A.pkl.go │ │ ├── Being.pkl.go │ │ ├── Wheel.pkl.go │ │ ├── Bike.pkl.go │ │ ├── C.pkl.go │ │ ├── D.pkl.go │ │ ├── B.pkl.go │ │ ├── ThisPerson.pkl.go │ │ ├── init.pkl.go │ │ ├── bugkind │ │ │ └── BugKind.pkl.go │ │ ├── Bug.pkl.go │ │ ├── bugkindtwo │ │ │ └── BugKindTwo.pkl.go │ │ ├── Person.pkl.go │ │ └── BugHolder.pkl.go │ ├── explicitname │ │ ├── SomethingVeryFunny.pkl.go │ │ ├── init.pkl.go │ │ ├── configtype │ │ │ └── ConfigType.pkl.go │ │ └── ExplicitlyCoolName.pkl.go │ ├── union │ │ ├── init.pkl.go │ │ ├── city │ │ │ └── City.pkl.go │ │ ├── noodles │ │ │ └── Noodles.pkl.go │ │ ├── county │ │ │ └── County.pkl.go │ │ ├── accountdisposition │ │ │ └── AccountDisposition.pkl.go │ │ └── Union.pkl.go │ ├── pairs │ │ ├── init.pkl.go │ │ └── Pairs.pkl.go │ ├── moduletype │ │ ├── init.pkl.go │ │ └── ModuleType.pkl.go │ ├── structtags │ │ ├── init.pkl.go │ │ └── StructTags.pkl.go │ ├── cyclicmodule │ │ ├── Cyclic.pkl.go │ │ ├── init.pkl.go │ │ └── CyclicModule.pkl.go │ ├── extendmodule │ │ ├── init.pkl.go │ │ └── ExtendModule.pkl.go │ ├── moduleusinglib │ │ ├── init.pkl.go │ │ └── ModuleUsingLib.pkl.go │ ├── nomappinghidden │ │ ├── init.pkl.go │ │ └── NoMappingHidden.pkl.go │ ├── emptyopenmodule │ │ ├── init.pkl.go │ │ └── EmptyOpenModule.pkl.go │ ├── hiddenproperties │ │ ├── init.pkl.go │ │ └── HiddenProperties.pkl.go │ ├── unionnamekeyword │ │ ├── init.pkl.go │ │ ├── _type │ │ │ └── Type.pkl.go │ │ └── UnionNameKeyword.pkl.go │ ├── extendabstractclass │ │ ├── B.pkl.go │ │ ├── A.pkl.go │ │ ├── init.pkl.go │ │ ├── C.pkl.go │ │ └── ExtendsAbstractClass.pkl.go │ ├── override2 │ │ ├── init.pkl.go │ │ ├── MySubclass.pkl.go │ │ └── Override2.pkl.go │ ├── extendopenclass │ │ ├── MyOpenClass.pkl.go │ │ ├── MyClass.pkl.go │ │ ├── init.pkl.go │ │ ├── MyClass2.pkl.go │ │ └── ExtendingOpenClass.pkl.go │ ├── ConflictingNames.err │ ├── ConflictingNames2.err │ └── InvalidPackageName.err │ └── generator-settings.pkl ├── .gitattributes ├── .mailmap ├── pkl ├── test_fixtures │ ├── msgpack │ │ ├── any.pkl.msgpack │ │ ├── classes.pkl.msgpack │ │ ├── dynamic.pkl.msgpack │ │ ├── types.pkl.msgpack │ │ ├── unions.pkl.msgpack │ │ ├── datasize.pkl.msgpack │ │ ├── duration.pkl.msgpack │ │ ├── nullables.pkl.msgpack │ │ ├── collections.pkl.msgpack │ │ ├── collections.res1.msgpack │ │ ├── collections.res2.msgpack │ │ ├── collections.res9.msgpack │ │ ├── primitives.pkl.msgpack │ │ └── unknown_type.pkl.msgpack │ ├── gen │ │ ├── types │ │ │ ├── Foo.pkl.go │ │ │ ├── init.pkl.go │ │ │ └── Types.pkl.go │ │ ├── any │ │ │ ├── Person.pkl.go │ │ │ ├── init.pkl.go │ │ │ └── Any.pkl.go │ │ ├── classes │ │ │ ├── Animal.pkl.go │ │ │ ├── House.pkl.go │ │ │ ├── Greyhound.pkl.go │ │ │ ├── Cat.pkl.go │ │ │ ├── init.pkl.go │ │ │ ├── Dog.pkl.go │ │ │ └── Classes.pkl.go │ │ ├── dynamic │ │ │ ├── MyClass.pkl.go │ │ │ ├── init.pkl.go │ │ │ └── Dynamic.pkl.go │ │ ├── nullables │ │ │ ├── MyClass.pkl.go │ │ │ ├── init.pkl.go │ │ │ └── Nullables.pkl.go │ │ ├── unions │ │ │ ├── init.pkl.go │ │ │ ├── number │ │ │ │ └── Number.pkl.go │ │ │ ├── othernumbers │ │ │ │ └── OtherNumbers.pkl.go │ │ │ └── Unions.pkl.go │ │ ├── datasize │ │ │ ├── init.pkl.go │ │ │ └── Datasize.pkl.go │ │ ├── duration │ │ │ ├── init.pkl.go │ │ │ └── Duration.pkl.go │ │ ├── primitives │ │ │ ├── init.pkl.go │ │ │ └── Primitives.pkl.go │ │ ├── collections │ │ │ ├── init.pkl.go │ │ │ └── Collections.pkl.go │ │ └── unknown_type │ │ │ ├── init.pkl.go │ │ │ └── UnknownType.pkl.go │ ├── manual │ │ ├── arrays_too_long.pkl.msgpack │ │ └── types_pre_0.30.pkl.msgpack │ ├── types.pkl │ ├── testfs │ │ ├── subdir │ │ │ └── person.pkl │ │ └── person.pkl │ ├── unions.pkl │ ├── unknown_type.pkl │ ├── dynamic.pkl │ ├── duration.pkl │ ├── any.pkl │ ├── primitives.pkl │ ├── datasize.pkl │ ├── classes.pkl │ ├── collections.pkl │ └── nullables.pkl ├── reader_test.go ├── evaluator_manager_exec_windows.go ├── module_source_test.go ├── internal │ ├── debug.go │ ├── msgapi │ │ └── code.go │ └── version_test.go ├── atomic.go ├── evaluator_manager_exec_unix.go ├── schema.go ├── unmarshal.go ├── errors.go ├── decode_slice.go ├── logger.go ├── fs_reader.go └── values_test.go ├── docs ├── antora.yml ├── nav.adoc └── modules │ └── ROOT │ └── pages │ ├── index.adoc │ └── external-readers.adoc ├── .gitignore ├── .github ├── dependabot.yml ├── PklProject ├── workflows │ ├── test_report.yml │ └── __lockfile__.yml └── PklProject.deps.json ├── cmd ├── internal │ ├── gen-fixtures │ │ └── README.adoc │ └── test-external-reader │ │ └── test-external-reader.go └── pkl-gen-go │ ├── generatorsettings │ └── init.pkl.go │ └── pkg │ └── template.gopkl ├── scripts ├── notice.tpl ├── license-header.txt ├── create_notice.sh └── test_snippets.sh ├── licenserc.toml ├── MAINTAINERS.adoc ├── README.adoc ├── go.mod ├── SECURITY.md ├── generator-settings.pkl ├── CONTRIBUTING.adoc ├── go.sum └── DEVELOPMENT.adoc /VERSION.txt: -------------------------------------------------------------------------------- 1 | 0.13.0 2 | -------------------------------------------------------------------------------- /codegen/src/resources/VERSION.txt: -------------------------------------------------------------------------------- 1 | ../../../VERSION.txt -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | PklProject linguist-language=Pkl 2 | *.msgpack binary 3 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/support/NoMapping.pkl: -------------------------------------------------------------------------------- 1 | module NoMapping 2 | 3 | foo: String 4 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | Jen Basch <421772+HT154@users.noreply.github.com> 2 | Jen Basch 3 | -------------------------------------------------------------------------------- /codegen/src/PklProject.deps.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": 1, 3 | "resolvedDependencies": {} 4 | } 5 | -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/any.pkl.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/HEAD/pkl/test_fixtures/msgpack/any.pkl.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/classes.pkl.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/HEAD/pkl/test_fixtures/msgpack/classes.pkl.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/dynamic.pkl.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/HEAD/pkl/test_fixtures/msgpack/dynamic.pkl.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/types.pkl.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/HEAD/pkl/test_fixtures/msgpack/types.pkl.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/unions.pkl.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/HEAD/pkl/test_fixtures/msgpack/unions.pkl.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/datasize.pkl.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/HEAD/pkl/test_fixtures/msgpack/datasize.pkl.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/duration.pkl.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/HEAD/pkl/test_fixtures/msgpack/duration.pkl.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/nullables.pkl.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/HEAD/pkl/test_fixtures/msgpack/nullables.pkl.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/collections.pkl.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/HEAD/pkl/test_fixtures/msgpack/collections.pkl.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/collections.res1.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/HEAD/pkl/test_fixtures/msgpack/collections.res1.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/collections.res2.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/HEAD/pkl/test_fixtures/msgpack/collections.res2.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/collections.res9.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/HEAD/pkl/test_fixtures/msgpack/collections.res9.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/primitives.pkl.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/HEAD/pkl/test_fixtures/msgpack/primitives.pkl.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/unknown_type.pkl.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/HEAD/pkl/test_fixtures/msgpack/unknown_type.pkl.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/types/Foo.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `types`. DO NOT EDIT. 2 | package types 3 | 4 | type Foo struct { 5 | } 6 | -------------------------------------------------------------------------------- /pkl/test_fixtures/manual/arrays_too_long.pkl.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/HEAD/pkl/test_fixtures/manual/arrays_too_long.pkl.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/manual/types_pre_0.30.pkl.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/HEAD/pkl/test_fixtures/manual/types_pre_0.30.pkl.msgpack -------------------------------------------------------------------------------- /docs/antora.yml: -------------------------------------------------------------------------------- 1 | name: go 2 | title: Pkl Go Bindings 3 | version: &version 0.13.0 4 | nav: 5 | - nav.adoc 6 | asciidoc: 7 | attributes: 8 | version: *version 9 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/any/Person.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `any`. DO NOT EDIT. 2 | package any 3 | 4 | type Person struct { 5 | Name string `pkl:"name"` 6 | } 7 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/classes/Animal.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `classes`. DO NOT EDIT. 2 | package classes 3 | 4 | type Animal interface { 5 | GetName() string 6 | } 7 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/override/Foo.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `override`. DO NOT EDIT. 2 | package override 3 | 4 | type Foo interface { 5 | GetMyProp() string 6 | } 7 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/support/lib4/MyLib4.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `lib4`. DO NOT EDIT. 2 | package lib4 3 | 4 | type MyLib4 struct { 5 | Foo Lib4 `pkl:"foo"` 6 | } 7 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/bugholder/A.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `org.foo.BugHolder`. DO NOT EDIT. 2 | package bugholder 3 | 4 | type A interface { 5 | GetA() string 6 | } 7 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/dynamic/MyClass.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `dynamic`. DO NOT EDIT. 2 | package dynamic 3 | 4 | type MyClass struct { 5 | MyValue int `pkl:"myValue"` 6 | } 7 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/nullables/MyClass.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `nullables`. DO NOT EDIT. 2 | package nullables 3 | 4 | type MyClass struct { 5 | Prop *string `pkl:"prop"` 6 | } 7 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/bugholder/Being.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `org.foo.BugHolder`. DO NOT EDIT. 2 | package bugholder 3 | 4 | type Being interface { 5 | GetIsAlive() bool 6 | } 7 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/explicitname/SomethingVeryFunny.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `ExplicitName`. DO NOT EDIT. 2 | package explicitname 3 | 4 | type SomethingVeryFunny struct { 5 | } 6 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/bugholder/Wheel.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `org.foo.BugHolder`. DO NOT EDIT. 2 | package bugholder 3 | 4 | type Wheel struct { 5 | HasSpokes bool `pkl:"hasSpokes"` 6 | } 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /antlr/gen 2 | /parser/antlr 3 | /.idea 4 | .run/ 5 | *.pb.go 6 | .gradle/ 7 | *.jar 8 | libpkl/ 9 | out/ 10 | docker/files/bin/ 11 | .vscode/ 12 | build/ 13 | .env 14 | .out 15 | .cicd/ 16 | test-results/ 17 | .pkl-lsp 18 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/union/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `union`. DO NOT EDIT. 2 | package union 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("union", Union{}) 8 | } 9 | -------------------------------------------------------------------------------- /docs/nav.adoc: -------------------------------------------------------------------------------- 1 | * xref:ROOT:quickstart.adoc[Quickstart] 2 | * xref:ROOT:evaluation.adoc[Evaluator API] 3 | * xref:ROOT:codegen.adoc[Code Generation] 4 | * xref:ROOT:external-readers.adoc[External Readers] 5 | * xref:ROOT:CHANGELOG.adoc[Changelog] 6 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/unions/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `unions`. DO NOT EDIT. 2 | package unions 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("unions", Unions{}) 8 | } 9 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/pairs/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `Pairs`. DO NOT EDIT. 2 | package pairs 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("Pairs", PairsImpl{}) 8 | } 9 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/datasize/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `datasize`. DO NOT EDIT. 2 | package datasize 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("datasize", Datasize{}) 8 | } 9 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/duration/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `duration`. DO NOT EDIT. 2 | package duration 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("duration", Duration{}) 8 | } 9 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: github-actions 4 | directory: / 5 | ignore: 6 | - dependency-name: '*' 7 | update-types: 8 | - version-update:semver-major 9 | schedule: 10 | interval: weekly 11 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/primitives/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `primitives`. DO NOT EDIT. 2 | package primitives 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("primitives", Primitives{}) 8 | } 9 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/moduletype/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `ModuleType`. DO NOT EDIT. 2 | package moduletype 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("ModuleType", ModuleType{}) 8 | } 9 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/structtags/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `StructTags`. DO NOT EDIT. 2 | package structtags 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("StructTags", StructTags{}) 8 | } 9 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/collections/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `collections`. DO NOT EDIT. 2 | package collections 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("collections", Collections{}) 8 | } 9 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/NoMappingHidden.pkl: -------------------------------------------------------------------------------- 1 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/nomappinghidden" } 2 | module NoMappingHidden 3 | 4 | import ".../src/go.pkl" 5 | import "support/NoMapping.pkl" 6 | 7 | hidden noMapping: NoMapping 8 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/unknown_type/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `unknown_type`. DO NOT EDIT. 2 | package unknowntype 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("unknown_type", UnknownType{}) 8 | } 9 | -------------------------------------------------------------------------------- /cmd/internal/gen-fixtures/README.adoc: -------------------------------------------------------------------------------- 1 | = gen-fixtures 2 | 3 | This is a simple script that generates the fixtures in the pkl/test_fixtures/msgpack directory. 4 | 5 | == Usage 6 | 7 | [source,shell script] 8 | ---- 9 | go run cmd/gen-fixtures/gen-fixtures.go 10 | ---- 11 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/support/openmodule/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `MyModule`. DO NOT EDIT. 2 | package openmodule 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("MyModule", MyModuleImpl{}) 8 | } 9 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/classes/House.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `classes`. DO NOT EDIT. 2 | package classes 3 | 4 | type House struct { 5 | Area int `pkl:"area"` 6 | 7 | Bedrooms int `pkl:"bedrooms"` 8 | 9 | Bathrooms int `pkl:"bathrooms"` 10 | } 11 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/cyclicmodule/Cyclic.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `CyclicModule`. DO NOT EDIT. 2 | package cyclicmodule 3 | 4 | type Cyclic struct { 5 | A string `pkl:"a"` 6 | 7 | B int `pkl:"b"` 8 | 9 | Myself *Cyclic `pkl:"myself"` 10 | } 11 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/extendmodule/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `ExtendModule`. DO NOT EDIT. 2 | package extendmodule 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("ExtendModule", ExtendModuleImpl{}) 8 | } 9 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/moduleusinglib/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `ModuleUsingLib`. DO NOT EDIT. 2 | package moduleusinglib 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("ModuleUsingLib", ModuleUsingLib{}) 8 | } 9 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/nomappinghidden/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `NoMappingHidden`. DO NOT EDIT. 2 | package nomappinghidden 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("NoMappingHidden", NoMappingHidden{}) 8 | } 9 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/any/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `any`. DO NOT EDIT. 2 | package any 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("any", Any{}) 8 | pkl.RegisterStrictMapping("any#Person", Person{}) 9 | } 10 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/emptyopenmodule/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `EmptyOpenModule`. DO NOT EDIT. 2 | package emptyopenmodule 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("EmptyOpenModule", EmptyOpenModuleImpl{}) 8 | } 9 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/hiddenproperties/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `HiddenProperties`. DO NOT EDIT. 2 | package hiddenproperties 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("HiddenProperties", HiddenProperties{}) 8 | } 9 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/unionnamekeyword/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `UnionNameKeyword`. DO NOT EDIT. 2 | package unionnamekeyword 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("UnionNameKeyword", UnionNameKeyword{}) 8 | } 9 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/types/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `types`. DO NOT EDIT. 2 | package types 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("types", Types{}) 8 | pkl.RegisterStrictMapping("types#Foo", Foo{}) 9 | } 10 | -------------------------------------------------------------------------------- /cmd/pkl-gen-go/generatorsettings/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `pkl.golang.GeneratorSettings`. DO NOT EDIT. 2 | package generatorsettings 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("pkl.golang.GeneratorSettings", GeneratorSettings{}) 8 | } 9 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/support/lib/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `lib`. DO NOT EDIT. 2 | package lib 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("lib", Lib{}) 8 | pkl.RegisterStrictMapping("lib#MyClass", MyClassImpl{}) 9 | } 10 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/support/lib4/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `lib4`. DO NOT EDIT. 2 | package lib4 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("lib4", Lib4{}) 8 | pkl.RegisterStrictMapping("lib4#MyLib4", MyLib4{}) 9 | } 10 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/support/lib3/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `lib3`. DO NOT EDIT. 2 | package lib3 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("lib3", Lib3{}) 8 | pkl.RegisterStrictMapping("lib3#GoGoGo", GoGoGoImpl{}) 9 | } 10 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/dynamic/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `dynamic`. DO NOT EDIT. 2 | package dynamic 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("dynamic", Dynamic{}) 8 | pkl.RegisterStrictMapping("dynamic#MyClass", MyClass{}) 9 | } 10 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/override/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `override`. DO NOT EDIT. 2 | package override 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("override", Override{}) 8 | pkl.RegisterStrictMapping("override#Bar", BarImpl{}) 9 | } 10 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/extendabstractclass/B.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `ExtendsAbstractClass`. DO NOT EDIT. 2 | package extendabstractclass 3 | 4 | import "github.com/apple/pkl-go/codegen/snippet-tests/output/support/lib2/cities" 5 | 6 | type B interface { 7 | A 8 | 9 | GetE() cities.Cities 10 | } 11 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/nullables/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `nullables`. DO NOT EDIT. 2 | package nullables 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("nullables", Nullables{}) 8 | pkl.RegisterStrictMapping("nullables#MyClass", MyClass{}) 9 | } 10 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/extendabstractclass/A.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `ExtendsAbstractClass`. DO NOT EDIT. 2 | package extendabstractclass 3 | 4 | import "github.com/apple/pkl-go/codegen/snippet-tests/output/support/lib3" 5 | 6 | type A interface { 7 | GetB() string 8 | 9 | GetC() lib3.GoGoGo 10 | } 11 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/cyclicmodule/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `CyclicModule`. DO NOT EDIT. 2 | package cyclicmodule 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("CyclicModule", CyclicModule{}) 8 | pkl.RegisterStrictMapping("CyclicModule#Cyclic", Cyclic{}) 9 | } 10 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/override2/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `Override2`. DO NOT EDIT. 2 | package override2 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("Override2", Override2Impl{}) 8 | pkl.RegisterStrictMapping("Override2#MySubclass", MySubclassImpl{}) 9 | } 10 | -------------------------------------------------------------------------------- /scripts/notice.tpl: -------------------------------------------------------------------------------- 1 | Copyright © 2024 Apple Inc. and the Pkl project authors 2 | 3 | The pkl-gen-go binary includes libraries that may be distributed under a different license. 4 | 5 | {{ range $index, $value := . }} 6 | --- 7 | {{ .Name }} 8 | {{ .LicenseName }} - {{ .LicenseURL }} 9 | 10 | *** 11 | 12 | {{ .LicenseText }} 13 | {{ end }} 14 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/bugholder/Bike.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `org.foo.BugHolder`. DO NOT EDIT. 2 | package bugholder 3 | 4 | type Bike struct { 5 | IsFixie bool `pkl:"isFixie"` 6 | 7 | // Wheels are the front and back wheels. 8 | // 9 | // There are typically two of them. 10 | Wheels []Wheel `pkl:"wheels"` 11 | } 12 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/override/Bar.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `override`. DO NOT EDIT. 2 | package override 3 | 4 | type Bar interface { 5 | Foo 6 | } 7 | 8 | var _ Bar = BarImpl{} 9 | 10 | type BarImpl struct { 11 | MyProp string `pkl:"myProp"` 12 | } 13 | 14 | func (rcv BarImpl) GetMyProp() string { 15 | return rcv.MyProp 16 | } 17 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/explicitname/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `ExplicitName`. DO NOT EDIT. 2 | package explicitname 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("ExplicitName", ExplicitlyCoolName{}) 8 | pkl.RegisterStrictMapping("ExplicitName#SomethingFunny", SomethingVeryFunny{}) 9 | } 10 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/support/lib3/GoGoGo.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `lib3`. DO NOT EDIT. 2 | package lib3 3 | 4 | type GoGoGo interface { 5 | GetDuck() string 6 | } 7 | 8 | var _ GoGoGo = GoGoGoImpl{} 9 | 10 | type GoGoGoImpl struct { 11 | Duck string `pkl:"duck"` 12 | } 13 | 14 | func (rcv GoGoGoImpl) GetDuck() string { 15 | return rcv.Duck 16 | } 17 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/bugholder/C.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `org.foo.BugHolder`. DO NOT EDIT. 2 | package bugholder 3 | 4 | type C interface { 5 | B 6 | 7 | GetC() string 8 | } 9 | 10 | var _ C = CImpl{} 11 | 12 | type CImpl struct { 13 | BImpl 14 | 15 | C string `pkl:"c"` 16 | } 17 | 18 | func (rcv CImpl) GetC() string { 19 | return rcv.C 20 | } 21 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/bugholder/D.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `org.foo.BugHolder`. DO NOT EDIT. 2 | package bugholder 3 | 4 | type D interface { 5 | C 6 | 7 | GetD() string 8 | } 9 | 10 | var _ D = DImpl{} 11 | 12 | type DImpl struct { 13 | CImpl 14 | 15 | D string `pkl:"d"` 16 | } 17 | 18 | func (rcv DImpl) GetD() string { 19 | return rcv.D 20 | } 21 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/extendabstractclass/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `ExtendsAbstractClass`. DO NOT EDIT. 2 | package extendabstractclass 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("ExtendsAbstractClass", ExtendsAbstractClass{}) 8 | pkl.RegisterStrictMapping("ExtendsAbstractClass#C", CImpl{}) 9 | } 10 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/support/lib/MyClass.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `lib`. DO NOT EDIT. 2 | package lib 3 | 4 | type MyClass interface { 5 | GetThing() string 6 | } 7 | 8 | var _ MyClass = MyClassImpl{} 9 | 10 | type MyClassImpl struct { 11 | Thing string `pkl:"thing"` 12 | } 13 | 14 | func (rcv MyClassImpl) GetThing() string { 15 | return rcv.Thing 16 | } 17 | -------------------------------------------------------------------------------- /licenserc.toml: -------------------------------------------------------------------------------- 1 | headerPath = "scripts/license-header.txt" 2 | 3 | includes = [ 4 | "*.go", 5 | "*.pkl", 6 | "*.sh", 7 | "PklProject", 8 | ] 9 | 10 | excludes = [ 11 | "pkl/test_fixtures/", 12 | "codegen/snippet-tests", 13 | "doc", 14 | "*.pkl.go" 15 | ] 16 | 17 | [git] 18 | attrs = 'enable' 19 | ignore = 'enable' 20 | 21 | [mapping.LINE_BLOCK_STYLE] 22 | extensions = ["go"] 23 | -------------------------------------------------------------------------------- /pkl/test_fixtures/types.pkl: -------------------------------------------------------------------------------- 1 | @go.Package { name = "github.com/apple/pkl-go/pkl/test_fixtures/gen/types" } 2 | module types 3 | 4 | import "pkl:base" 5 | 6 | import ".../codegen/src/go.pkl" 7 | 8 | stringClass: Class = String 9 | baseModuleClass: Class = base.getClass() 10 | uint8TypeAlias: TypeAlias = UInt8 11 | fooClass: Class = Foo 12 | barTypeAlias: TypeAlias = Bar 13 | 14 | class Foo {} 15 | typealias Bar = Foo 16 | -------------------------------------------------------------------------------- /MAINTAINERS.adoc: -------------------------------------------------------------------------------- 1 | = MAINTAINERS 2 | 3 | This page lists all active Maintainers of this repository. 4 | 5 | See link:CONTRIBUTING.adoc[] for general contribution guidelines. 6 | 7 | == Maintainers (in alphabetical order) 8 | 9 | * https://github.com/bioball[Daniel Chao] 10 | * https://github.com/stackoverflow[Islon Scherer] 11 | * https://github.com/HT154[Jen Basch] 12 | * https://github.com/holzensp[Philip Hölzenspies] 13 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/Pairs.pkl: -------------------------------------------------------------------------------- 1 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/pairs" } 2 | open module Pairs 3 | 4 | import ".../src/go.pkl" 5 | 6 | untyped: Pair 7 | 8 | optional: Pair? 9 | 10 | typed: Pair 11 | 12 | aliased: MyPair 13 | 14 | typeArgAliased: OurPair 15 | 16 | typealias MyPair = Pair 17 | typealias OurPair = Pair 18 | typealias Foo = Int 19 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/extendopenclass/MyOpenClass.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `ExtendingOpenClass`. DO NOT EDIT. 2 | package extendopenclass 3 | 4 | type MyOpenClass interface { 5 | GetMyStr() string 6 | } 7 | 8 | var _ MyOpenClass = MyOpenClassImpl{} 9 | 10 | type MyOpenClassImpl struct { 11 | MyStr string `pkl:"myStr"` 12 | } 13 | 14 | func (rcv MyOpenClassImpl) GetMyStr() string { 15 | return rcv.MyStr 16 | } 17 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/classes/Greyhound.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `classes`. DO NOT EDIT. 2 | package classes 3 | 4 | type Greyhound interface { 5 | Dog 6 | 7 | GetCanRoach() bool 8 | } 9 | 10 | var _ Greyhound = GreyhoundImpl{} 11 | 12 | type GreyhoundImpl struct { 13 | DogImpl 14 | 15 | CanRoach bool `pkl:"canRoach"` 16 | } 17 | 18 | func (rcv GreyhoundImpl) GetCanRoach() bool { 19 | return rcv.CanRoach 20 | } 21 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/bugholder/B.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `org.foo.BugHolder`. DO NOT EDIT. 2 | package bugholder 3 | 4 | type B interface { 5 | A 6 | 7 | GetB() string 8 | } 9 | 10 | var _ B = BImpl{} 11 | 12 | type BImpl struct { 13 | B string `pkl:"b"` 14 | 15 | A string `pkl:"a"` 16 | } 17 | 18 | func (rcv BImpl) GetB() string { 19 | return rcv.B 20 | } 21 | 22 | func (rcv BImpl) GetA() string { 23 | return rcv.A 24 | } 25 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/extendopenclass/MyClass.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `ExtendingOpenClass`. DO NOT EDIT. 2 | package extendopenclass 3 | 4 | type MyClass interface { 5 | MyOpenClass 6 | 7 | GetMyBoolean() bool 8 | } 9 | 10 | var _ MyClass = MyClassImpl{} 11 | 12 | type MyClassImpl struct { 13 | MyOpenClassImpl 14 | 15 | MyBoolean bool `pkl:"myBoolean"` 16 | } 17 | 18 | func (rcv MyClassImpl) GetMyBoolean() bool { 19 | return rcv.MyBoolean 20 | } 21 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/classes/Cat.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `classes`. DO NOT EDIT. 2 | package classes 3 | 4 | type Cat interface { 5 | Animal 6 | 7 | GetMeows() bool 8 | } 9 | 10 | var _ Cat = CatImpl{} 11 | 12 | type CatImpl struct { 13 | Meows bool `pkl:"meows"` 14 | 15 | Name string `pkl:"name"` 16 | } 17 | 18 | func (rcv CatImpl) GetMeows() bool { 19 | return rcv.Meows 20 | } 21 | 22 | func (rcv CatImpl) GetName() string { 23 | return rcv.Name 24 | } 25 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/classes/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `classes`. DO NOT EDIT. 2 | package classes 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("classes", Classes{}) 8 | pkl.RegisterStrictMapping("classes#House", House{}) 9 | pkl.RegisterStrictMapping("classes#Dog", DogImpl{}) 10 | pkl.RegisterStrictMapping("classes#Greyhound", GreyhoundImpl{}) 11 | pkl.RegisterStrictMapping("classes#Cat", CatImpl{}) 12 | } 13 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/override2/MySubclass.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `Override2`. DO NOT EDIT. 2 | package override2 3 | 4 | type MySubclass interface { 5 | Override2 6 | 7 | GetFoo() string 8 | } 9 | 10 | var _ MySubclass = MySubclassImpl{} 11 | 12 | type MySubclassImpl struct { 13 | Override2Impl 14 | 15 | // Different doc comments 16 | Foo string `pkl:"foo"` 17 | } 18 | 19 | // Different doc comments 20 | func (rcv MySubclassImpl) GetFoo() string { 21 | return rcv.Foo 22 | } 23 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/extendopenclass/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `ExtendingOpenClass`. DO NOT EDIT. 2 | package extendopenclass 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("ExtendingOpenClass", ExtendingOpenClass{}) 8 | pkl.RegisterStrictMapping("ExtendingOpenClass#MyClass", MyClassImpl{}) 9 | pkl.RegisterStrictMapping("ExtendingOpenClass#MyClass2", MyClass2Impl{}) 10 | pkl.RegisterStrictMapping("ExtendingOpenClass#MyOpenClass", MyOpenClassImpl{}) 11 | } 12 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/extendopenclass/MyClass2.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `ExtendingOpenClass`. DO NOT EDIT. 2 | package extendopenclass 3 | 4 | import "github.com/apple/pkl-go/codegen/snippet-tests/output/support/lib3" 5 | 6 | type MyClass2 interface { 7 | lib3.GoGoGo 8 | 9 | GetMyBoolean() bool 10 | } 11 | 12 | var _ MyClass2 = MyClass2Impl{} 13 | 14 | type MyClass2Impl struct { 15 | lib3.GoGoGoImpl 16 | 17 | MyBoolean bool `pkl:"myBoolean"` 18 | } 19 | 20 | func (rcv MyClass2Impl) GetMyBoolean() bool { 21 | return rcv.MyBoolean 22 | } 23 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | = pkl-go 2 | 3 | This library exposes Go bindings for the Pkl configuration language. 4 | 5 | It allows you to embed Pkl into your Go application, complete with code generation for full type safety and ease of use. 6 | 7 | The full documentation for this library can be found on our https://pkl-lang.org/go/current/index.html[documentation site]. 8 | 9 | To get up and going, reference the https://pkl-lang.org/go/current/quickstart.html[quick start guide]. 10 | 11 | When upgrading pkl-go, reference the https://pkl-lang.org/go/current/CHANGELOG.html[changelog] for details. 12 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/apple/pkl-go 2 | 3 | go 1.23.7 4 | 5 | require ( 6 | github.com/google/go-cmp v0.6.0 7 | github.com/spf13/cobra v1.8.0 8 | github.com/spf13/pflag v1.0.5 9 | github.com/stretchr/testify v1.9.0 10 | github.com/vmihailenco/msgpack/v5 v5.4.1 11 | golang.org/x/mod v0.24.0 12 | ) 13 | 14 | require ( 15 | github.com/davecgh/go-spew v1.1.1 // indirect 16 | github.com/inconshreveable/mousetrap v1.1.0 // indirect 17 | github.com/pmezard/go-difflib v1.0.0 // indirect 18 | github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect 19 | gopkg.in/yaml.v3 v3.0.1 // indirect 20 | ) 21 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/classes/Dog.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `classes`. DO NOT EDIT. 2 | package classes 3 | 4 | type Dog interface { 5 | Animal 6 | 7 | GetBarks() bool 8 | 9 | GetBreed() string 10 | } 11 | 12 | var _ Dog = DogImpl{} 13 | 14 | type DogImpl struct { 15 | Barks bool `pkl:"barks"` 16 | 17 | Breed string `pkl:"breed"` 18 | 19 | Name string `pkl:"name"` 20 | } 21 | 22 | func (rcv DogImpl) GetBarks() bool { 23 | return rcv.Barks 24 | } 25 | 26 | func (rcv DogImpl) GetBreed() string { 27 | return rcv.Breed 28 | } 29 | 30 | func (rcv DogImpl) GetName() string { 31 | return rcv.Name 32 | } 33 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/bugholder/ThisPerson.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `org.foo.BugHolder`. DO NOT EDIT. 2 | package bugholder 3 | 4 | type ThisPerson interface { 5 | Person 6 | 7 | GetMyself() ThisPerson 8 | 9 | GetSomeoneElse() Person 10 | } 11 | 12 | var _ ThisPerson = ThisPersonImpl{} 13 | 14 | type ThisPersonImpl struct { 15 | PersonImpl 16 | 17 | Myself ThisPerson `pkl:"myself"` 18 | 19 | SomeoneElse Person `pkl:"someoneElse"` 20 | } 21 | 22 | func (rcv ThisPersonImpl) GetMyself() ThisPerson { 23 | return rcv.Myself 24 | } 25 | 26 | func (rcv ThisPersonImpl) GetSomeoneElse() Person { 27 | return rcv.SomeoneElse 28 | } 29 | -------------------------------------------------------------------------------- /cmd/pkl-gen-go/pkg/template.gopkl: -------------------------------------------------------------------------------- 1 | {{- /*gotype: github.com/apple/pkl-go/cmd/pkl-gen-go/pkg.TemplateValues*/ -}} 2 | import "{{.GeneratorScriptPath}}" as Generator 3 | import "{{.PklModulePath}}" as theModule 4 | 5 | output = new Generator { 6 | codegenSettings { 7 | packageMappings { 8 | {{range $key, $value := .PackageMappings}} 9 | ["{{$key}}"] = "{{$value}}" 10 | {{end}} 11 | } 12 | {{if ne .BasePath ""}} 13 | basePath = "{{.BasePath}}" 14 | {{end}} 15 | structTags { 16 | {{range $key, $value := .StructTags}} 17 | ["{{$key}}"] = "{{$value}}" 18 | {{end}} 19 | } 20 | } 21 | moduleToGenerate = theModule 22 | }.output 23 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security 2 | 3 | For the protection of our community, the Pkl team does not disclose, discuss, or confirm security issues until our investigation is complete and any necessary updates are generally available. 4 | 5 | ## Reporting a security vulnerability 6 | 7 | If you have discovered a security vulnerability within the Pkl Go Example project, please report it to us. 8 | We welcome reports from everyone, including security researchers, developers, and users. 9 | 10 | Security vulnerabilities may be reported on the [Report a vulnerability](https://security.apple.com/submit) form. 11 | When submitting a vulnerability, select "Apple Devices and Software" as the affected platform, and "Open Source" as the affected area. 12 | 13 | For more information, see https://pkl-lang.org/security.html. 14 | -------------------------------------------------------------------------------- /docs/modules/ROOT/pages/index.adoc: -------------------------------------------------------------------------------- 1 | = Integration with Go 2 | 3 | Pkl provides a rich integration with Go. Our integration allows you to embed the Pkl runtime into your Go program, and also provides code generation from Pkl source code. 4 | 5 | To get started, reference the xref:quickstart.adoc[Quickstart guide]. 6 | Alternatively, use our https://github.com/apple/pkl-go-examples[example project] as a way to get bootstrapped and on your way. 7 | 8 | [source,go] 9 | ---- 10 | package main 11 | 12 | import ( 13 | "context" 14 | "fmt" 15 | 16 | "github.com/myteam/myapp/myconfig" 17 | ) 18 | 19 | func main() { 20 | cfg, err := myconfig.LoadFromPath(context.Background(), "config.pkl") 21 | if err != nil { 22 | panic(err) 23 | } 24 | fmt.Printf("I'm running on host %s\n", cfg.Host) 25 | } 26 | ---- 27 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/bugholder/init.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `org.foo.BugHolder`. DO NOT EDIT. 2 | package bugholder 3 | 4 | import "github.com/apple/pkl-go/pkl" 5 | 6 | func init() { 7 | pkl.RegisterStrictMapping("org.foo.BugHolder", BugHolder{}) 8 | pkl.RegisterStrictMapping("org.foo.BugHolder#B", BImpl{}) 9 | pkl.RegisterStrictMapping("org.foo.BugHolder#Bike", Bike{}) 10 | pkl.RegisterStrictMapping("org.foo.BugHolder#Bug", Bug{}) 11 | pkl.RegisterStrictMapping("org.foo.BugHolder#C", CImpl{}) 12 | pkl.RegisterStrictMapping("org.foo.BugHolder#D", DImpl{}) 13 | pkl.RegisterStrictMapping("org.foo.BugHolder#Person", PersonImpl{}) 14 | pkl.RegisterStrictMapping("org.foo.BugHolder#ThisPerson", ThisPersonImpl{}) 15 | pkl.RegisterStrictMapping("org.foo.BugHolder#Wheel", Wheel{}) 16 | } 17 | -------------------------------------------------------------------------------- /scripts/license-header.txt: -------------------------------------------------------------------------------- 1 | Copyright ©{{ " " }}{%- if attrs.git_file_modified_year != attrs.git_file_created_year -%}{{ attrs.git_file_created_year }}-{{ attrs.git_file_modified_year }}{%- else -%}{{ attrs.git_file_created_year }}{%- endif -%}{{ " " }}Apple Inc. and the Pkl project authors. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | https://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/extendabstractclass/C.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `ExtendsAbstractClass`. DO NOT EDIT. 2 | package extendabstractclass 3 | 4 | import ( 5 | "github.com/apple/pkl-go/codegen/snippet-tests/output/support/lib2/cities" 6 | "github.com/apple/pkl-go/codegen/snippet-tests/output/support/lib3" 7 | ) 8 | 9 | type C interface { 10 | B 11 | 12 | GetD() string 13 | } 14 | 15 | var _ C = CImpl{} 16 | 17 | type CImpl struct { 18 | B string `pkl:"b"` 19 | 20 | D string `pkl:"d"` 21 | 22 | E cities.Cities `pkl:"e"` 23 | 24 | C lib3.GoGoGo `pkl:"c"` 25 | } 26 | 27 | func (rcv CImpl) GetB() string { 28 | return rcv.B 29 | } 30 | 31 | func (rcv CImpl) GetD() string { 32 | return rcv.D 33 | } 34 | 35 | func (rcv CImpl) GetE() cities.Cities { 36 | return rcv.E 37 | } 38 | 39 | func (rcv CImpl) GetC() lib3.GoGoGo { 40 | return rcv.C 41 | } 42 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/explicitname/configtype/ConfigType.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `ExplicitName`. DO NOT EDIT. 2 | package configtype 3 | 4 | import ( 5 | "encoding" 6 | "fmt" 7 | ) 8 | 9 | type ConfigType string 10 | 11 | const ( 12 | One ConfigType = "one" 13 | Two ConfigType = "two" 14 | ) 15 | 16 | // String returns the string representation of ConfigType 17 | func (rcv ConfigType) String() string { 18 | return string(rcv) 19 | } 20 | 21 | var _ encoding.BinaryUnmarshaler = new(ConfigType) 22 | 23 | // UnmarshalBinary implements encoding.BinaryUnmarshaler for ConfigType. 24 | func (rcv *ConfigType) UnmarshalBinary(data []byte) error { 25 | switch str := string(data); str { 26 | case "one": 27 | *rcv = One 28 | case "two": 29 | *rcv = Two 30 | default: 31 | return fmt.Errorf(`illegal: "%s" is not a valid ConfigType`, str) 32 | } 33 | return nil 34 | } 35 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/unions/number/Number.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `unions`. DO NOT EDIT. 2 | package number 3 | 4 | import ( 5 | "encoding" 6 | "fmt" 7 | ) 8 | 9 | type Number string 10 | 11 | const ( 12 | One Number = "one" 13 | Two Number = "two" 14 | Three Number = "three" 15 | ) 16 | 17 | // String returns the string representation of Number 18 | func (rcv Number) String() string { 19 | return string(rcv) 20 | } 21 | 22 | var _ encoding.BinaryUnmarshaler = new(Number) 23 | 24 | // UnmarshalBinary implements encoding.BinaryUnmarshaler for Number. 25 | func (rcv *Number) UnmarshalBinary(data []byte) error { 26 | switch str := string(data); str { 27 | case "one": 28 | *rcv = One 29 | case "two": 30 | *rcv = Two 31 | case "three": 32 | *rcv = Three 33 | default: 34 | return fmt.Errorf(`illegal: "%s" is not a valid Number`, str) 35 | } 36 | return nil 37 | } 38 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/unionnamekeyword/_type/Type.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `UnionNameKeyword`. DO NOT EDIT. 2 | package _type 3 | 4 | import ( 5 | "encoding" 6 | "fmt" 7 | ) 8 | 9 | type Type string 10 | 11 | const ( 12 | One Type = "one" 13 | Two Type = "two" 14 | Three Type = "three" 15 | ) 16 | 17 | // String returns the string representation of Type 18 | func (rcv Type) String() string { 19 | return string(rcv) 20 | } 21 | 22 | var _ encoding.BinaryUnmarshaler = new(Type) 23 | 24 | // UnmarshalBinary implements encoding.BinaryUnmarshaler for Type. 25 | func (rcv *Type) UnmarshalBinary(data []byte) error { 26 | switch str := string(data); str { 27 | case "one": 28 | *rcv = One 29 | case "two": 30 | *rcv = Two 31 | case "three": 32 | *rcv = Three 33 | default: 34 | return fmt.Errorf(`illegal: "%s" is not a valid Type`, str) 35 | } 36 | return nil 37 | } 38 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/support/lib/myenum/MyEnum.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `lib`. DO NOT EDIT. 2 | package myenum 3 | 4 | import ( 5 | "encoding" 6 | "fmt" 7 | ) 8 | 9 | type MyEnum string 10 | 11 | const ( 12 | One MyEnum = "one" 13 | Two MyEnum = "two" 14 | Three MyEnum = "three" 15 | ) 16 | 17 | // String returns the string representation of MyEnum 18 | func (rcv MyEnum) String() string { 19 | return string(rcv) 20 | } 21 | 22 | var _ encoding.BinaryUnmarshaler = new(MyEnum) 23 | 24 | // UnmarshalBinary implements encoding.BinaryUnmarshaler for MyEnum. 25 | func (rcv *MyEnum) UnmarshalBinary(data []byte) error { 26 | switch str := string(data); str { 27 | case "one": 28 | *rcv = One 29 | case "two": 30 | *rcv = Two 31 | case "three": 32 | *rcv = Three 33 | default: 34 | return fmt.Errorf(`illegal: "%s" is not a valid MyEnum`, str) 35 | } 36 | return nil 37 | } 38 | -------------------------------------------------------------------------------- /codegen/src/tests/fixtures/types3.pkl: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | class Bike 18 | -------------------------------------------------------------------------------- /pkl/test_fixtures/testfs/subdir/person.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | 17 | amends "..." 18 | 19 | name = "Fred" 20 | -------------------------------------------------------------------------------- /pkl/test_fixtures/testfs/person.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | 17 | name: String = "Barney" 18 | 19 | age: Int = 43 20 | -------------------------------------------------------------------------------- /codegen/src/tests/fixtures/types4.pkl: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | class Foo { 18 | bar: Listing 19 | } 20 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/unions/othernumbers/OtherNumbers.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `unions`. DO NOT EDIT. 2 | package othernumbers 3 | 4 | import ( 5 | "encoding" 6 | "fmt" 7 | ) 8 | 9 | type OtherNumbers string 10 | 11 | const ( 12 | N一 OtherNumbers = "一" 13 | N二 OtherNumbers = "二" 14 | N三 OtherNumbers = "三" 15 | ) 16 | 17 | // String returns the string representation of OtherNumbers 18 | func (rcv OtherNumbers) String() string { 19 | return string(rcv) 20 | } 21 | 22 | var _ encoding.BinaryUnmarshaler = new(OtherNumbers) 23 | 24 | // UnmarshalBinary implements encoding.BinaryUnmarshaler for OtherNumbers. 25 | func (rcv *OtherNumbers) UnmarshalBinary(data []byte) error { 26 | switch str := string(data); str { 27 | case "一": 28 | *rcv = N一 29 | case "二": 30 | *rcv = N二 31 | case "三": 32 | *rcv = N三 33 | default: 34 | return fmt.Errorf(`illegal: "%s" is not a valid OtherNumbers`, str) 35 | } 36 | return nil 37 | } 38 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/union/city/City.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `union`. DO NOT EDIT. 2 | package city 3 | 4 | import ( 5 | "encoding" 6 | "fmt" 7 | ) 8 | 9 | // City; e.g. where people live 10 | type City string 11 | 12 | const ( 13 | SanFrancisco City = "San Francisco" 14 | London City = "London" 15 | N上海 City = "上海" 16 | ) 17 | 18 | // String returns the string representation of City 19 | func (rcv City) String() string { 20 | return string(rcv) 21 | } 22 | 23 | var _ encoding.BinaryUnmarshaler = new(City) 24 | 25 | // UnmarshalBinary implements encoding.BinaryUnmarshaler for City. 26 | func (rcv *City) UnmarshalBinary(data []byte) error { 27 | switch str := string(data); str { 28 | case "San Francisco": 29 | *rcv = SanFrancisco 30 | case "London": 31 | *rcv = London 32 | case "上海": 33 | *rcv = N上海 34 | default: 35 | return fmt.Errorf(`illegal: "%s" is not a valid City`, str) 36 | } 37 | return nil 38 | } 39 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/bugholder/bugkind/BugKind.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `org.foo.BugHolder`. DO NOT EDIT. 2 | package bugkind 3 | 4 | import ( 5 | "encoding" 6 | "fmt" 7 | ) 8 | 9 | type BugKind string 10 | 11 | const ( 12 | Butterfly BugKind = "butterfly" 13 | Beetle BugKind = `beetle"` 14 | BeetleOne BugKind = "beetle one" 15 | ) 16 | 17 | // String returns the string representation of BugKind 18 | func (rcv BugKind) String() string { 19 | return string(rcv) 20 | } 21 | 22 | var _ encoding.BinaryUnmarshaler = new(BugKind) 23 | 24 | // UnmarshalBinary implements encoding.BinaryUnmarshaler for BugKind. 25 | func (rcv *BugKind) UnmarshalBinary(data []byte) error { 26 | switch str := string(data); str { 27 | case "butterfly": 28 | *rcv = Butterfly 29 | case `beetle"`: 30 | *rcv = Beetle 31 | case "beetle one": 32 | *rcv = BeetleOne 33 | default: 34 | return fmt.Errorf(`illegal: "%s" is not a valid BugKind`, str) 35 | } 36 | return nil 37 | } 38 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/support/lib2/cities/Cities.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `lib2`. DO NOT EDIT. 2 | package cities 3 | 4 | import ( 5 | "encoding" 6 | "fmt" 7 | ) 8 | 9 | type Cities string 10 | 11 | const ( 12 | London Cities = "London" 13 | SanFrancisco Cities = "San Francisco" 14 | LosAngeles Cities = "Los Angeles" 15 | ) 16 | 17 | // String returns the string representation of Cities 18 | func (rcv Cities) String() string { 19 | return string(rcv) 20 | } 21 | 22 | var _ encoding.BinaryUnmarshaler = new(Cities) 23 | 24 | // UnmarshalBinary implements encoding.BinaryUnmarshaler for Cities. 25 | func (rcv *Cities) UnmarshalBinary(data []byte) error { 26 | switch str := string(data); str { 27 | case "London": 28 | *rcv = London 29 | case "San Francisco": 30 | *rcv = SanFrancisco 31 | case "Los Angeles": 32 | *rcv = LosAngeles 33 | default: 34 | return fmt.Errorf(`illegal: "%s" is not a valid Cities`, str) 35 | } 36 | return nil 37 | } 38 | -------------------------------------------------------------------------------- /codegen/snippet-tests/generator-settings.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | amends "../src/GeneratorSettings.pkl" 17 | 18 | generatorScriptPath = "codegen/src/Generator.pkl" 19 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/bugholder/Bug.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `org.foo.BugHolder`. DO NOT EDIT. 2 | package bugholder 3 | 4 | import ( 5 | "github.com/apple/pkl-go/codegen/snippet-tests/output/bugholder/bugkind" 6 | "github.com/apple/pkl-go/codegen/snippet-tests/output/bugholder/bugkindtwo" 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type Bug struct { 11 | // The owner of this bug. 12 | Owner *Person `pkl:"owner"` 13 | 14 | // The age of this bug 15 | Age *int `pkl:"age"` 16 | 17 | // How long the bug holds its breath for 18 | HoldsBreathFor pkl.Duration `pkl:"holdsBreathFor"` 19 | 20 | Size pkl.DataSize `pkl:"size"` 21 | 22 | Kind bugkind.BugKind `pkl:"kind"` 23 | 24 | Kind2 bugkindtwo.BugKindTwo `pkl:"kind2"` 25 | 26 | Kind3 string `pkl:"kind3"` 27 | 28 | Kind4 string `pkl:"kind4"` 29 | 30 | BagOfStuff pkl.Object `pkl:"bagOfStuff"` 31 | 32 | BugClass pkl.Class `pkl:"bugClass"` 33 | 34 | BugTypeAlias pkl.TypeAlias `pkl:"bugTypeAlias"` 35 | } 36 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/union/noodles/Noodles.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `union`. DO NOT EDIT. 2 | package noodles 3 | 4 | import ( 5 | "encoding" 6 | "fmt" 7 | ) 8 | 9 | // Noodles 10 | type Noodles string 11 | 12 | const ( 13 | N拉面 Noodles = "拉面" 14 | N刀切面 Noodles = "刀切面" 15 | N面线 Noodles = "面线" 16 | N意大利面 Noodles = "意大利面" 17 | ) 18 | 19 | // String returns the string representation of Noodles 20 | func (rcv Noodles) String() string { 21 | return string(rcv) 22 | } 23 | 24 | var _ encoding.BinaryUnmarshaler = new(Noodles) 25 | 26 | // UnmarshalBinary implements encoding.BinaryUnmarshaler for Noodles. 27 | func (rcv *Noodles) UnmarshalBinary(data []byte) error { 28 | switch str := string(data); str { 29 | case "拉面": 30 | *rcv = N拉面 31 | case "刀切面": 32 | *rcv = N刀切面 33 | case "面线": 34 | *rcv = N面线 35 | case "意大利面": 36 | *rcv = N意大利面 37 | default: 38 | return fmt.Errorf(`illegal: "%s" is not a valid Noodles`, str) 39 | } 40 | return nil 41 | } 42 | -------------------------------------------------------------------------------- /scripts/create_notice.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | set -x 17 | 18 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 19 | 20 | cd cmd/pkl-gen-go || exit 1 21 | 22 | go-licenses report ./... --template "$SCRIPT_DIR/notice.tpl" --ignore github.com/apple/pkl-go > "$SCRIPT_DIR"/../NOTICE.txt 23 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/union/county/County.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `union`. DO NOT EDIT. 2 | package county 3 | 4 | import ( 5 | "encoding" 6 | "fmt" 7 | ) 8 | 9 | // Locale that contains cities and towns 10 | type County string 11 | 12 | const ( 13 | SanFrancisco County = "San Francisco" 14 | SanMateo County = "San Mateo" 15 | Yolo County = "Yolo" 16 | ) 17 | 18 | // String returns the string representation of County 19 | func (rcv County) String() string { 20 | return string(rcv) 21 | } 22 | 23 | var _ encoding.BinaryUnmarshaler = new(County) 24 | 25 | // UnmarshalBinary implements encoding.BinaryUnmarshaler for County. 26 | func (rcv *County) UnmarshalBinary(data []byte) error { 27 | switch str := string(data); str { 28 | case "San Francisco": 29 | *rcv = SanFrancisco 30 | case "San Mateo": 31 | *rcv = SanMateo 32 | case "Yolo": 33 | *rcv = Yolo 34 | default: 35 | return fmt.Errorf(`illegal: "%s" is not a valid County`, str) 36 | } 37 | return nil 38 | } 39 | -------------------------------------------------------------------------------- /codegen/src/tests/fixtures/types2.pkl: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | import "types3.pkl" 18 | 19 | class Person { 20 | bikes: Listing 21 | otherbikes: Listing 22 | } 23 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/bugholder/bugkindtwo/BugKindTwo.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `org.foo.BugHolder`. DO NOT EDIT. 2 | package bugkindtwo 3 | 4 | import ( 5 | "encoding" 6 | "fmt" 7 | ) 8 | 9 | type BugKindTwo string 10 | 11 | const ( 12 | Butterfly BugKindTwo = "butterfly" 13 | Beetle BugKindTwo = `beetle"` 14 | BeetleOne BugKindTwo = "beetle one" 15 | ) 16 | 17 | // String returns the string representation of BugKindTwo 18 | func (rcv BugKindTwo) String() string { 19 | return string(rcv) 20 | } 21 | 22 | var _ encoding.BinaryUnmarshaler = new(BugKindTwo) 23 | 24 | // UnmarshalBinary implements encoding.BinaryUnmarshaler for BugKindTwo. 25 | func (rcv *BugKindTwo) UnmarshalBinary(data []byte) error { 26 | switch str := string(data); str { 27 | case "butterfly": 28 | *rcv = Butterfly 29 | case `beetle"`: 30 | *rcv = Beetle 31 | case "beetle one": 32 | *rcv = BeetleOne 33 | default: 34 | return fmt.Errorf(`illegal: "%s" is not a valid BugKindTwo`, str) 35 | } 36 | return nil 37 | } 38 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/support/lib/Lib.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `lib`. DO NOT EDIT. 2 | package lib 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type Lib struct { 11 | } 12 | 13 | // LoadFromPath loads the pkl module at the given path and evaluates it into a Lib 14 | func LoadFromPath(ctx context.Context, path string) (ret Lib, err error) { 15 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 16 | if err != nil { 17 | return ret, err 18 | } 19 | defer func() { 20 | cerr := evaluator.Close() 21 | if err == nil { 22 | err = cerr 23 | } 24 | }() 25 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 26 | return ret, err 27 | } 28 | 29 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a Lib 30 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (Lib, error) { 31 | var ret Lib 32 | err := evaluator.EvaluateModule(ctx, source, &ret) 33 | return ret, err 34 | } 35 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/support/lib3/Lib3.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `lib3`. DO NOT EDIT. 2 | package lib3 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type Lib3 struct { 11 | } 12 | 13 | // LoadFromPath loads the pkl module at the given path and evaluates it into a Lib3 14 | func LoadFromPath(ctx context.Context, path string) (ret Lib3, err error) { 15 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 16 | if err != nil { 17 | return ret, err 18 | } 19 | defer func() { 20 | cerr := evaluator.Close() 21 | if err == nil { 22 | err = cerr 23 | } 24 | }() 25 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 26 | return ret, err 27 | } 28 | 29 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a Lib3 30 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (Lib3, error) { 31 | var ret Lib3 32 | err := evaluator.EvaluateModule(ctx, source, &ret) 33 | return ret, err 34 | } 35 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/EmptyOpenModule.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/emptyopenmodule" } 17 | open module EmptyOpenModule 18 | 19 | import ".../src/go.pkl" 20 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/ExtendModule.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/extendmodule" } 17 | extends "support/OpenModule.pkl" 18 | 19 | import ".../src/go.pkl" 20 | 21 | bar: String 22 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/InvalidPackageName.err.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/import" } 17 | module InvalidPackageName 18 | 19 | import ".../src/go.pkl" 20 | 21 | foo: String 22 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/support/OpenModule.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/support/openmodule" } 17 | open module MyModule 18 | 19 | import ".../src/go.pkl" 20 | 21 | foo: String 22 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/support/lib4/Lib4.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `lib4`. DO NOT EDIT. 2 | package lib4 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type Lib4 struct { 11 | Bar string `pkl:"bar"` 12 | } 13 | 14 | // LoadFromPath loads the pkl module at the given path and evaluates it into a Lib4 15 | func LoadFromPath(ctx context.Context, path string) (ret Lib4, err error) { 16 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 17 | if err != nil { 18 | return ret, err 19 | } 20 | defer func() { 21 | cerr := evaluator.Close() 22 | if err == nil { 23 | err = cerr 24 | } 25 | }() 26 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 27 | return ret, err 28 | } 29 | 30 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a Lib4 31 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (Lib4, error) { 32 | var ret Lib4 33 | err := evaluator.EvaluateModule(ctx, source, &ret) 34 | return ret, err 35 | } 36 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/support/lib3.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/support/lib3" } 17 | module lib3 18 | 19 | import ".../src/go.pkl" 20 | 21 | open class GoGoGo { 22 | duck: "quack" 23 | } 24 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/dynamic/Dynamic.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `dynamic`. DO NOT EDIT. 2 | package dynamic 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type Dynamic struct { 11 | Res1 pkl.Object `pkl:"res1"` 12 | } 13 | 14 | // LoadFromPath loads the pkl module at the given path and evaluates it into a Dynamic 15 | func LoadFromPath(ctx context.Context, path string) (ret Dynamic, err error) { 16 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 17 | if err != nil { 18 | return ret, err 19 | } 20 | defer func() { 21 | cerr := evaluator.Close() 22 | if err == nil { 23 | err = cerr 24 | } 25 | }() 26 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 27 | return ret, err 28 | } 29 | 30 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a Dynamic 31 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (Dynamic, error) { 32 | var ret Dynamic 33 | err := evaluator.EvaluateModule(ctx, source, &ret) 34 | return ret, err 35 | } 36 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/support/lib2.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/support/lib2" } 17 | module lib2 18 | 19 | import ".../src/go.pkl" 20 | 21 | typealias Cities = "London" | "San Francisco" | "Los Angeles" 22 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/support/lib4.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/support/lib4" } 17 | module lib4 18 | 19 | import ".../src/go.pkl" 20 | 21 | bar: String 22 | 23 | class MyLib4 { 24 | foo: module 25 | } 26 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/override/Override.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `override`. DO NOT EDIT. 2 | package override 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type Override struct { 11 | Foo Foo `pkl:"foo"` 12 | } 13 | 14 | // LoadFromPath loads the pkl module at the given path and evaluates it into a Override 15 | func LoadFromPath(ctx context.Context, path string) (ret Override, err error) { 16 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 17 | if err != nil { 18 | return ret, err 19 | } 20 | defer func() { 21 | cerr := evaluator.Close() 22 | if err == nil { 23 | err = cerr 24 | } 25 | }() 26 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 27 | return ret, err 28 | } 29 | 30 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a Override 31 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (Override, error) { 32 | var ret Override 33 | err := evaluator.EvaluateModule(ctx, source, &ret) 34 | return ret, err 35 | } 36 | -------------------------------------------------------------------------------- /generator-settings.pkl: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | // Settings to control codegen 18 | amends "codegen/src/GeneratorSettings.pkl" 19 | 20 | basePath = "github.com/apple/pkl-go" 21 | 22 | generatorScriptPath = "codegen/src/Generator.pkl" 23 | 24 | projectDir = "codegen/src" 25 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/any/Any.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `any`. DO NOT EDIT. 2 | package any 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type Any struct { 11 | Res1 any `pkl:"res1"` 12 | 13 | Res2 any `pkl:"res2"` 14 | 15 | Res3 any `pkl:"res3"` 16 | } 17 | 18 | // LoadFromPath loads the pkl module at the given path and evaluates it into a Any 19 | func LoadFromPath(ctx context.Context, path string) (ret Any, err error) { 20 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 21 | if err != nil { 22 | return ret, err 23 | } 24 | defer func() { 25 | cerr := evaluator.Close() 26 | if err == nil { 27 | err = cerr 28 | } 29 | }() 30 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 31 | return ret, err 32 | } 33 | 34 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a Any 35 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (Any, error) { 36 | var ret Any 37 | err := evaluator.EvaluateModule(ctx, source, &ret) 38 | return ret, err 39 | } 40 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/UnionNameKeyword.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/unionnamekeyword" } 17 | module UnionNameKeyword 18 | 19 | import ".../src/go.pkl" 20 | 21 | typealias Type = "one" | "two" | "three" 22 | 23 | type: Type 24 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/ConflictingNames2.err.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/conflictingnames2" } 17 | module ConflictingNames2 18 | 19 | import ".../src/go.pkl" 20 | 21 | prop: ConflictingNames2 22 | 23 | class ConflictingNames2 24 | -------------------------------------------------------------------------------- /pkl/reader_test.go: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | package pkl 18 | 19 | import ( 20 | "fmt" 21 | "net/url" 22 | "strings" 23 | "testing" 24 | ) 25 | 26 | func TestGetSchemeSpecificPart(t *testing.T) { 27 | u, _ := url.Parse("foo:/bar/baz") 28 | fmt.Println(strings.Split(u.String(), ":")[1]) 29 | } 30 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/unknown_type/UnknownType.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `unknown_type`. DO NOT EDIT. 2 | package unknowntype 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type UnknownType struct { 11 | Res any `pkl:"res"` 12 | } 13 | 14 | // LoadFromPath loads the pkl module at the given path and evaluates it into a UnknownType 15 | func LoadFromPath(ctx context.Context, path string) (ret UnknownType, err error) { 16 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 17 | if err != nil { 18 | return ret, err 19 | } 20 | defer func() { 21 | cerr := evaluator.Close() 22 | if err == nil { 23 | err = cerr 24 | } 25 | }() 26 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 27 | return ret, err 28 | } 29 | 30 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a UnknownType 31 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (UnknownType, error) { 32 | var ret UnknownType 33 | err := evaluator.EvaluateModule(ctx, source, &ret) 34 | return ret, err 35 | } 36 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/support/lib.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/support/lib" } 17 | module lib 18 | 19 | import ".../src/go.pkl" 20 | 21 | open class MyClass { 22 | thing: String 23 | } 24 | 25 | typealias MyEnum = "one" | "two" | "three" 26 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/nomappinghidden/NoMappingHidden.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `NoMappingHidden`. DO NOT EDIT. 2 | package nomappinghidden 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type NoMappingHidden struct { 11 | } 12 | 13 | // LoadFromPath loads the pkl module at the given path and evaluates it into a NoMappingHidden 14 | func LoadFromPath(ctx context.Context, path string) (ret NoMappingHidden, err error) { 15 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 16 | if err != nil { 17 | return ret, err 18 | } 19 | defer func() { 20 | cerr := evaluator.Close() 21 | if err == nil { 22 | err = cerr 23 | } 24 | }() 25 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 26 | return ret, err 27 | } 28 | 29 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a NoMappingHidden 30 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (NoMappingHidden, error) { 31 | var ret NoMappingHidden 32 | err := evaluator.EvaluateModule(ctx, source, &ret) 33 | return ret, err 34 | } 35 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/cyclicmodule/CyclicModule.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `CyclicModule`. DO NOT EDIT. 2 | package cyclicmodule 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type CyclicModule struct { 11 | Thing Cyclic `pkl:"thing"` 12 | } 13 | 14 | // LoadFromPath loads the pkl module at the given path and evaluates it into a CyclicModule 15 | func LoadFromPath(ctx context.Context, path string) (ret CyclicModule, err error) { 16 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 17 | if err != nil { 18 | return ret, err 19 | } 20 | defer func() { 21 | cerr := evaluator.Close() 22 | if err == nil { 23 | err = cerr 24 | } 25 | }() 26 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 27 | return ret, err 28 | } 29 | 30 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a CyclicModule 31 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (CyclicModule, error) { 32 | var ret CyclicModule 33 | err := evaluator.EvaluateModule(ctx, source, &ret) 34 | return ret, err 35 | } 36 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/HiddenProperties.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/hiddenproperties" } 17 | module HiddenProperties 18 | 19 | import ".../src/go.pkl" 20 | 21 | hidden propA: String 22 | 23 | hidden propB: String 24 | 25 | propC: String = propA + propB 26 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/union/accountdisposition/AccountDisposition.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `union`. DO NOT EDIT. 2 | package accountdisposition 3 | 4 | import ( 5 | "encoding" 6 | "fmt" 7 | ) 8 | 9 | type AccountDisposition string 10 | 11 | const ( 12 | Empty AccountDisposition = "" 13 | Icloud3 AccountDisposition = "icloud3" 14 | Prod AccountDisposition = "prod" 15 | Shared AccountDisposition = "shared" 16 | ) 17 | 18 | // String returns the string representation of AccountDisposition 19 | func (rcv AccountDisposition) String() string { 20 | return string(rcv) 21 | } 22 | 23 | var _ encoding.BinaryUnmarshaler = new(AccountDisposition) 24 | 25 | // UnmarshalBinary implements encoding.BinaryUnmarshaler for AccountDisposition. 26 | func (rcv *AccountDisposition) UnmarshalBinary(data []byte) error { 27 | switch str := string(data); str { 28 | case "": 29 | *rcv = Empty 30 | case "icloud3": 31 | *rcv = Icloud3 32 | case "prod": 33 | *rcv = Prod 34 | case "shared": 35 | *rcv = Shared 36 | default: 37 | return fmt.Errorf(`illegal: "%s" is not a valid AccountDisposition`, str) 38 | } 39 | return nil 40 | } 41 | -------------------------------------------------------------------------------- /scripts/test_snippets.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | set -e 17 | 18 | SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)" 19 | SNIPPET_TEST_DIR="$SCRIPT_DIR/codegen/snippet-tests" 20 | 21 | rm -rf "$SNIPPET_TEST_DIR/output" 22 | 23 | go run cmd/internal/gen-snippets/gen-snippets.go 24 | 25 | diff=$(git diff codegen/snippet-tests/) 26 | 27 | if [[ -n "$diff" ]]; then 28 | echo "Error: Snippet tests contains changes!" 29 | echo "$diff" 30 | exit 1 31 | fi 32 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/CyclicModule.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/cyclicmodule" } 17 | module CyclicModule 18 | 19 | import ".../src/go.pkl" 20 | 21 | thing: Cyclic 22 | 23 | class Cyclic { 24 | a: String 25 | 26 | b: Int 27 | 28 | myself: Cyclic? 29 | } 30 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/IllegalOverride.err.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/overrideerr" } 17 | module overrideerr 18 | 19 | import ".../src/go.pkl" 20 | 21 | open class Parent { 22 | prop: Int 23 | } 24 | 25 | class Child extends Parent { 26 | prop: String 27 | } 28 | -------------------------------------------------------------------------------- /.github/PklProject: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | amends "pkl:Project" 18 | 19 | dependencies { 20 | ["pkl.impl.ghactions"] { 21 | uri = "package://pkg.pkl-lang.org/pkl-project-commons/pkl.impl.ghactions@1.1.6" 22 | } 23 | ["com.github.actions"] { 24 | uri = "package://pkg.pkl-lang.org/pkl-pantry/com.github.actions@1.3.0" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/Override.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/override" } 17 | module `override` 18 | 19 | import ".../src/go.pkl" 20 | 21 | abstract class Foo { 22 | myProp: String 23 | } 24 | 25 | class Bar extends Foo { 26 | myProp = "Bar" 27 | } 28 | 29 | foo: Foo 30 | -------------------------------------------------------------------------------- /codegen/src/internal/Gen.pkl: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | @Unlisted 18 | abstract module pkl.golang.internal.Gen 19 | 20 | import "GoMapping.pkl" 21 | 22 | /// The generated contents for this particular mapping. 23 | mapping: GoMapping 24 | 25 | /// All mappings 26 | mappings: List 27 | 28 | /// The Go contents 29 | contents: String 30 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/hiddenproperties/HiddenProperties.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `HiddenProperties`. DO NOT EDIT. 2 | package hiddenproperties 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type HiddenProperties struct { 11 | PropC string `pkl:"propC"` 12 | } 13 | 14 | // LoadFromPath loads the pkl module at the given path and evaluates it into a HiddenProperties 15 | func LoadFromPath(ctx context.Context, path string) (ret HiddenProperties, err error) { 16 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 17 | if err != nil { 18 | return ret, err 19 | } 20 | defer func() { 21 | cerr := evaluator.Close() 22 | if err == nil { 23 | err = cerr 24 | } 25 | }() 26 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 27 | return ret, err 28 | } 29 | 30 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a HiddenProperties 31 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (HiddenProperties, error) { 32 | var ret HiddenProperties 33 | err := evaluator.EvaluateModule(ctx, source, &ret) 34 | return ret, err 35 | } 36 | -------------------------------------------------------------------------------- /pkl/test_fixtures/unions.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | 17 | @go.Package { name = "github.com/apple/pkl-go/pkl/test_fixtures/gen/unions" } 18 | module unions 19 | 20 | import ".../codegen/src/go.pkl" 21 | 22 | res1: Number = "two" 23 | res2: OtherNumbers = "三" 24 | 25 | typealias Number = "one" | "two" | "three" 26 | typealias OtherNumbers = nothing | "一" | "二" | "三" 27 | -------------------------------------------------------------------------------- /pkl/test_fixtures/unknown_type.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | 17 | @go.Package { name = "github.com/apple/pkl-go/pkl/test_fixtures/gen/unknown_type" } 18 | module unknown_type 19 | 20 | import ".../codegen/src/go.pkl" 21 | 22 | // Simulate a situation where a property's type is generated as `any`, and the value is not a type that is codegen'd. 23 | res: Any = new PcfRenderer {} 24 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/ModuleType.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/moduletype" } 17 | module ModuleType 18 | 19 | import ".../src/go.pkl" 20 | import "support/lib4.pkl" 21 | 22 | myStr: String 23 | 24 | foo: module? 25 | 26 | lib: lib4.MyLib4 27 | 28 | fooAgain: Myself? 29 | 30 | typealias Myself = module 31 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/explicitname/ExplicitlyCoolName.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `ExplicitName`. DO NOT EDIT. 2 | package explicitname 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type ExplicitlyCoolName struct { 11 | MyCoolProp SomethingVeryFunny `pkl:"myProp"` 12 | } 13 | 14 | // LoadFromPath loads the pkl module at the given path and evaluates it into a ExplicitlyCoolName 15 | func LoadFromPath(ctx context.Context, path string) (ret ExplicitlyCoolName, err error) { 16 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 17 | if err != nil { 18 | return ret, err 19 | } 20 | defer func() { 21 | cerr := evaluator.Close() 22 | if err == nil { 23 | err = cerr 24 | } 25 | }() 26 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 27 | return ret, err 28 | } 29 | 30 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a ExplicitlyCoolName 31 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (ExplicitlyCoolName, error) { 32 | var ret ExplicitlyCoolName 33 | err := evaluator.EvaluateModule(ctx, source, &ret) 34 | return ret, err 35 | } 36 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/Override2.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/override2" } 17 | open module Override2 18 | 19 | import ".../src/go.pkl" 20 | import "Override2.pkl" 21 | 22 | /// Doc comments 23 | foo: String 24 | 25 | class MySubclass extends Override2 { 26 | /// Different doc comments 27 | foo: String 28 | } 29 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/extendabstractclass/ExtendsAbstractClass.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `ExtendsAbstractClass`. DO NOT EDIT. 2 | package extendabstractclass 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type ExtendsAbstractClass struct { 11 | A A `pkl:"a"` 12 | } 13 | 14 | // LoadFromPath loads the pkl module at the given path and evaluates it into a ExtendsAbstractClass 15 | func LoadFromPath(ctx context.Context, path string) (ret ExtendsAbstractClass, err error) { 16 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 17 | if err != nil { 18 | return ret, err 19 | } 20 | defer func() { 21 | cerr := evaluator.Close() 22 | if err == nil { 23 | err = cerr 24 | } 25 | }() 26 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 27 | return ret, err 28 | } 29 | 30 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a ExtendsAbstractClass 31 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (ExtendsAbstractClass, error) { 32 | var ret ExtendsAbstractClass 33 | err := evaluator.EvaluateModule(ctx, source, &ret) 34 | return ret, err 35 | } 36 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/bugholder/Person.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `org.foo.BugHolder`. DO NOT EDIT. 2 | package bugholder 3 | 4 | type Person interface { 5 | Being 6 | 7 | GetBike() Bike 8 | 9 | GetFirstName() *uint16 10 | 11 | GetLastName() map[string]*uint32 12 | 13 | GetThings() map[int]struct{} 14 | } 15 | 16 | var _ Person = PersonImpl{} 17 | 18 | // A Person! 19 | type PersonImpl struct { 20 | IsAlive bool `pkl:"isAlive"` 21 | 22 | Bike Bike `pkl:"bike"` 23 | 24 | // The person's first name 25 | FirstName *uint16 `pkl:"firstName"` 26 | 27 | // The person's last name 28 | LastName map[string]*uint32 `pkl:"lastName"` 29 | 30 | Things map[int]struct{} `pkl:"things"` 31 | } 32 | 33 | func (rcv PersonImpl) GetIsAlive() bool { 34 | return rcv.IsAlive 35 | } 36 | 37 | func (rcv PersonImpl) GetBike() Bike { 38 | return rcv.Bike 39 | } 40 | 41 | // The person's first name 42 | func (rcv PersonImpl) GetFirstName() *uint16 { 43 | return rcv.FirstName 44 | } 45 | 46 | // The person's last name 47 | func (rcv PersonImpl) GetLastName() map[string]*uint32 { 48 | return rcv.LastName 49 | } 50 | 51 | func (rcv PersonImpl) GetThings() map[int]struct{} { 52 | return rcv.Things 53 | } 54 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/ModuleUsingLib.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/moduleusinglib" } 17 | module ModuleUsingLib 18 | 19 | import ".../src/go.pkl" 20 | import "support/lib.pkl" 21 | import "support/lib2.pkl" 22 | 23 | res: Listing 24 | 25 | res2: lib.MyEnum 26 | 27 | res3: String 28 | 29 | res4: lib2.Cities 30 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/bugholder/BugHolder.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `org.foo.BugHolder`. DO NOT EDIT. 2 | package bugholder 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type BugHolder struct { 11 | Bug Bug `pkl:"bug"` 12 | 13 | N蚊子 Bug `pkl:"蚊子"` 14 | 15 | ThisPerson ThisPerson `pkl:"thisPerson"` 16 | 17 | D D `pkl:"d"` 18 | } 19 | 20 | // LoadFromPath loads the pkl module at the given path and evaluates it into a BugHolder 21 | func LoadFromPath(ctx context.Context, path string) (ret BugHolder, err error) { 22 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 23 | if err != nil { 24 | return ret, err 25 | } 26 | defer func() { 27 | cerr := evaluator.Close() 28 | if err == nil { 29 | err = cerr 30 | } 31 | }() 32 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 33 | return ret, err 34 | } 35 | 36 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a BugHolder 37 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (BugHolder, error) { 38 | var ret BugHolder 39 | err := evaluator.EvaluateModule(ctx, source, &ret) 40 | return ret, err 41 | } 42 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/ConflictingNames.err.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/conflictingnames" } 17 | module ConflictingNames 18 | 19 | import ".../src/go.pkl" 20 | 21 | myClassOne: `Class One` 22 | 23 | otherClass: ClassOne 24 | 25 | class `Class One` { 26 | prop: String 27 | } 28 | 29 | class ClassOne { 30 | prop2: String 31 | } 32 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/extendopenclass/ExtendingOpenClass.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `ExtendingOpenClass`. DO NOT EDIT. 2 | package extendopenclass 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type ExtendingOpenClass struct { 11 | Res1 MyClass `pkl:"res1"` 12 | 13 | Res2 MyClass2 `pkl:"res2"` 14 | } 15 | 16 | // LoadFromPath loads the pkl module at the given path and evaluates it into a ExtendingOpenClass 17 | func LoadFromPath(ctx context.Context, path string) (ret ExtendingOpenClass, err error) { 18 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 19 | if err != nil { 20 | return ret, err 21 | } 22 | defer func() { 23 | cerr := evaluator.Close() 24 | if err == nil { 25 | err = cerr 26 | } 27 | }() 28 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 29 | return ret, err 30 | } 31 | 32 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a ExtendingOpenClass 33 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (ExtendingOpenClass, error) { 34 | var ret ExtendingOpenClass 35 | err := evaluator.EvaluateModule(ctx, source, &ret) 36 | return ret, err 37 | } 38 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/classes/Classes.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `classes`. DO NOT EDIT. 2 | package classes 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type Classes struct { 11 | Animals []Animal `pkl:"animals"` 12 | 13 | NullableAnimals []*Animal `pkl:"nullableAnimals"` 14 | 15 | MyAnimal Animal `pkl:"myAnimal"` 16 | 17 | House House `pkl:"house"` 18 | } 19 | 20 | // LoadFromPath loads the pkl module at the given path and evaluates it into a Classes 21 | func LoadFromPath(ctx context.Context, path string) (ret Classes, err error) { 22 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 23 | if err != nil { 24 | return ret, err 25 | } 26 | defer func() { 27 | cerr := evaluator.Close() 28 | if err == nil { 29 | err = cerr 30 | } 31 | }() 32 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 33 | return ret, err 34 | } 35 | 36 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a Classes 37 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (Classes, error) { 38 | var ret Classes 39 | err := evaluator.EvaluateModule(ctx, source, &ret) 40 | return ret, err 41 | } 42 | -------------------------------------------------------------------------------- /.github/workflows/test_report.yml: -------------------------------------------------------------------------------- 1 | # Generated from Workflow.pkl. DO NOT EDIT. 2 | name: PR Test Reports 3 | 'on': 4 | workflow_run: 5 | types: 6 | - completed 7 | workflows: 8 | - Pull Request 9 | permissions: 10 | contents: read 11 | jobs: 12 | test-results: 13 | name: Test Results 14 | if: github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure' 15 | permissions: 16 | actions: read 17 | checks: write 18 | runs-on: ubuntu-latest 19 | steps: 20 | - name: Download artifacts 21 | uses: dawidd6/action-download-artifact@ac66b43f0e6a346234dd65d4d0c8fbb31cb316e5 # v11 22 | with: 23 | path: artifacts 24 | name: test-results-.* 25 | name_is_regexp: true 26 | run_id: ${{ github.event.workflow_run.id }} 27 | - name: Publish test results 28 | uses: EnricoMi/publish-unit-test-result-action@34d7c956a59aed1bfebf31df77b8de55db9bbaaf # v2 29 | with: 30 | commit: ${{ github.event.workflow_run.head_sha }} 31 | comment_mode: 'off' 32 | files: artifacts/**/*.xml 33 | event_file: artifacts/test-results-event-file/event.json 34 | event_name: ${{ github.event.workflow_run.event }} 35 | -------------------------------------------------------------------------------- /pkl/test_fixtures/dynamic.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | 17 | @go.Package { name = "github.com/apple/pkl-go/pkl/test_fixtures/gen/dynamic" } 18 | module dynamic 19 | 20 | import ".../codegen/src/go.pkl" 21 | 22 | res1: Dynamic = new { 23 | res2 { res3 = 5 } 24 | ["res4"] = 6 25 | new MyClass { myValue = 7 } 26 | res5 = new MyClass { myValue = 8 } 27 | [5] = 9 28 | } 29 | 30 | class MyClass { 31 | myValue: Int 32 | } 33 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/emptyopenmodule/EmptyOpenModule.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `EmptyOpenModule`. DO NOT EDIT. 2 | package emptyopenmodule 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type EmptyOpenModule interface { 11 | } 12 | 13 | var _ EmptyOpenModule = EmptyOpenModuleImpl{} 14 | 15 | type EmptyOpenModuleImpl struct { 16 | } 17 | 18 | // LoadFromPath loads the pkl module at the given path and evaluates it into a EmptyOpenModule 19 | func LoadFromPath(ctx context.Context, path string) (ret EmptyOpenModule, err error) { 20 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 21 | if err != nil { 22 | return ret, err 23 | } 24 | defer func() { 25 | cerr := evaluator.Close() 26 | if err == nil { 27 | err = cerr 28 | } 29 | }() 30 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 31 | return ret, err 32 | } 33 | 34 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a EmptyOpenModule 35 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (EmptyOpenModule, error) { 36 | var ret EmptyOpenModuleImpl 37 | err := evaluator.EvaluateModule(ctx, source, &ret) 38 | return ret, err 39 | } 40 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/unionnamekeyword/UnionNameKeyword.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `UnionNameKeyword`. DO NOT EDIT. 2 | package unionnamekeyword 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/codegen/snippet-tests/output/unionnamekeyword/_type" 8 | "github.com/apple/pkl-go/pkl" 9 | ) 10 | 11 | type UnionNameKeyword struct { 12 | Type _type.Type `pkl:"type"` 13 | } 14 | 15 | // LoadFromPath loads the pkl module at the given path and evaluates it into a UnionNameKeyword 16 | func LoadFromPath(ctx context.Context, path string) (ret UnionNameKeyword, err error) { 17 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 18 | if err != nil { 19 | return ret, err 20 | } 21 | defer func() { 22 | cerr := evaluator.Close() 23 | if err == nil { 24 | err = cerr 25 | } 26 | }() 27 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 28 | return ret, err 29 | } 30 | 31 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a UnionNameKeyword 32 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (UnionNameKeyword, error) { 33 | var ret UnionNameKeyword 34 | err := evaluator.EvaluateModule(ctx, source, &ret) 35 | return ret, err 36 | } 37 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/unions/Unions.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `unions`. DO NOT EDIT. 2 | package unions 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | "github.com/apple/pkl-go/pkl/test_fixtures/gen/unions/number" 9 | "github.com/apple/pkl-go/pkl/test_fixtures/gen/unions/othernumbers" 10 | ) 11 | 12 | type Unions struct { 13 | Res1 number.Number `pkl:"res1"` 14 | 15 | Res2 othernumbers.OtherNumbers `pkl:"res2"` 16 | } 17 | 18 | // LoadFromPath loads the pkl module at the given path and evaluates it into a Unions 19 | func LoadFromPath(ctx context.Context, path string) (ret Unions, err error) { 20 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 21 | if err != nil { 22 | return ret, err 23 | } 24 | defer func() { 25 | cerr := evaluator.Close() 26 | if err == nil { 27 | err = cerr 28 | } 29 | }() 30 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 31 | return ret, err 32 | } 33 | 34 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a Unions 35 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (Unions, error) { 36 | var ret Unions 37 | err := evaluator.EvaluateModule(ctx, source, &ret) 38 | return ret, err 39 | } 40 | -------------------------------------------------------------------------------- /pkl/test_fixtures/duration.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | 17 | @go.Package { name = "github.com/apple/pkl-go/pkl/test_fixtures/gen/duration" } 18 | module duration 19 | 20 | import ".../codegen/src/go.pkl" 21 | 22 | res1: Duration = 1.ns 23 | 24 | res2: Duration = 2.us 25 | 26 | res3: Duration = 3.ms 27 | 28 | res4: Duration = 4.s 29 | 30 | res5: Duration = 5.min 31 | 32 | res6: Duration = 6.h 33 | 34 | res7: Duration = 7.d 35 | 36 | res8: DurationUnit = "us" 37 | -------------------------------------------------------------------------------- /pkl/evaluator_manager_exec_windows.go: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | package pkl 18 | 19 | import ( 20 | "os" 21 | "os/exec" 22 | "strconv" 23 | ) 24 | 25 | func (e *execEvaluator) getStartCommand() *exec.Cmd { 26 | cmd, arg := e.getCommandAndArgStrings() 27 | return exec.Command(cmd, append(arg, "server")...) 28 | } 29 | 30 | func killProcess(proc *os.Process) error { 31 | return exec.Command("TASKKILL", "/T", "/F", "/PID", strconv.Itoa(proc.Pid)).Run() 32 | } 33 | -------------------------------------------------------------------------------- /codegen/src/tests/fixtures/ClassGen.pkl: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | amends "pkl:test" 18 | 19 | import "pkl:reflect" 20 | 21 | import ".../internal/ClassGen.pkl" 22 | 23 | local class Person { 24 | name: String 25 | hobbies: List 26 | hidden talent: String 27 | } 28 | 29 | facts { 30 | ["getFields ignores hidden members"] { 31 | local fields = ClassGen.getFields(reflect.Class(Person), List()) 32 | fields.keys == Set("name", "hobbies") 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /pkl/module_source_test.go: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | package pkl 18 | 19 | import ( 20 | "testing" 21 | 22 | "github.com/stretchr/testify/assert" 23 | ) 24 | 25 | func Test_PathSource(t *testing.T) { 26 | src := FileSource("/usr/local/myfile.pkl") 27 | assert.Equal(t, "file:///usr/local/myfile.pkl", src.Uri.String()) 28 | src = FileSource("/usr", "local", "lib", "myotherfile.pkl") 29 | assert.Equal(t, "file:///usr/local/lib/myotherfile.pkl", src.Uri.String()) 30 | } 31 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/support/openmodule/MyModule.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `MyModule`. DO NOT EDIT. 2 | package openmodule 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type MyModule interface { 11 | GetFoo() string 12 | } 13 | 14 | var _ MyModule = MyModuleImpl{} 15 | 16 | type MyModuleImpl struct { 17 | Foo string `pkl:"foo"` 18 | } 19 | 20 | func (rcv MyModuleImpl) GetFoo() string { 21 | return rcv.Foo 22 | } 23 | 24 | // LoadFromPath loads the pkl module at the given path and evaluates it into a MyModule 25 | func LoadFromPath(ctx context.Context, path string) (ret MyModule, err error) { 26 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 27 | if err != nil { 28 | return ret, err 29 | } 30 | defer func() { 31 | cerr := evaluator.Close() 32 | if err == nil { 33 | err = cerr 34 | } 35 | }() 36 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 37 | return ret, err 38 | } 39 | 40 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a MyModule 41 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (MyModule, error) { 42 | var ret MyModuleImpl 43 | err := evaluator.EvaluateModule(ctx, source, &ret) 44 | return ret, err 45 | } 46 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/types/Types.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `types`. DO NOT EDIT. 2 | package types 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type Types struct { 11 | StringClass pkl.Class `pkl:"stringClass"` 12 | 13 | BaseModuleClass pkl.Class `pkl:"baseModuleClass"` 14 | 15 | Uint8TypeAlias pkl.TypeAlias `pkl:"uint8TypeAlias"` 16 | 17 | FooClass pkl.Class `pkl:"fooClass"` 18 | 19 | BarTypeAlias pkl.TypeAlias `pkl:"barTypeAlias"` 20 | } 21 | 22 | // LoadFromPath loads the pkl module at the given path and evaluates it into a Types 23 | func LoadFromPath(ctx context.Context, path string) (ret Types, err error) { 24 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 25 | if err != nil { 26 | return ret, err 27 | } 28 | defer func() { 29 | cerr := evaluator.Close() 30 | if err == nil { 31 | err = cerr 32 | } 33 | }() 34 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 35 | return ret, err 36 | } 37 | 38 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a Types 39 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (Types, error) { 40 | var ret Types 41 | err := evaluator.EvaluateModule(ctx, source, &ret) 42 | return ret, err 43 | } 44 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/ExplicitName.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/explicitname" } 17 | @go.Name { value = "ExplicitlyCoolName" } 18 | module ExplicitName 19 | 20 | import ".../src/go.pkl" 21 | 22 | @go.Name { value = "MyCoolProp" } 23 | myProp: SomethingFunny 24 | 25 | @go.Name { value = "SomethingVeryFunny" } 26 | class SomethingFunny {} 27 | 28 | @go.Name { value = "ConfigType" } 29 | typealias Type = "one" | "two" 30 | -------------------------------------------------------------------------------- /pkl/test_fixtures/any.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | 17 | @go.Package { name = "github.com/apple/pkl-go/pkl/test_fixtures/gen/any" } 18 | module any 19 | 20 | import ".../codegen/src/go.pkl" 21 | 22 | class Person { 23 | name: String 24 | } 25 | 26 | res1 = new Listing { 27 | new { 28 | name = "Barney" 29 | } 30 | } 31 | 32 | res2 = new Person { 33 | name = "Bobby" 34 | } 35 | 36 | res3 = new Mapping { 37 | ["Wilma"] { 38 | name = "Wilma" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/moduletype/ModuleType.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `ModuleType`. DO NOT EDIT. 2 | package moduletype 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/codegen/snippet-tests/output/support/lib4" 8 | "github.com/apple/pkl-go/pkl" 9 | ) 10 | 11 | type ModuleType struct { 12 | MyStr string `pkl:"myStr"` 13 | 14 | Foo *ModuleType `pkl:"foo"` 15 | 16 | Lib lib4.MyLib4 `pkl:"lib"` 17 | 18 | FooAgain *ModuleType `pkl:"fooAgain"` 19 | } 20 | 21 | // LoadFromPath loads the pkl module at the given path and evaluates it into a ModuleType 22 | func LoadFromPath(ctx context.Context, path string) (ret ModuleType, err error) { 23 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 24 | if err != nil { 25 | return ret, err 26 | } 27 | defer func() { 28 | cerr := evaluator.Close() 29 | if err == nil { 30 | err = cerr 31 | } 32 | }() 33 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 34 | return ret, err 35 | } 36 | 37 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a ModuleType 38 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (ModuleType, error) { 39 | var ret ModuleType 40 | err := evaluator.EvaluateModule(ctx, source, &ret) 41 | return ret, err 42 | } 43 | -------------------------------------------------------------------------------- /.github/workflows/__lockfile__.yml: -------------------------------------------------------------------------------- 1 | #file: noinspection MandatoryParamsAbsent,UndefinedAction 2 | # This is a fake workflow that never runs. 3 | # It's used to pin actions to specific git SHAs when generating actual workflows. 4 | # It also gets updated by dependabot (see .github/dependabot.yml). 5 | # Generated from Workflow.pkl. DO NOT EDIT. 6 | name: __lockfile__ 7 | 'on': 8 | push: 9 | branches-ignore: 10 | - '**' 11 | tags-ignore: 12 | - '**' 13 | jobs: 14 | locks: 15 | if: 'false' 16 | runs-on: nothing 17 | steps: 18 | - name: EnricoMi/publish-unit-test-result-action@v2 19 | uses: EnricoMi/publish-unit-test-result-action@34d7c956a59aed1bfebf31df77b8de55db9bbaaf # v2 20 | - name: actions/checkout@v6 21 | uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 22 | - name: actions/download-artifact@v6 23 | uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6 24 | - name: actions/setup-go@v6 25 | uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6 26 | - name: actions/upload-artifact@v5 27 | uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5 28 | - name: dawidd6/action-download-artifact@v11 29 | uses: dawidd6/action-download-artifact@ac66b43f0e6a346234dd65d4d0c8fbb31cb316e5 # v11 30 | -------------------------------------------------------------------------------- /pkl/test_fixtures/primitives.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | 17 | @go.Package { name = "github.com/apple/pkl-go/pkl/test_fixtures/gen/primitives" } 18 | module primitives 19 | 20 | import ".../codegen/src/go.pkl" 21 | 22 | res0: String = "bar" 23 | res1: Int = 1 24 | res2: Int8 = 2 25 | res3: Int16 = 3 26 | res4: Int32 = 4 27 | res5: UInt = 5 28 | res6: UInt8 = 6 29 | res7: UInt16 = 7 30 | res8: UInt32 = 8 31 | res9: Float = 5.3 32 | res10: Boolean = true 33 | res11: Null = null 34 | res12: Number = 33 35 | res13: Number = 33.3333 36 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/override2/Override2.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `Override2`. DO NOT EDIT. 2 | package override2 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type Override2 interface { 11 | GetFoo() string 12 | } 13 | 14 | var _ Override2 = Override2Impl{} 15 | 16 | type Override2Impl struct { 17 | // Doc comments 18 | Foo string `pkl:"foo"` 19 | } 20 | 21 | // Doc comments 22 | func (rcv Override2Impl) GetFoo() string { 23 | return rcv.Foo 24 | } 25 | 26 | // LoadFromPath loads the pkl module at the given path and evaluates it into a Override2 27 | func LoadFromPath(ctx context.Context, path string) (ret Override2, err error) { 28 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 29 | if err != nil { 30 | return ret, err 31 | } 32 | defer func() { 33 | cerr := evaluator.Close() 34 | if err == nil { 35 | err = cerr 36 | } 37 | }() 38 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 39 | return ret, err 40 | } 41 | 42 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a Override2 43 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (Override2, error) { 44 | var ret Override2Impl 45 | err := evaluator.EvaluateModule(ctx, source, &ret) 46 | return ret, err 47 | } 48 | -------------------------------------------------------------------------------- /pkl/internal/debug.go: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | package internal 18 | 19 | import ( 20 | "fmt" 21 | "os" 22 | ) 23 | 24 | var DebugEnabled bool 25 | 26 | func init() { 27 | if value, exists := os.LookupEnv("PKL_DEBUG"); exists && value == "1" { 28 | DebugEnabled = true 29 | } 30 | } 31 | 32 | // Debug writes debugging messages if PKL_DEBUG is set to 1. 33 | func Debug(format string, a ...any) { 34 | if DebugEnabled { 35 | _, _ = os.Stderr.WriteString("[pkl-go] " + fmt.Sprintf(format, a...) + "\n") 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/ExtendAbstractClass.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/extendabstractclass" } 17 | module ExtendsAbstractClass 18 | 19 | import ".../src/go.pkl" 20 | import "support/lib2.pkl" 21 | import "support/lib3.pkl" 22 | 23 | abstract class A { 24 | b: String 25 | c: lib3.GoGoGo 26 | } 27 | 28 | abstract class B extends A { 29 | b = "hello" 30 | e: lib2.Cities 31 | } 32 | 33 | class C extends B { 34 | b = "hi" 35 | d: String 36 | } 37 | 38 | a: A 39 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/ExtendOpenClass.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/extendopenclass" } 17 | module ExtendingOpenClass 18 | 19 | import ".../src/go.pkl" 20 | import "support/lib3.pkl" 21 | 22 | res1: MyClass 23 | 24 | res2: MyClass2 25 | 26 | open class MyOpenClass { 27 | myStr: String 28 | } 29 | 30 | class MyClass extends MyOpenClass { 31 | myStr = "mystr" 32 | myBoolean: Boolean 33 | } 34 | 35 | class MyClass2 extends lib3.GoGoGo { 36 | myBoolean: Boolean 37 | } 38 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/duration/Duration.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `duration`. DO NOT EDIT. 2 | package duration 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type Duration struct { 11 | Res1 pkl.Duration `pkl:"res1"` 12 | 13 | Res2 pkl.Duration `pkl:"res2"` 14 | 15 | Res3 pkl.Duration `pkl:"res3"` 16 | 17 | Res4 pkl.Duration `pkl:"res4"` 18 | 19 | Res5 pkl.Duration `pkl:"res5"` 20 | 21 | Res6 pkl.Duration `pkl:"res6"` 22 | 23 | Res7 pkl.Duration `pkl:"res7"` 24 | 25 | Res8 pkl.DurationUnit `pkl:"res8"` 26 | } 27 | 28 | // LoadFromPath loads the pkl module at the given path and evaluates it into a Duration 29 | func LoadFromPath(ctx context.Context, path string) (ret Duration, err error) { 30 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 31 | if err != nil { 32 | return ret, err 33 | } 34 | defer func() { 35 | cerr := evaluator.Close() 36 | if err == nil { 37 | err = cerr 38 | } 39 | }() 40 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 41 | return ret, err 42 | } 43 | 44 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a Duration 45 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (Duration, error) { 46 | var ret Duration 47 | err := evaluator.EvaluateModule(ctx, source, &ret) 48 | return ret, err 49 | } 50 | -------------------------------------------------------------------------------- /pkl/test_fixtures/datasize.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | 17 | @go.Package { name = "github.com/apple/pkl-go/pkl/test_fixtures/gen/datasize" } 18 | module datasize 19 | 20 | import ".../codegen/src/go.pkl" 21 | 22 | res1: DataSize = 1.b 23 | 24 | res2: DataSize = 2.kb 25 | 26 | res3: DataSize = 3.mb 27 | 28 | res4: DataSize = 4.gb 29 | 30 | res5: DataSize = 5.tb 31 | 32 | res6: DataSize = 6.pb 33 | 34 | res7: DataSize = 7.kib 35 | 36 | res8: DataSize = 8.mib 37 | 38 | res9: DataSize = 9.gib 39 | 40 | res10: DataSize = 10.tib 41 | 42 | res11: DataSize = 11.pib 43 | 44 | res12: DataSizeUnit = "mb" 45 | -------------------------------------------------------------------------------- /.github/PklProject.deps.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": 1, 3 | "resolvedDependencies": { 4 | "package://pkg.pkl-lang.org/pkl-pantry/com.github.actions@1": { 5 | "type": "remote", 6 | "uri": "projectpackage://pkg.pkl-lang.org/pkl-pantry/com.github.actions@1.3.0", 7 | "checksums": { 8 | "sha256": "76174cb974310b3d952280b76ed224eb4ee6fd5419bf696ad9a66fba44bd427d" 9 | } 10 | }, 11 | "package://pkg.pkl-lang.org/pkl-project-commons/pkl.impl.ghactions@1": { 12 | "type": "remote", 13 | "uri": "projectpackage://pkg.pkl-lang.org/pkl-project-commons/pkl.impl.ghactions@1.1.6", 14 | "checksums": { 15 | "sha256": "efe36e694f45b0804c5fcc746774727c016c866478b8c1eb0ea86d00c8bd8cf2" 16 | } 17 | }, 18 | "package://pkg.pkl-lang.org/pkl-pantry/pkl.experimental.deepToTyped@1": { 19 | "type": "remote", 20 | "uri": "projectpackage://pkg.pkl-lang.org/pkl-pantry/pkl.experimental.deepToTyped@1.1.1", 21 | "checksums": { 22 | "sha256": "1e6e29b441ffdee2605d317f6543a4a604aab5af472b63f0c47d92a3b4b36f7f" 23 | } 24 | }, 25 | "package://pkg.pkl-lang.org/pkl-pantry/com.github.dependabot@1": { 26 | "type": "remote", 27 | "uri": "projectpackage://pkg.pkl-lang.org/pkl-pantry/com.github.dependabot@1.0.0", 28 | "checksums": { 29 | "sha256": "02ef6f25bfca5b1d095db73ea15de79d2d2c6832ebcab61e6aba90554382abcb" 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/extendmodule/ExtendModule.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `ExtendModule`. DO NOT EDIT. 2 | package extendmodule 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/codegen/snippet-tests/output/support/openmodule" 8 | "github.com/apple/pkl-go/pkl" 9 | ) 10 | 11 | type ExtendModule interface { 12 | openmodule.MyModule 13 | 14 | GetBar() string 15 | } 16 | 17 | var _ ExtendModule = ExtendModuleImpl{} 18 | 19 | type ExtendModuleImpl struct { 20 | openmodule.MyModuleImpl 21 | 22 | Bar string `pkl:"bar"` 23 | } 24 | 25 | func (rcv ExtendModuleImpl) GetBar() string { 26 | return rcv.Bar 27 | } 28 | 29 | // LoadFromPath loads the pkl module at the given path and evaluates it into a ExtendModule 30 | func LoadFromPath(ctx context.Context, path string) (ret ExtendModule, err error) { 31 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 32 | if err != nil { 33 | return ret, err 34 | } 35 | defer func() { 36 | cerr := evaluator.Close() 37 | if err == nil { 38 | err = cerr 39 | } 40 | }() 41 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 42 | return ret, err 43 | } 44 | 45 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a ExtendModule 46 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (ExtendModule, error) { 47 | var ret ExtendModuleImpl 48 | err := evaluator.EvaluateModule(ctx, source, &ret) 49 | return ret, err 50 | } 51 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/moduleusinglib/ModuleUsingLib.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `ModuleUsingLib`. DO NOT EDIT. 2 | package moduleusinglib 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/codegen/snippet-tests/output/support/lib" 8 | "github.com/apple/pkl-go/codegen/snippet-tests/output/support/lib/myenum" 9 | "github.com/apple/pkl-go/codegen/snippet-tests/output/support/lib2/cities" 10 | "github.com/apple/pkl-go/pkl" 11 | ) 12 | 13 | type ModuleUsingLib struct { 14 | Res []lib.MyClass `pkl:"res"` 15 | 16 | Res2 myenum.MyEnum `pkl:"res2"` 17 | 18 | Res3 string `pkl:"res3"` 19 | 20 | Res4 cities.Cities `pkl:"res4"` 21 | } 22 | 23 | // LoadFromPath loads the pkl module at the given path and evaluates it into a ModuleUsingLib 24 | func LoadFromPath(ctx context.Context, path string) (ret ModuleUsingLib, err error) { 25 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 26 | if err != nil { 27 | return ret, err 28 | } 29 | defer func() { 30 | cerr := evaluator.Close() 31 | if err == nil { 32 | err = cerr 33 | } 34 | }() 35 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 36 | return ret, err 37 | } 38 | 39 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a ModuleUsingLib 40 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (ModuleUsingLib, error) { 41 | var ret ModuleUsingLib 42 | err := evaluator.EvaluateModule(ctx, source, &ret) 43 | return ret, err 44 | } 45 | -------------------------------------------------------------------------------- /pkl/atomic.go: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | package pkl 18 | 19 | import ( 20 | "math/rand" 21 | "sync" 22 | "sync/atomic" 23 | "time" 24 | ) 25 | 26 | type atomicBool struct { 27 | atomic.Bool 28 | } 29 | 30 | func (a *atomicBool) get() bool { 31 | return a.Load() 32 | } 33 | 34 | func (a *atomicBool) set(value bool) { 35 | a.Store(value) 36 | } 37 | 38 | var randPool = &sync.Pool{ 39 | New: func() interface{} { 40 | return rand.New(rand.NewSource(time.Now().UnixNano())) 41 | }, 42 | } 43 | 44 | type atomicRandom struct{} 45 | 46 | func (a *atomicRandom) Int63() int64 { 47 | r := randPool.Get().(*rand.Rand) 48 | defer randPool.Put(r) 49 | return r.Int63() 50 | } 51 | 52 | var random = &atomicRandom{} 53 | -------------------------------------------------------------------------------- /pkl/evaluator_manager_exec_unix.go: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | //go:build unix 18 | 19 | package pkl 20 | 21 | import ( 22 | "os" 23 | "os/exec" 24 | "syscall" 25 | ) 26 | 27 | func (e *execEvaluator) getStartCommand() *exec.Cmd { 28 | exe, arg := e.getCommandAndArgStrings() 29 | cmd := exec.Command(exe, append(arg, "server")...) 30 | cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} 31 | return cmd 32 | } 33 | 34 | // killProcess kills the process's entire group 35 | func killProcess(proc *os.Process) error { 36 | pgid, err := syscall.Getpgid(proc.Pid) 37 | if err != nil { 38 | return err 39 | } 40 | // negative pid indicates to send the signal to the whole pg 41 | return syscall.Kill(-pgid, syscall.SIGKILL) 42 | } 43 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/Unions.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/union" } 17 | module union 18 | 19 | import ".../src/go.pkl" 20 | 21 | /// A city 22 | city: City 23 | 24 | /// County 25 | county: County 26 | 27 | /// Noodles 28 | noodle: Noodles 29 | 30 | /// Account disposition 31 | disposition: AccountDisposition 32 | 33 | /// City; e.g. where people live 34 | typealias City = "San Francisco" | "London" | "上海" 35 | 36 | /// Locale that contains cities and towns 37 | typealias County = "San Francisco" | "San Mateo" | "Yolo" 38 | 39 | /// Noodles 40 | typealias Noodles = "拉面" | "刀切面" | "面线" | "意大利面" 41 | 42 | typealias AccountDisposition = "" | "icloud3" | "prod" | "shared" 43 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/datasize/Datasize.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `datasize`. DO NOT EDIT. 2 | package datasize 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type Datasize struct { 11 | Res1 pkl.DataSize `pkl:"res1"` 12 | 13 | Res2 pkl.DataSize `pkl:"res2"` 14 | 15 | Res3 pkl.DataSize `pkl:"res3"` 16 | 17 | Res4 pkl.DataSize `pkl:"res4"` 18 | 19 | Res5 pkl.DataSize `pkl:"res5"` 20 | 21 | Res6 pkl.DataSize `pkl:"res6"` 22 | 23 | Res7 pkl.DataSize `pkl:"res7"` 24 | 25 | Res8 pkl.DataSize `pkl:"res8"` 26 | 27 | Res9 pkl.DataSize `pkl:"res9"` 28 | 29 | Res10 pkl.DataSize `pkl:"res10"` 30 | 31 | Res11 pkl.DataSize `pkl:"res11"` 32 | 33 | Res12 pkl.DataSizeUnit `pkl:"res12"` 34 | } 35 | 36 | // LoadFromPath loads the pkl module at the given path and evaluates it into a Datasize 37 | func LoadFromPath(ctx context.Context, path string) (ret Datasize, err error) { 38 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 39 | if err != nil { 40 | return ret, err 41 | } 42 | defer func() { 43 | cerr := evaluator.Close() 44 | if err == nil { 45 | err = cerr 46 | } 47 | }() 48 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 49 | return ret, err 50 | } 51 | 52 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a Datasize 53 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (Datasize, error) { 54 | var ret Datasize 55 | err := evaluator.EvaluateModule(ctx, source, &ret) 56 | return ret, err 57 | } 58 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/primitives/Primitives.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `primitives`. DO NOT EDIT. 2 | package primitives 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type Primitives struct { 11 | Res0 string `pkl:"res0"` 12 | 13 | Res1 int `pkl:"res1"` 14 | 15 | Res2 int8 `pkl:"res2"` 16 | 17 | Res3 int16 `pkl:"res3"` 18 | 19 | Res4 int32 `pkl:"res4"` 20 | 21 | Res5 uint `pkl:"res5"` 22 | 23 | Res6 uint8 `pkl:"res6"` 24 | 25 | Res7 uint16 `pkl:"res7"` 26 | 27 | Res8 uint32 `pkl:"res8"` 28 | 29 | Res9 float64 `pkl:"res9"` 30 | 31 | Res10 bool `pkl:"res10"` 32 | 33 | Res11 any `pkl:"res11"` 34 | 35 | Res12 float64 `pkl:"res12"` 36 | 37 | Res13 float64 `pkl:"res13"` 38 | } 39 | 40 | // LoadFromPath loads the pkl module at the given path and evaluates it into a Primitives 41 | func LoadFromPath(ctx context.Context, path string) (ret Primitives, err error) { 42 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 43 | if err != nil { 44 | return ret, err 45 | } 46 | defer func() { 47 | cerr := evaluator.Close() 48 | if err == nil { 49 | err = cerr 50 | } 51 | }() 52 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 53 | return ret, err 54 | } 55 | 56 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a Primitives 57 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (Primitives, error) { 58 | var ret Primitives 59 | err := evaluator.EvaluateModule(ctx, source, &ret) 60 | return ret, err 61 | } 62 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/union/Union.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `union`. DO NOT EDIT. 2 | package union 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/codegen/snippet-tests/output/union/accountdisposition" 8 | "github.com/apple/pkl-go/codegen/snippet-tests/output/union/city" 9 | "github.com/apple/pkl-go/codegen/snippet-tests/output/union/county" 10 | "github.com/apple/pkl-go/codegen/snippet-tests/output/union/noodles" 11 | "github.com/apple/pkl-go/pkl" 12 | ) 13 | 14 | type Union struct { 15 | // A city 16 | City city.City `pkl:"city"` 17 | 18 | // County 19 | County county.County `pkl:"county"` 20 | 21 | // Noodles 22 | Noodle noodles.Noodles `pkl:"noodle"` 23 | 24 | // Account disposition 25 | Disposition accountdisposition.AccountDisposition `pkl:"disposition"` 26 | } 27 | 28 | // LoadFromPath loads the pkl module at the given path and evaluates it into a Union 29 | func LoadFromPath(ctx context.Context, path string) (ret Union, err error) { 30 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 31 | if err != nil { 32 | return ret, err 33 | } 34 | defer func() { 35 | cerr := evaluator.Close() 36 | if err == nil { 37 | err = cerr 38 | } 39 | }() 40 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 41 | return ret, err 42 | } 43 | 44 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a Union 45 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (Union, error) { 46 | var ret Union 47 | err := evaluator.EvaluateModule(ctx, source, &ret) 48 | return ret, err 49 | } 50 | -------------------------------------------------------------------------------- /pkl/schema.go: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | package pkl 18 | 19 | import "reflect" 20 | 21 | var schemas = make(map[string]reflect.Type) 22 | 23 | // RegisterStrictMapping associates the type given the Pkl name to the corresponding Go type. 24 | // 25 | //goland:noinspection GoUnusedExportedFunction 26 | func RegisterStrictMapping(name string, value any) { 27 | schemas[name] = reflect.TypeOf(value) 28 | } 29 | 30 | // RegisterMapping is like RegisterStrictMapping, but casts it to a pointer. 31 | // 32 | // This method exists to preserve compatibility with legacy generated code, where object types were generated as 33 | // pointers. 34 | // 35 | //goland:noinspection GoUnusedExportedFunction 36 | func RegisterMapping(name string, value any) { 37 | schemas[name] = reflect.PointerTo(reflect.TypeOf(value)) 38 | } 39 | -------------------------------------------------------------------------------- /codegen/src/PklProject: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | amends "pkl:Project" 18 | 19 | local repo = "github.com/apple/pkl-go" 20 | 21 | package { 22 | name = "pkl.golang" 23 | baseUri = "package://pkg.pkl-lang.org/pkl-go/\(name)" 24 | packageZipUrl = "https://\(repo)/releases/download/\(name)@\(version)/\(name)@\(version).zip" 25 | version = read("../../VERSION.txt").text.trim() 26 | authors { 27 | "The Pkl Authors " 28 | } 29 | sourceCodeUrlScheme = "https://\(repo)/tree/v\(version)/codegen/src%{path}#L%{line}-L%{endLine}" 30 | sourceCode = "https://\(repo)" 31 | description = "Pkl bindings for the Go programming language" 32 | license = "Apache-2.0" 33 | exclude { 34 | "tests" 35 | "tests/**" 36 | } 37 | } 38 | 39 | tests { 40 | for (key, _ in import*("tests/*.pkl")) { 41 | key 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/structtags/StructTags.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `StructTags`. DO NOT EDIT. 2 | package structtags 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type StructTags struct { 11 | Res string `pkl:"res" json:"res,omitempty"` 12 | 13 | Res2 string `pkl:"res2" json:"res2"` 14 | 15 | Res3 string `pkl:"res3" json:"-"` 16 | 17 | Res5 string `pkl:"res5" json:"myFoo5,omitempty"` 18 | 19 | Res6 string `pkl:"res6" json:"myFoo6"` 20 | 21 | Res7 string `pkl:"res7" yaml:",omitempty" bson:",omitempty"` 22 | 23 | Res8 string `pkl:"res8" yaml:"res8,omitempty" bson:"res8,omitempty"` 24 | 25 | Res9 string `pkl:"res9"` 26 | 27 | Res10 string `pkl:"res10"` 28 | 29 | Res11 string `pkl:"res11" json:"-,omitempty"` 30 | 31 | Res12 string `pkl:"res12" toml:"res12,multiline"` 32 | } 33 | 34 | // LoadFromPath loads the pkl module at the given path and evaluates it into a StructTags 35 | func LoadFromPath(ctx context.Context, path string) (ret StructTags, err error) { 36 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 37 | if err != nil { 38 | return ret, err 39 | } 40 | defer func() { 41 | cerr := evaluator.Close() 42 | if err == nil { 43 | err = cerr 44 | } 45 | }() 46 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 47 | return ret, err 48 | } 49 | 50 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a StructTags 51 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (StructTags, error) { 52 | var ret StructTags 53 | err := evaluator.EvaluateModule(ctx, source, &ret) 54 | return ret, err 55 | } 56 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/collections/Collections.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `collections`. DO NOT EDIT. 2 | package collections 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type Collections struct { 11 | Res1 []int `pkl:"res1"` 12 | 13 | Res2 []int `pkl:"res2"` 14 | 15 | Res3 [][]int `pkl:"res3"` 16 | 17 | Res4 [][]int `pkl:"res4"` 18 | 19 | Res5 map[int]bool `pkl:"res5"` 20 | 21 | Res6 map[int]map[int]bool `pkl:"res6"` 22 | 23 | Res7 map[int]bool `pkl:"res7"` 24 | 25 | Res8 map[int]map[int]bool `pkl:"res8"` 26 | 27 | Res9 map[string]struct{} `pkl:"res9"` 28 | 29 | Res10 map[int8]struct{} `pkl:"res10"` 30 | 31 | Res11 pkl.Pair[int, float64] `pkl:"res11"` 32 | 33 | Res12 pkl.Pair[any, any] `pkl:"res12"` 34 | 35 | Res13 pkl.Pair[int, *int] `pkl:"res13"` 36 | 37 | Res14 []byte `pkl:"res14"` 38 | } 39 | 40 | // LoadFromPath loads the pkl module at the given path and evaluates it into a Collections 41 | func LoadFromPath(ctx context.Context, path string) (ret Collections, err error) { 42 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 43 | if err != nil { 44 | return ret, err 45 | } 46 | defer func() { 47 | cerr := evaluator.Close() 48 | if err == nil { 49 | err = cerr 50 | } 51 | }() 52 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 53 | return ret, err 54 | } 55 | 56 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a Collections 57 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (Collections, error) { 58 | var ret Collections 59 | err := evaluator.EvaluateModule(ctx, source, &ret) 60 | return ret, err 61 | } 62 | -------------------------------------------------------------------------------- /CONTRIBUTING.adoc: -------------------------------------------------------------------------------- 1 | :uri-github-issue-pkl: https://github.com/apple/pkl-go/issues/new 2 | :uri-seven-rules: https://cbea.ms/git-commit/#seven-rules 3 | 4 | = Pkl Go Contributors Guide 5 | 6 | Welcome to the Pkl community, and thank you for contributing! 7 | This guide explains how to get involved. 8 | 9 | * <> 10 | * <> 11 | * <> 12 | 13 | == Licensing 14 | 15 | Pkl Go is released under the Apache 2.0 license. 16 | This is why we require that, by submitting a pull request, you acknowledge that you have the right to license your contribution to Apple and the community, and agree that your contribution is licensed under the Apache 2.0 license. 17 | 18 | == Issue Tracking 19 | 20 | To file a bug or feature request, use {uri-github-issue-pkl}[GitHub]. 21 | Be sure to include the following information: 22 | 23 | * Context 24 | ** What are/were you trying to achieve? 25 | ** What's the impact of this bug/feature? 26 | 27 | == Pull Requests 28 | 29 | When preparing a pull request, follow this checklist: 30 | 31 | * Imitate the conventions of surrounding code. 32 | * Format `.pkl` files in your PR with the JetBrains IDE formatter. 33 | * Follow the {uri-seven-rules}[seven rules] of great Git commit messages: 34 | ** Separate subject from body with a blank line. 35 | ** Limit the subject line to 50 characters. 36 | ** Capitalize the subject line. 37 | ** Do not end the subject line with a period. 38 | ** Use the imperative mood in the subject line. 39 | ** Wrap the body at 72 characters. 40 | ** Use the body to explain what and why vs. how. 41 | 42 | == Maintainers 43 | 44 | The project’s maintainers (those with write access to the upstream repository) are listed in link:MAINTAINERS.adoc[]. 45 | -------------------------------------------------------------------------------- /pkl/unmarshal.go: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | package pkl 18 | 19 | import ( 20 | "errors" 21 | "fmt" 22 | "reflect" 23 | ) 24 | 25 | // Unmarshal parses Pkl-encoded data and stores the result into 26 | // the value pointed by v. 27 | // 28 | // This is a low-level API. Most users should be using Evaluator.Evaluate instead. 29 | // 30 | // The following struct tags are supported: 31 | // 32 | // pkl:"Field" Overrides the field's name to map to. 33 | // 34 | //goland:noinspection GoUnusedExportedFunction 35 | func Unmarshal(data []byte, v any) error { 36 | value := reflect.ValueOf(v) 37 | if value.Kind() != reflect.Ptr { 38 | return fmt.Errorf("cannot unmarshal non-pointer. Got kind: %v", value.Kind()) 39 | } 40 | if value.IsNil() { 41 | return errors.New("cannot unmarshal into nil") 42 | } 43 | res, err := newDecoder(data, schemas).Decode(value.Elem().Type()) 44 | if err != nil { 45 | return err 46 | } 47 | value.Elem().Set(*res) 48 | return nil 49 | } 50 | -------------------------------------------------------------------------------- /codegen/src/tests/fixtures/types.pkl: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | class Bike { 18 | isFixie: Boolean 19 | } 20 | 21 | abstract class Being { 22 | isAlive: Boolean 23 | } 24 | 25 | /// A Person! 26 | open class Person extends Being { 27 | bike: Bike 28 | 29 | /// The person's first name 30 | firstName: UInt16? 31 | 32 | /// The person's last name 33 | lastName: Mapping 34 | } 35 | 36 | typealias BugKind = "butterfly" | "beetle\"" | "beetle one" | "beetle_one" 37 | 38 | typealias SymbolKind = "*" | "beetle\"" | "!!!" | "__" 39 | 40 | class Bug { 41 | /// The owner of this bug. 42 | owner: Person? 43 | 44 | secondOwner: Person 45 | 46 | /// The age of this bug 47 | age: Int? 48 | 49 | /// How long the bug holds its breath for 50 | holdsBreathFor: Duration 51 | 52 | size: DataSize 53 | 54 | kind: BugKind 55 | 56 | symbol: SymbolKind 57 | } 58 | 59 | class Cyclic { 60 | a: String 61 | 62 | b: Int 63 | 64 | myself: Cyclic 65 | } 66 | -------------------------------------------------------------------------------- /codegen/src/tests/utils.pkl: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | amends "pkl:test" 18 | 19 | import "../internal/utils.pkl" 20 | 21 | facts { 22 | ["normalizeName"] { 23 | utils.normalizeName("foo") == "Foo" 24 | utils.normalizeName("foo foo") == "FooFoo" 25 | utils.normalizeName("1 foo") == "N1Foo" 26 | utils.normalizeName("bar ` $$ 你好 baz") == "Bar你好Baz" 27 | utils.normalizeName("Go111") == "Go111" 28 | utils.normalizeName("snake_case") == "SnakeCase" 29 | } 30 | ["toGoString"] { 31 | utils.toGoString("foo") == #""foo""# 32 | utils.toGoString("你好") == #""你好""# 33 | utils.toGoString(#"pkl:"name""#) == #"`pkl:"name"`"# 34 | utils.toGoString( 35 | """ 36 | my multiline 37 | 38 | string 39 | """ 40 | ) 41 | == """ 42 | `my multiline 43 | 44 | string` 45 | """ 46 | utils.toGoString( 47 | """ 48 | multiline string 49 | 50 | with `backticks` 51 | """ 52 | ) 53 | == #""multiline string\n\nwith `backticks`""# 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /docs/modules/ROOT/pages/external-readers.adoc: -------------------------------------------------------------------------------- 1 | = External Readers 2 | 3 | pkl-go provides APIs that aid in implementing xref:main:language-reference:index.adoc#external-readers[External Readers]. 4 | In this mode of execution, the program built with pkl-go runs as a child process of the Pkl evaluator, rather than a parent process. 5 | The https://pkg.go.dev/github.com/apple/pkl-go/pkl#ExternalReaderClient[`pkl.ExternalReaderClient`] type provides a set of tools for building external readers. 6 | 7 | Much like implementing xref:ROOT:evaluation.adoc#custom-readers[Custom Readers], external readers are implemented by providing one or more instances of the https://pkg.go.dev/github.com/apple/pkl-go/pkl#ResourceReader[`pkl.ResourceReader`] and https://pkg.go.dev/github.com/apple/pkl-go/pkl#ModuleReader[`pkl.ModuleReader`] interfaces. 8 | 9 | == Example 10 | 11 | This simple reader implementation reads the specified environment variable: 12 | 13 | .main.go 14 | [source,go] 15 | ---- 16 | package main 17 | 18 | import ( 19 | "log" 20 | "net/url" 21 | "os" 22 | 23 | "github.com/apple/pkl-go/pkl" 24 | ) 25 | 26 | func main() { 27 | client, err := pkl.NewExternalReaderClient(pkl.WithExternalClientResourceReader(myReader{})) 28 | if err != nil { 29 | log.Fatalln(err) 30 | } 31 | if err := client.Run(); err != nil { 32 | log.Fatalln(err) 33 | } 34 | } 35 | 36 | type myReader struct{} 37 | 38 | var _ pkl.ResourceReader = &myReader{} 39 | 40 | func (r myReader) Scheme() string { 41 | return "env2" 42 | } 43 | 44 | func (r myReader) HasHierarchicalUris() bool { 45 | return false 46 | } 47 | 48 | func (r myReader) IsGlobbable() bool { 49 | return false 50 | } 51 | 52 | func (r myReader) ListElements(baseURI url.URL) ([]pkl.PathElement, error) { 53 | return nil, nil 54 | } 55 | 56 | func (r myReader) Read(uri url.URL) ([]byte, error) { 57 | return []byte(os.Getenv(uri.Opaque)), nil 58 | } 59 | ---- 60 | -------------------------------------------------------------------------------- /codegen/src/tests/gatherer.pkl: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | amends "pkl:test" 18 | 19 | import "pkl:reflect" 20 | 21 | import "../internal/gatherer.pkl" 22 | import "fixtures/types.pkl" 23 | import "fixtures/types2.pkl" 24 | import "fixtures/types4.pkl" 25 | 26 | // it's important that these classes are defined in another module because they gather the type 27 | // declarations of their enclosing module. 28 | facts { 29 | ["gather type declarations"] { 30 | gatherer.gatherTypeDeclarations(reflect.Class(types.Bug), List()).map((c) -> c.name) 31 | == List("Bug", "Person", "Bike", "ModuleClass", "Being", "Cyclic", "BugKind", "SymbolKind") 32 | } 33 | ["gather type declarations - listing arguments"] { 34 | gatherer.gatherTypeDeclarations(reflect.Class(types2.Person), List()).map((c) -> c.name) 35 | == List("Person", "Bike", "ModuleClass", "ModuleClass") 36 | } 37 | ["gather type declarations - type params with unions"] { 38 | gatherer.gatherTypeDeclarations(reflect.Class(types4.Foo), List()).map((c) -> c.name) 39 | == List("Foo", "ModuleClass") 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /pkl/internal/msgapi/code.go: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | package msgapi 18 | 19 | const ( 20 | codeNewEvaluator int = 0x20 21 | codeNewEvaluatorResponse int = 0x21 22 | codeCloseEvaluator int = 0x22 23 | codeEvaluate int = 0x23 24 | codeEvaluateResponse int = 0x24 25 | codeEvaluateLog int = 0x25 26 | codeEvaluateRead int = 0x26 27 | codeEvaluateReadResponse int = 0x27 28 | codeEvaluateReadModule int = 0x28 29 | codeEvaluateReadModuleResponse int = 0x29 30 | codeListResourcesRequest int = 0x2a 31 | codeListResourcesResponse int = 0x2b 32 | codeListModulesRequest int = 0x2c 33 | codeListModulesResponse int = 0x2d 34 | codeInitializeModuleReaderRequest int = 0x2e 35 | codeInitializeModuleReaderResponse int = 0x2f 36 | codeInitializeResourceReaderRequest int = 0x30 37 | codeInitializeResourceReaderResponse int = 0x31 38 | codeCloseExternalProcess int = 0x32 39 | ) 40 | -------------------------------------------------------------------------------- /pkl/test_fixtures/classes.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | 17 | @go.Package { name = "github.com/apple/pkl-go/pkl/test_fixtures/gen/classes" } 18 | module classes 19 | 20 | import ".../codegen/src/go.pkl" 21 | 22 | animals: Listing = new { 23 | new Greyhound { name = "Uni"; barks = false; canRoach = true } 24 | new Cat { name = "Millie"; meows = true } 25 | } 26 | 27 | nullableAnimals: Listing = new { 28 | null 29 | new Greyhound { name = "Uni"; barks = false; canRoach = true } 30 | } 31 | 32 | myAnimal: Animal = new Greyhound { 33 | name = "Uni" 34 | barks = false 35 | canRoach = true 36 | } 37 | 38 | house: House = new { 39 | area = 2000 40 | bedrooms = 3 41 | bathrooms = 2 42 | } 43 | 44 | abstract class Animal { 45 | name: String 46 | } 47 | 48 | open class Dog extends Animal { 49 | barks: Boolean 50 | breed: String 51 | } 52 | 53 | class Greyhound extends Dog { 54 | breed = "Greyhound" 55 | canRoach: Boolean 56 | } 57 | 58 | class Cat extends Animal { 59 | meows: Boolean 60 | } 61 | 62 | class House { 63 | area: Int 64 | bedrooms: Int 65 | bathrooms: Int 66 | } 67 | -------------------------------------------------------------------------------- /codegen/snippet-tests/input/StructTags.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/structtags" } 17 | module StructTags 18 | 19 | import ".../src/go.pkl" 20 | 21 | @go.Field { json { omitempty = true } } 22 | res: String 23 | 24 | @go.Field { json = true } 25 | res2: String 26 | 27 | @go.Field { json { name = "-" } } 28 | res3: String 29 | 30 | @go.Field { json { name = "myFoo5"; omitempty = true } } 31 | res5: String 32 | 33 | @go.Field { json { name = "myFoo6" } } 34 | res6: String 35 | 36 | @go.Field { 37 | structTags { 38 | ["yaml"] = ",omitempty" 39 | ["bson"] = ",omitempty" 40 | } 41 | } 42 | res7: String 43 | 44 | @go.Field { 45 | structTags { 46 | ["yaml"] = "%{name},omitempty" 47 | ["bson"] = "%{name},omitempty" 48 | } 49 | } 50 | res8: String 51 | 52 | @go.Field 53 | res9: String 54 | 55 | @go.Field { json = false } 56 | res10: String 57 | 58 | @go.Field { json { value = "-,omitempty" } } 59 | res11: String 60 | 61 | class TomlField extends go.Field { 62 | structTags { 63 | ["toml"] = "%{name},multiline" 64 | } 65 | } 66 | 67 | @TomlField 68 | res12: String 69 | -------------------------------------------------------------------------------- /pkl/test_fixtures/collections.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | 17 | @go.Package { name = "github.com/apple/pkl-go/pkl/test_fixtures/gen/collections" } 18 | module collections 19 | 20 | import ".../codegen/src/go.pkl" 21 | 22 | res1: List = List(1, 2, 3) 23 | 24 | res2: Listing = new { 2; 3; 4 } 25 | 26 | res3: List> = List(List(1), List(2), List(3)) 27 | 28 | res4: Listing> = new { new { 1 }; new { 2 }; new { 3 } } 29 | 30 | res5: Mapping = new { [1] = true; [2] = false } 31 | 32 | res6: Mapping> = new { 33 | [1] { 34 | [1] = true 35 | } 36 | [2] { 37 | [2] = true 38 | } 39 | [3] { 40 | [3] = true 41 | } 42 | } 43 | 44 | res7: Map = Map(1, true, 2, false) 45 | 46 | res8: Map> = Map(1, Map(1, true), 2, Map(2, false)) 47 | 48 | res9: Set = Set("one", "two", "three") 49 | 50 | res10: Set = Set(1, 2, 3) 51 | 52 | res11: Pair = Pair(1, 5.0) 53 | 54 | res12: Pair = Pair("hello", "goodbye") 55 | 56 | res13: Pair = Pair(1, 2) 57 | 58 | // introduced in Pkl 0.29 59 | res14: Bytes = Bytes(1, 2, 3, 4, 255) 60 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/pairs/Pairs.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `Pairs`. DO NOT EDIT. 2 | package pairs 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type Pairs interface { 11 | GetUntyped() pkl.Pair[any, any] 12 | 13 | GetOptional() *pkl.Pair[any, any] 14 | 15 | GetTyped() pkl.Pair[string, int] 16 | 17 | GetAliased() pkl.Pair[string, any] 18 | 19 | GetTypeArgAliased() pkl.Pair[string, int] 20 | } 21 | 22 | var _ Pairs = PairsImpl{} 23 | 24 | type PairsImpl struct { 25 | Untyped pkl.Pair[any, any] `pkl:"untyped"` 26 | 27 | Optional *pkl.Pair[any, any] `pkl:"optional"` 28 | 29 | Typed pkl.Pair[string, int] `pkl:"typed"` 30 | 31 | Aliased pkl.Pair[string, any] `pkl:"aliased"` 32 | 33 | TypeArgAliased pkl.Pair[string, int] `pkl:"typeArgAliased"` 34 | } 35 | 36 | func (rcv PairsImpl) GetUntyped() pkl.Pair[any, any] { 37 | return rcv.Untyped 38 | } 39 | 40 | func (rcv PairsImpl) GetOptional() *pkl.Pair[any, any] { 41 | return rcv.Optional 42 | } 43 | 44 | func (rcv PairsImpl) GetTyped() pkl.Pair[string, int] { 45 | return rcv.Typed 46 | } 47 | 48 | func (rcv PairsImpl) GetAliased() pkl.Pair[string, any] { 49 | return rcv.Aliased 50 | } 51 | 52 | func (rcv PairsImpl) GetTypeArgAliased() pkl.Pair[string, int] { 53 | return rcv.TypeArgAliased 54 | } 55 | 56 | // LoadFromPath loads the pkl module at the given path and evaluates it into a Pairs 57 | func LoadFromPath(ctx context.Context, path string) (ret Pairs, err error) { 58 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 59 | if err != nil { 60 | return ret, err 61 | } 62 | defer func() { 63 | cerr := evaluator.Close() 64 | if err == nil { 65 | err = cerr 66 | } 67 | }() 68 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 69 | return ret, err 70 | } 71 | 72 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a Pairs 73 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (Pairs, error) { 74 | var ret PairsImpl 75 | err := evaluator.EvaluateModule(ctx, source, &ret) 76 | return ret, err 77 | } 78 | -------------------------------------------------------------------------------- /pkl/test_fixtures/nullables.pkl: -------------------------------------------------------------------------------- 1 | // ===----------------------------------------------------------------------===// 2 | // Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | // ===----------------------------------------------------------------------===// 16 | 17 | @go.Package { name = "github.com/apple/pkl-go/pkl/test_fixtures/gen/nullables" } 18 | module nullables 19 | 20 | import ".../codegen/src/go.pkl" 21 | 22 | res0: String? = "bar" 23 | res1: String? = null 24 | res2: Int? = 1 25 | res3: Int? = null 26 | res4: Int8? = 2 27 | res5: Int8? = null 28 | res6: Int16? = 3 29 | res7: Int16? = null 30 | res8: Int32? = 4 31 | res9: Int32? = null 32 | res10: UInt? = 5 33 | res11: UInt? = null 34 | res12: UInt8? = 6 35 | res13: UInt8? = null 36 | res14: UInt16? = 7 37 | res15: UInt16? = null 38 | res16: UInt32? = 8 39 | res17: UInt32? = null 40 | res18: Float? = 5.3 41 | res19: Float? = null 42 | res20: Boolean? = true 43 | res21: Boolean? = null 44 | res22: Mapping? = new { ["foo"] = "bar" } 45 | res23: Mapping? = null 46 | // can't test this due to https://github.com/stretchr/testify/issues/1143 47 | //res24: Mapping? = new { 48 | // ["foo"] = "bar" 49 | // [null] = null 50 | // ["foo2"] = null 51 | //} 52 | res25: Mapping? = null 53 | res26: Listing? = new { 1; 2; null; 4; 5 } 54 | res27: Listing? = null 55 | res28: MyClass? = new {} 56 | res29: MyClass? = new { prop = "foo" } 57 | res30: MyClass? = null 58 | 59 | class MyClass { 60 | prop: String? 61 | } 62 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/ConflictingNames.err: -------------------------------------------------------------------------------- 1 | –– Pkl Error –– 2 | Conflict: multiple Pkl declarations compute to Go name `ClassOne`. 3 | 4 | To resolve this conflict, add a `@go.Name` annotation to any of the following declarations: 5 | 6 | * class `ConflictingNames#Class One` (file:///snippet-tests/input/ConflictingNames.err.pkl) 7 | * class `ConflictingNames#ClassOne` (file:///snippet-tests/input/ConflictingNames.err.pkl) 8 | 9 | For example: 10 | 11 | ``` 12 | @go.Name { value = "CrabCakes" } 13 | class Crab_Cakes 14 | ``` 15 | 16 | xx | throw( 17 | ^^^^^^ 18 | at pkl.golang.internal.Package#hasUniqueNames. (file:///src/internal/Package.pkl) 19 | 20 | xx | let (locations = duplicateNames.map((it) -> describeLocation(it.source)).join("\n")) 21 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22 | at pkl.golang.internal.Package#hasUniqueNames. (file:///src/internal/Package.pkl) 23 | 24 | xx | let ( 25 | ^^^^^ 26 | at pkl.golang.internal.Package#hasUniqueNames. (file:///src/internal/Package.pkl) 27 | 28 | xx | let (names = moduleMappings.map((it) -> it.name)) 29 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 30 | at pkl.golang.internal.Package#hasUniqueNames (file:///src/internal/Package.pkl) 31 | 32 | xx | local generated: List(hasUniqueNames()) = 33 | ^^^^^^^^^^^^^^^^ 34 | at pkl.golang.internal.Package#generated (file:///src/internal/Package.pkl) 35 | 36 | xx | moduleMappings.map((it) -> 37 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 38 | at pkl.golang.internal.Package#generated (file:///src/internal/Package.pkl) 39 | 40 | xxx | for (gen in generated) { 41 | ^^^^^^^^^ 42 | at pkl.golang.internal.Package#output.files (file:///src/internal/Package.pkl) 43 | 44 | xxx | for (filename, fileOutput in package.output.files!!) { 45 | ^^^^^^^^^^^^^^^^^^^^ 46 | at pkl.golang.Generator#output.files (file:///src/Generator.pkl) 47 | 48 | x | output.files?.toMap()?.mapValues((_, it) -> it.text) ?? Map() 49 | ^^^^^^^^^^^^ 50 | at (repl:text) 51 | -------------------------------------------------------------------------------- /pkl/test_fixtures/gen/nullables/Nullables.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `nullables`. DO NOT EDIT. 2 | package nullables 3 | 4 | import ( 5 | "context" 6 | 7 | "github.com/apple/pkl-go/pkl" 8 | ) 9 | 10 | type Nullables struct { 11 | Res0 *string `pkl:"res0"` 12 | 13 | Res1 *string `pkl:"res1"` 14 | 15 | Res2 *int `pkl:"res2"` 16 | 17 | Res3 *int `pkl:"res3"` 18 | 19 | Res4 *int8 `pkl:"res4"` 20 | 21 | Res5 *int8 `pkl:"res5"` 22 | 23 | Res6 *int16 `pkl:"res6"` 24 | 25 | Res7 *int16 `pkl:"res7"` 26 | 27 | Res8 *int32 `pkl:"res8"` 28 | 29 | Res9 *int32 `pkl:"res9"` 30 | 31 | Res10 *uint `pkl:"res10"` 32 | 33 | Res11 *uint `pkl:"res11"` 34 | 35 | Res12 *uint8 `pkl:"res12"` 36 | 37 | Res13 *uint8 `pkl:"res13"` 38 | 39 | Res14 *uint16 `pkl:"res14"` 40 | 41 | Res15 *uint16 `pkl:"res15"` 42 | 43 | Res16 *uint32 `pkl:"res16"` 44 | 45 | Res17 *uint32 `pkl:"res17"` 46 | 47 | Res18 *float64 `pkl:"res18"` 48 | 49 | Res19 *float64 `pkl:"res19"` 50 | 51 | Res20 *bool `pkl:"res20"` 52 | 53 | Res21 *bool `pkl:"res21"` 54 | 55 | Res22 *map[string]string `pkl:"res22"` 56 | 57 | Res23 *map[string]string `pkl:"res23"` 58 | 59 | Res25 *map[*string]*string `pkl:"res25"` 60 | 61 | Res26 *[]*int `pkl:"res26"` 62 | 63 | Res27 *[]*int `pkl:"res27"` 64 | 65 | Res28 *MyClass `pkl:"res28"` 66 | 67 | Res29 *MyClass `pkl:"res29"` 68 | 69 | Res30 *MyClass `pkl:"res30"` 70 | } 71 | 72 | // LoadFromPath loads the pkl module at the given path and evaluates it into a Nullables 73 | func LoadFromPath(ctx context.Context, path string) (ret Nullables, err error) { 74 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 75 | if err != nil { 76 | return ret, err 77 | } 78 | defer func() { 79 | cerr := evaluator.Close() 80 | if err == nil { 81 | err = cerr 82 | } 83 | }() 84 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 85 | return ret, err 86 | } 87 | 88 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a Nullables 89 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (Nullables, error) { 90 | var ret Nullables 91 | err := evaluator.EvaluateModule(ctx, source, &ret) 92 | return ret, err 93 | } 94 | -------------------------------------------------------------------------------- /pkl/errors.go: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | package pkl 18 | 19 | import ( 20 | "errors" 21 | "fmt" 22 | ) 23 | 24 | // EvalError is an error that occurs during the normal evaluation of Pkl code. 25 | // 26 | // This means that Pkl evaluation occurred, and the Pkl runtime produced an error. 27 | type EvalError struct { 28 | ErrorOutput string 29 | } 30 | 31 | var _ error = (*EvalError)(nil) 32 | 33 | func (r *EvalError) Error() string { 34 | return r.ErrorOutput 35 | } 36 | 37 | // Is implements the interface expected by errors.Is. 38 | func (r *EvalError) Is(err error) bool { 39 | if err == nil { 40 | return false 41 | } 42 | var evalError *EvalError 43 | ok := errors.As(err, &evalError) 44 | return ok 45 | } 46 | 47 | // InternalError indicates that an unexpected error occurred. 48 | type InternalError struct { 49 | err error 50 | } 51 | 52 | var _ error = (*InternalError)(nil) 53 | 54 | func (r *InternalError) Error() string { 55 | return fmt.Sprintf("an internal error occurred: %v", r.err) 56 | } 57 | 58 | // Is implements the interface expected by errors.Is. 59 | func (r *InternalError) Is(err error) bool { 60 | if err == nil { 61 | return false 62 | } 63 | var internalError *InternalError 64 | ok := errors.As(err, &internalError) 65 | return ok 66 | } 67 | 68 | // Unwrap implements the interface expected by errors.Unwrap. 69 | func (r *InternalError) Unwrap() error { 70 | return r.err 71 | } 72 | -------------------------------------------------------------------------------- /pkl/decode_slice.go: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | package pkl 18 | 19 | import ( 20 | "fmt" 21 | "reflect" 22 | ) 23 | 24 | func (d *decoder) decodeSlice(inType reflect.Type) (*reflect.Value, error) { 25 | length, code, err := d.decodeObjectPreamble() 26 | if err != nil { 27 | return nil, err 28 | } 29 | if length != 2 { 30 | return nil, fmt.Errorf("expected array length 2 but got %d", length) 31 | } 32 | if code == codeBytes { 33 | return d.decodeBytesImpl() 34 | } 35 | if code != codeList && code != codeListing { 36 | return nil, fmt.Errorf("invalid code for slices: %d. Expected %d or %d", code, codeList, codeListing) 37 | } 38 | return d.decodeSliceImpl(inType) 39 | } 40 | 41 | func (d *decoder) decodeBytesImpl() (*reflect.Value, error) { 42 | bytes, err := d.dec.DecodeBytes() 43 | if err != nil { 44 | return nil, err 45 | } 46 | ret := reflect.ValueOf(bytes) 47 | return &ret, nil 48 | } 49 | 50 | func (d *decoder) decodeSliceImpl(inType reflect.Type) (*reflect.Value, error) { 51 | sliceLen, err := d.dec.DecodeArrayLen() 52 | if err != nil { 53 | return nil, err 54 | } 55 | elemType := inType.Elem() 56 | ret := reflect.MakeSlice(reflect.SliceOf(elemType), sliceLen, sliceLen) 57 | for i := 0; i < sliceLen; i++ { 58 | v := ret.Index(i) 59 | decoded, err := d.Decode(elemType) 60 | if err != nil { 61 | return nil, err 62 | } 63 | v.Set(*decoded) 64 | } 65 | return &ret, nil 66 | } 67 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/ConflictingNames2.err: -------------------------------------------------------------------------------- 1 | –– Pkl Error –– 2 | Conflict: multiple Pkl declarations compute to Go name `ConflictingNames2`. 3 | 4 | To resolve this conflict, add a `@go.Name` annotation to any of the following declarations: 5 | 6 | * module `ConflictingNames2` (file:///snippet-tests/input/ConflictingNames2.err.pkl) 7 | * class `ConflictingNames2#ConflictingNames2` (file:///snippet-tests/input/ConflictingNames2.err.pkl) 8 | 9 | For example: 10 | 11 | ``` 12 | @go.Name { value = "CrabCakes" } 13 | class Crab_Cakes 14 | ``` 15 | 16 | xx | throw( 17 | ^^^^^^ 18 | at pkl.golang.internal.Package#hasUniqueNames. (file:///src/internal/Package.pkl) 19 | 20 | xx | let (locations = duplicateNames.map((it) -> describeLocation(it.source)).join("\n")) 21 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22 | at pkl.golang.internal.Package#hasUniqueNames. (file:///src/internal/Package.pkl) 23 | 24 | xx | let ( 25 | ^^^^^ 26 | at pkl.golang.internal.Package#hasUniqueNames. (file:///src/internal/Package.pkl) 27 | 28 | xx | let (names = moduleMappings.map((it) -> it.name)) 29 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 30 | at pkl.golang.internal.Package#hasUniqueNames (file:///src/internal/Package.pkl) 31 | 32 | xx | local generated: List(hasUniqueNames()) = 33 | ^^^^^^^^^^^^^^^^ 34 | at pkl.golang.internal.Package#generated (file:///src/internal/Package.pkl) 35 | 36 | xx | moduleMappings.map((it) -> 37 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 38 | at pkl.golang.internal.Package#generated (file:///src/internal/Package.pkl) 39 | 40 | xxx | for (gen in generated) { 41 | ^^^^^^^^^ 42 | at pkl.golang.internal.Package#output.files (file:///src/internal/Package.pkl) 43 | 44 | xxx | for (filename, fileOutput in package.output.files!!) { 45 | ^^^^^^^^^^^^^^^^^^^^ 46 | at pkl.golang.Generator#output.files (file:///src/Generator.pkl) 47 | 48 | x | output.files?.toMap()?.mapValues((_, it) -> it.text) ?? Map() 49 | ^^^^^^^^^^^^ 50 | at (repl:text) 51 | -------------------------------------------------------------------------------- /cmd/internal/test-external-reader/test-external-reader.go: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | package main 18 | 19 | import ( 20 | "errors" 21 | "fmt" 22 | "log" 23 | "net/url" 24 | "strconv" 25 | 26 | "github.com/apple/pkl-go/pkl" 27 | ) 28 | 29 | func main() { 30 | client, err := pkl.NewExternalReaderClient(func(opts *pkl.ExternalReaderClientOptions) { 31 | opts.ResourceReaders = append(opts.ResourceReaders, fibReader{}) 32 | }) 33 | if err != nil { 34 | log.Fatalln(err) 35 | } 36 | 37 | if err := client.Run(); err != nil { 38 | log.Fatalln(err) 39 | } 40 | } 41 | 42 | type fibReader struct{} 43 | 44 | var _ pkl.ResourceReader = &fibReader{} 45 | 46 | func (r fibReader) Scheme() string { 47 | return "fib" 48 | } 49 | 50 | func (r fibReader) HasHierarchicalUris() bool { 51 | return false 52 | } 53 | 54 | func (r fibReader) IsGlobbable() bool { 55 | return false 56 | } 57 | 58 | func (r fibReader) ListElements(baseURI url.URL) ([]pkl.PathElement, error) { 59 | return nil, nil 60 | } 61 | 62 | func (r fibReader) Read(uri url.URL) ([]byte, error) { 63 | n, err := strconv.Atoi(uri.Opaque) 64 | if n <= 0 { 65 | err = errors.New("non-positive value") 66 | } 67 | if err != nil { 68 | return nil, fmt.Errorf("input uri must be in format fib:: %w", err) 69 | } 70 | 71 | return []byte(strconv.Itoa(fibonacci(n))), nil 72 | } 73 | 74 | func fibonacci(n int) int { 75 | f0, f1 := 0, 1 76 | for range n { 77 | f0, f1 = f1, f0+f1 78 | } 79 | return f0 80 | } 81 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= 2 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 3 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 4 | github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= 5 | github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 6 | github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= 7 | github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= 8 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 9 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 10 | github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 11 | github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= 12 | github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= 13 | github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= 14 | github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 15 | github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= 16 | github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= 17 | github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8= 18 | github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok= 19 | github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= 20 | github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds= 21 | golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU= 22 | golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww= 23 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 24 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 25 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 26 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 27 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/InvalidPackageName.err: -------------------------------------------------------------------------------- 1 | –– Pkl Error –– 2 | Package name `github.com/apple/pkl-go/codegen/snippet-tests/output/import` is not valid because it clashes with keyword `import`. 3 | 4 | xx | throw( 5 | ^^^^^^ 6 | at pkl.golang.go#isValidPackageName. (file:///src/go.pkl) 7 | 8 | xx | let (packageNameShort = it.substring(it.lastIndexOf("/") + 1, it.length)) 9 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 10 | at pkl.golang.go#isValidPackageName. (file:///src/go.pkl) 11 | 12 | xx | @go.Package { name = "github.com/apple/pkl-go/codegen/snippet-tests/output/import" } 13 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 14 | at InvalidPackageName.name (file:///snippet-tests/input/InvalidPackageName.err.pkl) 15 | 16 | xx | if (seen.contains(decl)) 17 | ^^^^^^^^^^^^^^^^^^^ 18 | at pkl.golang.internal.gatherer#gatherTypeDeclarations (file:///src/internal/gatherer.pkl) 19 | 20 | xx | gatherTypeDeclarations(superclass, seen) 21 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 22 | at pkl.golang.internal.gatherer#gatherSuperDeclarations. (file:///src/internal/gatherer.pkl) 23 | 24 | xx | let (superclass = clazz.superclass) 25 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 26 | at pkl.golang.internal.gatherer#gatherSuperDeclarations. (file:///src/internal/gatherer.pkl) 27 | 28 | xx | let (declarations = gatherer.gatherTypeDeclarations(clazz, List())) 29 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 30 | at pkl.golang.Generator#allMappings. (file:///src/Generator.pkl) 31 | 32 | xx | let (clazz = reflect.Module(moduleToGenerate).moduleClass) 33 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 34 | at pkl.golang.Generator#allMappings (file:///src/Generator.pkl) 35 | 36 | xx | allMappings 37 | ^^^^^^^^^^^ 38 | at pkl.golang.Generator#packages (file:///src/Generator.pkl) 39 | 40 | xxx | for (_, package in packages) { 41 | ^^^^^^^^ 42 | at pkl.golang.Generator#output.files (file:///src/Generator.pkl) 43 | 44 | x | output.files?.toMap()?.mapValues((_, it) -> it.text) ?? Map() 45 | ^^^^^^^^^^^^ 46 | at (repl:text) 47 | -------------------------------------------------------------------------------- /pkl/logger.go: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | package pkl 18 | 19 | import ( 20 | "fmt" 21 | "io" 22 | "os" 23 | ) 24 | 25 | // Logger is the interface for logging messages emitted by the Pkl evaluator. 26 | // 27 | // To set a logger, register it on EvaluatorOptions.Logger when building an Evaluator. 28 | type Logger interface { 29 | // Trace logs the given message on level TRACE. 30 | Trace(message string, frameUri string) 31 | 32 | // Warn logs the given message on level WARN. 33 | Warn(message string, frameUri string) 34 | } 35 | 36 | // NewLogger builds a logger that writes to the provided output stream, 37 | // using the default formatting. 38 | func NewLogger(out io.Writer) Logger { 39 | return &logger{out} 40 | } 41 | 42 | // FormatLogMessage returns the default formatter for log messages. 43 | func FormatLogMessage(level, message, frameUri string) string { 44 | return fmt.Sprintf("pkl: %s: %s (%s)\n", level, message, frameUri) 45 | } 46 | 47 | type logger struct { 48 | out io.Writer 49 | } 50 | 51 | func (s logger) Trace(message string, frameUri string) { 52 | _, _ = io.WriteString(s.out, FormatLogMessage("TRACE", message, frameUri)) 53 | } 54 | 55 | func (s logger) Warn(message string, frameUri string) { 56 | _, _ = io.WriteString(s.out, FormatLogMessage("WARN", message, frameUri)) 57 | } 58 | 59 | var _ Logger = (*logger)(nil) 60 | 61 | // StderrLogger is a logger that writes to standard error. 62 | // 63 | //goland:noinspection GoUnusedGlobalVariable 64 | var StderrLogger = NewLogger(os.Stdout) 65 | 66 | // NoopLogger is a logger that discards all messages. 67 | var NoopLogger = NewLogger(io.Discard) 68 | -------------------------------------------------------------------------------- /pkl/internal/version_test.go: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | package internal 18 | 19 | import ( 20 | "testing" 21 | 22 | "github.com/stretchr/testify/assert" 23 | ) 24 | 25 | func compareVersions(v1 string, v2 string) int { 26 | semverV1 := MustParseSemver(v1) 27 | semverV2 := MustParseSemver(v2) 28 | return semverV1.CompareTo(semverV2) 29 | } 30 | 31 | func TestCompareSemverVersions(t *testing.T) { 32 | assert.Equal(t, -1, compareVersions("1.0.0", "2.0.0")) 33 | assert.Equal(t, -1, compareVersions("1.0.0", "1.0.1")) 34 | assert.Equal(t, -1, compareVersions("1.0.0", "1.1.0")) 35 | assert.Equal(t, -1, compareVersions("1.0.5", "1.5.0")) 36 | assert.Equal(t, 0, compareVersions("1.0.0", "1.0.0")) 37 | assert.Equal(t, 0, compareVersions("1.1.0", "1.1.0")) 38 | assert.Equal(t, 0, compareVersions("5.1.0", "5.1.0")) 39 | assert.Equal(t, 1, compareVersions("2.0.0", "1.0.0")) 40 | assert.Equal(t, 1, compareVersions("2.0.0", "0.2.0")) 41 | assert.Equal(t, 1, compareVersions("2.0.0", "0.0.2")) 42 | assert.Equal(t, 1, compareVersions("2.0.0", "0.0.15")) 43 | assert.Equal(t, 1, compareVersions("2.0.0", "2.0.0-alpha")) 44 | assert.Equal(t, -1, compareVersions("2.0.0-alpha", "2.0.0-beta")) 45 | assert.Equal(t, 1, compareVersions("2.0.0-alpha", "2.0.0-aaa")) 46 | assert.Equal(t, 0, compareVersions("2.0.0-alpha", "2.0.0-alpha")) 47 | assert.Equal(t, 0, compareVersions("2.0.0-1.2.3", "2.0.0-1.2.3")) 48 | assert.Equal(t, 1, compareVersions("2.0.0-1.2.3", "2.0.0-1.2.2")) 49 | assert.Equal(t, 0, compareVersions("2.0.0-a.b.3", "2.0.0-a.b.3")) 50 | assert.Equal(t, 1, compareVersions("2.0.0-1.2.3.4", "2.0.0-1.2.3")) 51 | assert.Equal(t, 0, compareVersions("2.0.0+foo", "2.0.0+bar")) 52 | } 53 | -------------------------------------------------------------------------------- /pkl/fs_reader.go: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | package pkl 18 | 19 | import ( 20 | "io/fs" 21 | "net/url" 22 | "strings" 23 | ) 24 | 25 | type fsReader struct { 26 | fs fs.FS 27 | scheme string 28 | } 29 | 30 | func (f *fsReader) Scheme() string { 31 | return f.scheme 32 | } 33 | 34 | func (f *fsReader) IsGlobbable() bool { 35 | return true 36 | } 37 | 38 | func (f *fsReader) HasHierarchicalUris() bool { 39 | return true 40 | } 41 | 42 | func (f *fsReader) ListElements(url url.URL) ([]PathElement, error) { 43 | path := strings.Trim(url.Path, "/") 44 | if path == "" { 45 | path = "." 46 | } 47 | entries, err := fs.ReadDir(f.fs, path) 48 | if err != nil { 49 | return nil, err 50 | } 51 | ret := make([]PathElement, 0, len(entries)) 52 | for _, entry := range entries { 53 | // copy Pkl's built-in `file` ModuleKey and don't follow symlinks. 54 | if entry.Type()&fs.ModeSymlink != 0 { 55 | continue 56 | } 57 | ret = append(ret, NewPathElement(entry.Name(), entry.IsDir())) 58 | } 59 | return ret, nil 60 | } 61 | 62 | var _ Reader = (*fsReader)(nil) 63 | 64 | type fsModuleReader struct { 65 | *fsReader 66 | } 67 | 68 | func (f fsModuleReader) IsLocal() bool { 69 | return true 70 | } 71 | 72 | func (f fsModuleReader) Read(url url.URL) (string, error) { 73 | contents, err := fs.ReadFile(f.fs, strings.TrimPrefix(url.Path, "/")) 74 | return string(contents), err 75 | } 76 | 77 | var _ ModuleReader = (*fsModuleReader)(nil) 78 | 79 | type fsResourceReader struct { 80 | *fsReader 81 | } 82 | 83 | func (f fsResourceReader) Read(url url.URL) ([]byte, error) { 84 | return fs.ReadFile(f.fs, strings.TrimPrefix(url.Path, "/")) 85 | } 86 | 87 | var _ ResourceReader = (*fsResourceReader)(nil) 88 | -------------------------------------------------------------------------------- /pkl/values_test.go: -------------------------------------------------------------------------------- 1 | //===----------------------------------------------------------------------===// 2 | // Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // https://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | //===----------------------------------------------------------------------===// 16 | 17 | package pkl 18 | 19 | import ( 20 | "testing" 21 | 22 | "github.com/stretchr/testify/assert" 23 | ) 24 | 25 | func TestDataSize_String(t *testing.T) { 26 | tests := []struct { 27 | name string 28 | input DataSize 29 | expected string 30 | }{ 31 | { 32 | name: "bytes", 33 | input: DataSize{ 34 | Value: 1.0, 35 | Unit: Bytes, 36 | }, 37 | expected: "1.b", 38 | }, 39 | { 40 | name: "kebibytes", 41 | input: DataSize{ 42 | Value: 5.3, 43 | Unit: Kibibytes, 44 | }, 45 | expected: "5.3.kib", 46 | }, 47 | { 48 | name: "invalid", 49 | input: DataSize{ 50 | Value: 5.0, 51 | }, 52 | expected: "5.", 53 | }, 54 | } 55 | for _, test := range tests { 56 | t.Run(test.name, func(t *testing.T) { 57 | assert.Equal(t, test.expected, test.input.String()) 58 | }) 59 | } 60 | } 61 | 62 | func TestDataSize_ConvertToUnit(t *testing.T) { 63 | tests := []struct { 64 | name string 65 | input DataSize 66 | expected DataSize 67 | }{ 68 | { 69 | name: "bytes_to_gigabytes", 70 | input: DataSize{ 71 | Value: 1.0, 72 | Unit: Bytes, 73 | }, 74 | expected: DataSize{ 75 | Value: 0.000_000_001, 76 | Unit: Gigabytes, 77 | }, 78 | }, 79 | { 80 | name: "megabytes_to_bytes", 81 | input: DataSize{ 82 | Value: 1.0, 83 | Unit: Megabytes, 84 | }, 85 | expected: DataSize{ 86 | Value: 1_000_000, 87 | Unit: Bytes, 88 | }, 89 | }, 90 | } 91 | for _, test := range tests { 92 | t.Run(test.name, func(t *testing.T) { 93 | got := test.input.ToUnit(test.expected.Unit) 94 | assert.Equal(t, test.expected, got) 95 | }) 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /DEVELOPMENT.adoc: -------------------------------------------------------------------------------- 1 | :uri-pkl-repo: https://github.com/apple/pkl 2 | 3 | = Pkl Go Development Guide 4 | 5 | == Debugging the Pkl Server 6 | 7 | The pkl-go evaluator API runs `pkl server` as a subprocess, which presents obstacles for directly debugging the server process. 8 | It is possible to 9 | 10 | *Debug Stub Setup* 11 | 12 | . Create a file named `debugpkl` 13 | . Mark the file executable with `chmod +x debugpkl` 14 | . Populate the file with this content (note: the value for `JPKL_EXEC` will need to be updated depending on where the Pkl repo is cloned): 15 | 16 | [,shell] 17 | ---- 18 | #!/bin/sh 19 | 20 | JPKL_EXEC=/path/to/pkl/pkl-cli/build/executable/jpkl 21 | 22 | if [ "$1" = "--version" ]; then 23 | # if this is the version discovery command, don't connect to the debugger 24 | exec "$JPKL_EXEC" "$@" 25 | fi 26 | 27 | exec java -agentlib:jdwp=transport=dt_socket,server=n,address=127.0.0.1:5005,suspend=y -jar "$JPKL_EXEC" "$@" 28 | ---- 29 | 30 | 31 | *IntelliJ IDEA Setup:* 32 | 33 | . Open the {uri-pkl-repo}[pkl] project 34 | . Build `jpkl` by running `./gradlew javaExecutable` so it is available to the script defined above 35 | . Run > Edit Configurations... 36 | . Add a new "Remote JVM Debug" configuration 37 | . Provide a name, eg. `debugpkl` 38 | . Under "Configuration", select the "Listen to remote JVM" debugger mode 39 | . Enable "Auto restart" 40 | . Ensure Host is "localhost" and Port is "5005" 41 | 42 | *Usage* 43 | 44 | . Configure pkl-go to use `debugpkl` as the server executable: `export PKL_EXEC=./debugpkl` 45 | . Optionally, turn on extra debug output: `export PKL_DEBUG=1` 46 | . Define breakpoints as desired in the Pkl codebase using IntelliJ 47 | . In IntelliJ, start debugging the "Remote JVM Debug" configuration defined above 48 | . Execute the process using pkl-go 49 | 50 | When the Pkl server execution reaches a defined breakpoint, it will pause and activate the debugger in IntelliJ. 51 | 52 | == Running hawkeye formatting 53 | 54 | This project uses https://github.com/korandoru/hawkeye[hawkeye] to format license headers. 55 | 56 | To run the formatter: 57 | 58 | [source,shell] 59 | ---- 60 | hawkeye format 61 | ---- 62 | 63 | == Running gofumpt formatting 64 | 65 | This project uses https://github.com/mvdan/gofumpt[gofumpt] (v0.9.2) to format Go code. 66 | 67 | To run the formatter: 68 | 69 | [source,shell] 70 | ---- 71 | gofumpt -l -w . 72 | ---- 73 | 74 | == Running Pkl formatting 75 | 76 | This project uses Pkl's formatter to format Pkl code. 77 | 78 | To run the formatter: 79 | 80 | [source,shell] 81 | ---- 82 | pkl format --grammar-version 1 --write . 83 | ---- 84 | --------------------------------------------------------------------------------