├── .circleci ├── config.pkl └── config.yml ├── .gitattributes ├── .gitignore ├── .mailmap ├── CODE_OF_CONDUCT.adoc ├── CONTRIBUTING.adoc ├── DEVELOPMENT.adoc ├── LICENSE.txt ├── MAINTAINERS.adoc ├── NOTICE.txt ├── README.adoc ├── SECURITY.md ├── VERSION.txt ├── cmd ├── internal │ ├── gen-fixtures │ │ ├── README.adoc │ │ └── gen-fixtures.go │ ├── gen-snippets │ │ └── gen-snippets.go │ └── test-external-reader │ │ └── test-external-reader.go └── pkl-gen-go │ ├── generatorsettings │ ├── GeneratorSettings.pkl.go │ └── init.pkl.go │ ├── pkg │ ├── generate.go │ └── template.gopkl │ └── pkl-gen-go.go ├── codegen ├── snippet-tests │ ├── generator-settings.pkl │ ├── input │ │ ├── Classes.pkl │ │ ├── ConflictingNames.err.pkl │ │ ├── ConflictingNames2.err.pkl │ │ ├── CyclicModule.pkl │ │ ├── EmptyOpenModule.pkl │ │ ├── ExplicitName.pkl │ │ ├── ExtendAbstractClass.pkl │ │ ├── ExtendModule.pkl │ │ ├── ExtendOpenClass.pkl │ │ ├── HiddenProperties.pkl │ │ ├── IllegalOverride.err.pkl │ │ ├── InvalidPackageName.err.pkl │ │ ├── ModuleType.pkl │ │ ├── ModuleUsingLib.pkl │ │ ├── Override.pkl │ │ ├── Override2.pkl │ │ ├── StructTags.pkl │ │ ├── UnionNameKeyword.pkl │ │ ├── Unions.pkl │ │ └── support │ │ │ ├── OpenModule.pkl │ │ │ ├── lib.pkl │ │ │ ├── lib2.pkl │ │ │ ├── lib3.pkl │ │ │ └── lib4.pkl │ └── output │ │ ├── ConflictingNames.err │ │ ├── ConflictingNames2.err │ │ ├── IllegalOverride.err │ │ ├── InvalidPackageName.err │ │ ├── bugholder │ │ ├── A.pkl.go │ │ ├── B.pkl.go │ │ ├── Being.pkl.go │ │ ├── Bike.pkl.go │ │ ├── Bug.pkl.go │ │ ├── BugHolder.pkl.go │ │ ├── C.pkl.go │ │ ├── D.pkl.go │ │ ├── Person.pkl.go │ │ ├── ThisPerson.pkl.go │ │ ├── Wheel.pkl.go │ │ ├── bugkind │ │ │ └── BugKind.pkl.go │ │ ├── bugkindtwo │ │ │ └── BugKindTwo.pkl.go │ │ └── init.pkl.go │ │ ├── cyclicmodule │ │ ├── Cyclic.pkl.go │ │ ├── CyclicModule.pkl.go │ │ └── init.pkl.go │ │ ├── emptyopenmodule │ │ ├── EmptyOpenModule.pkl.go │ │ └── init.pkl.go │ │ ├── explicitname │ │ ├── ExplicitlyCoolName.pkl.go │ │ ├── SomethingVeryFunny.pkl.go │ │ ├── configtype │ │ │ └── ConfigType.pkl.go │ │ └── init.pkl.go │ │ ├── extendabstractclass │ │ ├── A.pkl.go │ │ ├── B.pkl.go │ │ ├── ExtendsAbstractClass.pkl.go │ │ └── init.pkl.go │ │ ├── extendmodule │ │ ├── ExtendModule.pkl.go │ │ └── init.pkl.go │ │ ├── extendopenclass │ │ ├── ExtendingOpenClass.pkl.go │ │ ├── MyClass.pkl.go │ │ ├── MyClass2.pkl.go │ │ ├── MyOpenClass.pkl.go │ │ └── init.pkl.go │ │ ├── hiddenproperties │ │ ├── HiddenProperties.pkl.go │ │ └── init.pkl.go │ │ ├── moduletype │ │ ├── ModuleType.pkl.go │ │ └── init.pkl.go │ │ ├── moduleusinglib │ │ ├── ModuleUsingLib.pkl.go │ │ └── init.pkl.go │ │ ├── override │ │ ├── Bar.pkl.go │ │ ├── Foo.pkl.go │ │ ├── Override.pkl.go │ │ └── init.pkl.go │ │ ├── override2 │ │ ├── MySubclass.pkl.go │ │ ├── Override2.pkl.go │ │ └── init.pkl.go │ │ ├── structtags │ │ ├── StructTags.pkl.go │ │ └── init.pkl.go │ │ ├── support │ │ ├── lib │ │ │ ├── Lib.pkl.go │ │ │ ├── MyClass.pkl.go │ │ │ ├── init.pkl.go │ │ │ └── myenum │ │ │ │ └── MyEnum.pkl.go │ │ ├── lib2 │ │ │ └── cities │ │ │ │ └── Cities.pkl.go │ │ ├── lib3 │ │ │ ├── GoGoGo.pkl.go │ │ │ ├── Lib3.pkl.go │ │ │ └── init.pkl.go │ │ ├── lib4 │ │ │ ├── Lib4.pkl.go │ │ │ ├── MyLib4.pkl.go │ │ │ └── init.pkl.go │ │ └── openmodule │ │ │ ├── MyModule.pkl.go │ │ │ └── init.pkl.go │ │ ├── union │ │ ├── Union.pkl.go │ │ ├── accountdisposition │ │ │ └── AccountDisposition.pkl.go │ │ ├── city │ │ │ └── City.pkl.go │ │ ├── county │ │ │ └── County.pkl.go │ │ ├── init.pkl.go │ │ └── noodles │ │ │ └── Noodles.pkl.go │ │ └── unionnamekeyword │ │ ├── UnionNameKeyword.pkl.go │ │ ├── _type │ │ └── Type.pkl.go │ │ └── init.pkl.go └── src │ ├── Generator.pkl │ ├── GeneratorSettings.pkl │ ├── PklProject │ ├── PklProject.deps.json │ ├── go.pkl │ ├── internal │ ├── ClassGen.pkl │ ├── EnumGen.pkl │ ├── Gen.pkl │ ├── GoMapping.pkl │ ├── Package.pkl │ ├── Type.pkl │ ├── gatherer.pkl │ ├── typegen.pkl │ └── utils.pkl │ ├── resources │ └── VERSION.txt │ └── tests │ ├── fixtures │ ├── ClassGen.pkl │ ├── types.pkl │ ├── types2.pkl │ ├── types3.pkl │ └── types4.pkl │ ├── gatherer.pkl │ ├── typegen.pkl │ └── utils.pkl ├── docs ├── antora.yml ├── modules │ └── ROOT │ │ └── pages │ │ ├── CHANGELOG.adoc │ │ ├── codegen.adoc │ │ ├── evaluation.adoc │ │ ├── external-readers.adoc │ │ ├── index.adoc │ │ └── quickstart.adoc └── nav.adoc ├── generator-settings.pkl ├── go.mod ├── go.sum ├── licenserc.toml ├── pkl ├── atomic.go ├── decode_map.go ├── decode_primitives.go ├── decode_slice.go ├── decode_struct.go ├── decoder.go ├── errors.go ├── evaluator.go ├── evaluator_exec.go ├── evaluator_manager.go ├── evaluator_manager_exec.go ├── evaluator_manager_exec_unix.go ├── evaluator_manager_exec_windows.go ├── evaluator_manager_test.go ├── evaluator_options.go ├── evaluator_test.go ├── external_reader.go ├── external_reader_test.go ├── fs_reader.go ├── internal │ ├── debug.go │ └── msgapi │ │ ├── code.go │ │ ├── incoming.go │ │ └── outgoing.go ├── logger.go ├── module_source.go ├── module_source_test.go ├── project.go ├── project_test.go ├── reader.go ├── reader_test.go ├── schema.go ├── test_fixtures │ ├── any.pkl │ ├── classes.pkl │ ├── collections.pkl │ ├── datasize.pkl │ ├── duration.pkl │ ├── dynamic.pkl │ ├── gen │ │ ├── any │ │ │ ├── Any.pkl.go │ │ │ ├── Person.pkl.go │ │ │ └── init.pkl.go │ │ ├── classes │ │ │ ├── Animal.pkl.go │ │ │ ├── Cat.pkl.go │ │ │ ├── Classes.pkl.go │ │ │ ├── Dog.pkl.go │ │ │ ├── Greyhound.pkl.go │ │ │ ├── House.pkl.go │ │ │ └── init.pkl.go │ │ ├── collections │ │ │ ├── Collections.pkl.go │ │ │ └── init.pkl.go │ │ ├── datasize │ │ │ ├── Datasize.pkl.go │ │ │ └── init.pkl.go │ │ ├── duration │ │ │ ├── Duration.pkl.go │ │ │ └── init.pkl.go │ │ ├── dynamic │ │ │ ├── Dynamic.pkl.go │ │ │ ├── MyClass.pkl.go │ │ │ └── init.pkl.go │ │ ├── nullables │ │ │ ├── MyClass.pkl.go │ │ │ ├── Nullables.pkl.go │ │ │ └── init.pkl.go │ │ ├── primitives │ │ │ ├── Primitives.pkl.go │ │ │ └── init.pkl.go │ │ ├── unions │ │ │ ├── Unions.pkl.go │ │ │ ├── init.pkl.go │ │ │ ├── number │ │ │ │ └── Number.pkl.go │ │ │ └── othernumbers │ │ │ │ └── OtherNumbers.pkl.go │ │ └── unknown_type │ │ │ ├── UnknownType.pkl.go │ │ │ └── init.pkl.go │ ├── msgpack │ │ ├── any.pkl.msgpack │ │ ├── classes.pkl.msgpack │ │ ├── collections.pkl.msgpack │ │ ├── collections.res1.msgpack │ │ ├── collections.res2.msgpack │ │ ├── collections.res9.msgpack │ │ ├── datasize.pkl.msgpack │ │ ├── duration.pkl.msgpack │ │ ├── dynamic.pkl.msgpack │ │ ├── nullables.pkl.msgpack │ │ ├── primitives.pkl.msgpack │ │ ├── unions.pkl.msgpack │ │ └── unknown_type.pkl.msgpack │ ├── nullables.pkl │ ├── primitives.pkl │ ├── testfs │ │ ├── person.pkl │ │ └── subdir │ │ │ └── person.pkl │ ├── unions.pkl │ └── unknown_type.pkl ├── unmarshal.go ├── unmarshal_test.go ├── values.go ├── values_test.go ├── version.go └── version_test.go └── scripts ├── create_notice.sh ├── license-header.txt ├── notice.tpl └── test_snippets.sh /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pkl linguist-language=Groovy 2 | *.msgpack binary 3 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.mailmap: -------------------------------------------------------------------------------- 1 | Jen Basch <421772+HT154@users.noreply.github.com> 2 | Jen Basch 3 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | ---- -------------------------------------------------------------------------------- /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/holzensp[Philip Hölzenspies] 12 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /VERSION.txt: -------------------------------------------------------------------------------- 1 | 0.11.0 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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.RegisterMapping("pkl.golang.GeneratorSettings", GeneratorSettings{}) 8 | } 9 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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/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/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 | 29 | @go.Name { value = "ConfigType" } 30 | typealias Type = "one"|"two" 31 | -------------------------------------------------------------------------------- /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 | 21 | abstract class A { 22 | b: String 23 | } 24 | 25 | class B extends A { 26 | b = "hi" 27 | c: String 28 | } 29 | 30 | a: A 31 | -------------------------------------------------------------------------------- /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/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 | 21 | import "support/lib3.pkl" 22 | 23 | res1: MyClass 24 | 25 | res2: MyClass2 26 | 27 | open class MyOpenClass { 28 | myStr: String 29 | } 30 | 31 | class MyClass extends MyOpenClass { 32 | myStr = "mystr" 33 | myBoolean: Boolean 34 | } 35 | 36 | class MyClass2 extends lib3.GoGoGo { 37 | myBoolean: Boolean 38 | } 39 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/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 "support/lib4.pkl" 20 | import ".../src/go.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/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/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/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 "Override2.pkl" 20 | import ".../src/go.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/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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/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/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/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 | -------------------------------------------------------------------------------- /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/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 (duplicateNames = moduleMappings.filter((it) -> moduleMappings.count((m) -> m.name == it.name) > 1)) 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()) = moduleMappings.map((it) -> 33 | ^^^^^^^^^^^^^^^^ 34 | at pkl.golang.internal.Package#generated (file:///src/internal/Package.pkl) 35 | 36 | xx | local generated: List(hasUniqueNames()) = 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 | xx | 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) 49 | ^^^^^^^^^^^^ 50 | at (repl:text) 51 | -------------------------------------------------------------------------------- /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 (duplicateNames = moduleMappings.filter((it) -> moduleMappings.count((m) -> m.name == it.name) > 1)) 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()) = moduleMappings.map((it) -> 33 | ^^^^^^^^^^^^^^^^ 34 | at pkl.golang.internal.Package#generated (file:///src/internal/Package.pkl) 35 | 36 | xx | local generated: List(hasUniqueNames()) = 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 | xx | 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) 49 | ^^^^^^^^^^^^ 50 | at (repl:text) 51 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/IllegalOverride.err: -------------------------------------------------------------------------------- 1 | –– Pkl Error –– 2 | Illegal: Class `overrideerr#Child` overrides property `prop`. This is not supported when generating Go. 3 | 4 | file:///snippet-tests/input/IllegalOverride.err.pkl 5 | 6 | xxx | else throw(""" 7 | ^^^^^^^^^ 8 | at pkl.golang.internal.ClassGen#getFields. (file:///src/internal/ClassGen.pkl) 9 | 10 | xxx | let (superProp = superProperties.findOrNull((it) -> it.name == prop.name)) 11 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 12 | at pkl.golang.internal.ClassGen#getFields. (file:///src/internal/ClassGen.pkl) 13 | 14 | xxx | clazz.properties 15 | ^^^^^^^^^^^^^^^^ 16 | at pkl.golang.internal.ClassGen#getFields. (file:///src/internal/ClassGen.pkl) 17 | 18 | xxx | let (superProperties = getAllProperties(clazz.superclass)) 19 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20 | at pkl.golang.internal.ClassGen#getFields. (file:///src/internal/ClassGen.pkl) 21 | 22 | xxx | let (superFields: Map = 23 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 24 | at pkl.golang.internal.ClassGen#getFields. (file:///src/internal/ClassGen.pkl) 25 | 26 | xxx | let (isSuperOpen: Boolean = clazz.superclass.modifiers.contains("open")) 27 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 28 | at pkl.golang.internal.ClassGen#getFields (file:///src/internal/ClassGen.pkl) 29 | 30 | xx | local fields: Map = getFields(clazz, mappings) 31 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ 32 | at pkl.golang.internal.ClassGen#fields (file:///src/internal/ClassGen.pkl) 33 | 34 | xx | fields.values 35 | ^^^^^^ 36 | at pkl.golang.internal.ClassGen#imports (file:///src/internal/ClassGen.pkl) 37 | 38 | xx | when (!imports.isEmpty) { 39 | ^^^^^^^ 40 | at pkl.golang.internal.ClassGen#contents (file:///src/internal/ClassGen.pkl) 41 | 42 | xxx | text = gen.contents 43 | ^^^^^^^^^^^^ 44 | at pkl.golang.internal.Package#output.files[#1].text (file:///src/internal/Package.pkl) 45 | 46 | x | output.files.toMap().mapValues((_, it) -> it.text) 47 | ^^^^^^^ 48 | at repl:text. (repl:text) 49 | 50 | x | output.files.toMap().mapValues((_, it) -> it.text) 51 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 52 | at (repl:text) 53 | -------------------------------------------------------------------------------- /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)) seen 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 | local packages = allMappings 37 | ^^^^^^^^^^^ 38 | at pkl.golang.Generator#packages (file:///src/Generator.pkl) 39 | 40 | xx | 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) 45 | ^^^^^^^^^^^^ 46 | at (repl:text) 47 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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)(nil) 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/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/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/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 | -------------------------------------------------------------------------------- /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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 40 | return nil, err 41 | } 42 | return &ret, nil 43 | } 44 | -------------------------------------------------------------------------------- /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)(nil) 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)(nil) 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/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)(nil) 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/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)(nil) 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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.RegisterMapping("org.foo.BugHolder", BugHolder{}) 8 | pkl.RegisterMapping("org.foo.BugHolder#Bug", Bug{}) 9 | pkl.RegisterMapping("org.foo.BugHolder#Person", PersonImpl{}) 10 | pkl.RegisterMapping("org.foo.BugHolder#Bike", Bike{}) 11 | pkl.RegisterMapping("org.foo.BugHolder#Wheel", Wheel{}) 12 | pkl.RegisterMapping("org.foo.BugHolder#ThisPerson", ThisPersonImpl{}) 13 | pkl.RegisterMapping("org.foo.BugHolder#D", DImpl{}) 14 | pkl.RegisterMapping("org.foo.BugHolder#C", CImpl{}) 15 | pkl.RegisterMapping("org.foo.BugHolder#B", BImpl{}) 16 | } 17 | -------------------------------------------------------------------------------- /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/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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 34 | return nil, err 35 | } 36 | return &ret, nil 37 | } 38 | -------------------------------------------------------------------------------- /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.RegisterMapping("CyclicModule", CyclicModule{}) 8 | pkl.RegisterMapping("CyclicModule#Cyclic", Cyclic{}) 9 | } 10 | -------------------------------------------------------------------------------- /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)(nil) 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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 38 | return nil, err 39 | } 40 | return &ret, nil 41 | } 42 | -------------------------------------------------------------------------------- /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.RegisterMapping("EmptyOpenModule", EmptyOpenModuleImpl{}) 8 | } 9 | -------------------------------------------------------------------------------- /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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 34 | return nil, err 35 | } 36 | return &ret, nil 37 | } 38 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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.RegisterMapping("ExplicitName", ExplicitlyCoolName{}) 8 | pkl.RegisterMapping("ExplicitName#SomethingFunny", SomethingVeryFunny{}) 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 | type A interface { 5 | GetB() string 6 | } 7 | -------------------------------------------------------------------------------- /codegen/snippet-tests/output/extendabstractclass/B.pkl.go: -------------------------------------------------------------------------------- 1 | // Code generated from Pkl module `ExtendsAbstractClass`. DO NOT EDIT. 2 | package extendabstractclass 3 | 4 | type B interface { 5 | A 6 | 7 | GetC() string 8 | } 9 | 10 | var _ B = (*BImpl)(nil) 11 | 12 | type BImpl struct { 13 | B string `pkl:"b"` 14 | 15 | C string `pkl:"c"` 16 | } 17 | 18 | func (rcv *BImpl) GetB() string { 19 | return rcv.B 20 | } 21 | 22 | func (rcv *BImpl) GetC() string { 23 | return rcv.C 24 | } 25 | -------------------------------------------------------------------------------- /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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 34 | return nil, err 35 | } 36 | return &ret, nil 37 | } 38 | -------------------------------------------------------------------------------- /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.RegisterMapping("ExtendsAbstractClass", ExtendsAbstractClass{}) 8 | pkl.RegisterMapping("ExtendsAbstractClass#B", BImpl{}) 9 | } 10 | -------------------------------------------------------------------------------- /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)(nil) 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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 49 | return nil, err 50 | } 51 | return &ret, nil 52 | } 53 | -------------------------------------------------------------------------------- /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.RegisterMapping("ExtendModule", ExtendModuleImpl{}) 8 | } 9 | -------------------------------------------------------------------------------- /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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 36 | return nil, err 37 | } 38 | return &ret, nil 39 | } 40 | -------------------------------------------------------------------------------- /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)(nil) 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 | -------------------------------------------------------------------------------- /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)(nil) 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 | -------------------------------------------------------------------------------- /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)(nil) 9 | 10 | type MyOpenClassImpl struct { 11 | MyStr string `pkl:"myStr"` 12 | } 13 | 14 | func (rcv *MyOpenClassImpl) GetMyStr() string { 15 | return rcv.MyStr 16 | } 17 | -------------------------------------------------------------------------------- /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.RegisterMapping("ExtendingOpenClass", ExtendingOpenClass{}) 8 | pkl.RegisterMapping("ExtendingOpenClass#MyClass", MyClassImpl{}) 9 | pkl.RegisterMapping("ExtendingOpenClass#MyOpenClass", MyOpenClassImpl{}) 10 | pkl.RegisterMapping("ExtendingOpenClass#MyClass2", MyClass2Impl{}) 11 | } 12 | -------------------------------------------------------------------------------- /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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 34 | return nil, err 35 | } 36 | return &ret, nil 37 | } 38 | -------------------------------------------------------------------------------- /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.RegisterMapping("HiddenProperties", HiddenProperties{}) 8 | } 9 | -------------------------------------------------------------------------------- /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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 41 | return nil, err 42 | } 43 | return &ret, nil 44 | } 45 | -------------------------------------------------------------------------------- /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.RegisterMapping("ModuleType", ModuleType{}) 8 | } 9 | -------------------------------------------------------------------------------- /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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 43 | return nil, err 44 | } 45 | return &ret, nil 46 | } 47 | -------------------------------------------------------------------------------- /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.RegisterMapping("ModuleUsingLib", ModuleUsingLib{}) 8 | } 9 | -------------------------------------------------------------------------------- /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)(nil) 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/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/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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 34 | return nil, err 35 | } 36 | return &ret, nil 37 | } 38 | -------------------------------------------------------------------------------- /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.RegisterMapping("override", Override{}) 8 | pkl.RegisterMapping("override#Bar", BarImpl{}) 9 | } 10 | -------------------------------------------------------------------------------- /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)(nil) 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/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)(nil) 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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 46 | return nil, err 47 | } 48 | return &ret, nil 49 | } 50 | -------------------------------------------------------------------------------- /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.RegisterMapping("Override2", Override2Impl{}) 8 | pkl.RegisterMapping("Override2#MySubclass", MySubclassImpl{}) 9 | } 10 | -------------------------------------------------------------------------------- /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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 54 | return nil, err 55 | } 56 | return &ret, nil 57 | } 58 | -------------------------------------------------------------------------------- /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.RegisterMapping("StructTags", StructTags{}) 8 | } 9 | -------------------------------------------------------------------------------- /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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 33 | return nil, err 34 | } 35 | return &ret, nil 36 | } 37 | -------------------------------------------------------------------------------- /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)(nil) 9 | 10 | type MyClassImpl struct { 11 | Thing string `pkl:"thing"` 12 | } 13 | 14 | func (rcv *MyClassImpl) GetThing() string { 15 | return rcv.Thing 16 | } 17 | -------------------------------------------------------------------------------- /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.RegisterMapping("lib#MyClass", MyClassImpl{}) 8 | pkl.RegisterMapping("lib", Lib{}) 9 | } 10 | -------------------------------------------------------------------------------- /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/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/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)(nil) 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/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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 33 | return nil, err 34 | } 35 | return &ret, nil 36 | } 37 | -------------------------------------------------------------------------------- /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.RegisterMapping("lib3#GoGoGo", GoGoGoImpl{}) 8 | pkl.RegisterMapping("lib3", Lib3{}) 9 | } 10 | -------------------------------------------------------------------------------- /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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 34 | return nil, err 35 | } 36 | return &ret, nil 37 | } 38 | -------------------------------------------------------------------------------- /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/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.RegisterMapping("lib4#MyLib4", MyLib4{}) 8 | pkl.RegisterMapping("lib4", Lib4{}) 9 | } 10 | -------------------------------------------------------------------------------- /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)(nil) 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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 44 | return nil, err 45 | } 46 | return &ret, nil 47 | } 48 | -------------------------------------------------------------------------------- /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.RegisterMapping("MyModule", MyModuleImpl{}) 8 | } 9 | -------------------------------------------------------------------------------- /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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 48 | return nil, err 49 | } 50 | return &ret, nil 51 | } 52 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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.RegisterMapping("union", Union{}) 8 | } 9 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 35 | return nil, err 36 | } 37 | return &ret, nil 38 | } 39 | -------------------------------------------------------------------------------- /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/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.RegisterMapping("UnionNameKeyword", UnionNameKeyword{}) 8 | } 9 | -------------------------------------------------------------------------------- /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/src/PklProject.deps.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": 1, 3 | "resolvedDependencies": {} 4 | } -------------------------------------------------------------------------------- /codegen/src/internal/EnumGen.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 | module pkl.golang.internal.EnumGen 19 | 20 | extends "Gen.pkl" 21 | 22 | import "pkl:reflect" 23 | import "GoMapping.pkl" 24 | import "utils.pkl" 25 | 26 | alias: reflect.TypeAlias = mapping.source as reflect.TypeAlias 27 | 28 | enumMapping: GoMapping.Enum = mapping as GoMapping.Enum 29 | 30 | contents = new Listing { 31 | utils.renderHeaderComment(alias.enclosingDeclaration) 32 | "package \(enumMapping.goPackageShort)" 33 | "" 34 | utils.renderImports(List("encoding", "fmt")) 35 | "" 36 | when (alias.docComment != null) { 37 | utils.renderDocComment(alias.docComment!!, "") 38 | } 39 | "type \(enumMapping.name) string" 40 | "" 41 | "const (" 42 | for (member in enumMapping.members) { 43 | renderEnumMember(member) 44 | } 45 | ")" 46 | "" 47 | "// String returns the string representation of \(enumMapping.name)" 48 | "func (rcv \(enumMapping.name)) String() string {" 49 | "\treturn string(rcv)" 50 | "}" 51 | "" 52 | "var _ encoding.BinaryUnmarshaler = new(\(enumMapping.name))" 53 | "" 54 | "// UnmarshalBinary implements encoding.BinaryUnmarshaler for \(enumMapping.name)." 55 | "func (rcv *\(enumMapping.name)) UnmarshalBinary(data []byte) error {" 56 | "\tswitch str := string(data); str {" 57 | for (member in enumMapping.members) { 58 | "\tcase \(utils.toGoString(member.pklName)):" 59 | "\t\t*rcv = \(member.goName)" 60 | } 61 | "\tdefault:" 62 | "\t\treturn fmt.Errorf(`illegal: \"%s\" is not a valid \(enumMapping.name)`, str)" 63 | "\t}" 64 | "\treturn nil" 65 | "}" 66 | "" 67 | }.join("\n") 68 | 69 | local function renderEnumMember(member: GoMapping.EnumMember) = 70 | let (maxMemberNameLen = enumMapping.members.map((m) -> m.goName.length).max) 71 | let (spaces = " ".repeat(maxMemberNameLen - member.goName.length)) 72 | "\t\(member.goName) \(spaces)\(enumMapping.name) = \(utils.toGoString(member.pklName))" 73 | -------------------------------------------------------------------------------- /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/src/internal/Type.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 | /// Representation of a type in Go. 18 | @Unlisted 19 | abstract module pkl.golang.internal.Type 20 | 21 | import "Type.pkl" 22 | 23 | /// The imports required by this type. 24 | imports: List 25 | 26 | /// The go representation of this type. 27 | /// 28 | /// [goPackage] is the full path of the package that this type appears in. 29 | abstract function render(goPackage: String): String 30 | 31 | class Pointer extends Type { 32 | elem: Type 33 | 34 | imports = elem.imports 35 | 36 | function render(goPackage: String) = 37 | "*\(elem.render(goPackage))" 38 | } 39 | 40 | class Map extends Type { 41 | key: Type 42 | 43 | elem: Type 44 | 45 | imports = key.imports + elem.imports 46 | 47 | function render(goPackage: String) = 48 | "map[\(key.render(goPackage))]\(elem.render(goPackage))" 49 | } 50 | 51 | class Slice extends Type { 52 | elem: Type 53 | 54 | imports = elem.imports 55 | 56 | function render(goPackage: String) = "[]\(elem.render(goPackage))" 57 | } 58 | 59 | class Declared extends Type { 60 | /// The full import path for this type. 61 | importPath: String? 62 | 63 | imports = (if (importPath != null) List(importPath) else List()) 64 | + if (typeArguments != null) typeArguments.flatMap((t) -> t.imports) else List() 65 | 66 | /// The package the type is found in 67 | package: String? 68 | 69 | /// The name of the type 70 | typeName: String 71 | 72 | /// The type arguments, if any. 73 | typeArguments: List? 74 | 75 | function renderBase(goPackage: String) = 76 | if (package != null && goPackage != importPath) "\(package).\(typeName)" 77 | else typeName 78 | 79 | function renderTypeArguments(goPackage: String) = 80 | if (typeArguments == null) "" 81 | else "[" + typeArguments.map((t) -> t.render(goPackage)).join(", ") + "]" 82 | 83 | function render(goPackage: String) = 84 | renderBase(goPackage) + renderTypeArguments(goPackage) 85 | } 86 | -------------------------------------------------------------------------------- /codegen/src/resources/VERSION.txt: -------------------------------------------------------------------------------- 1 | ../../../VERSION.txt -------------------------------------------------------------------------------- /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 ".../internal/ClassGen.pkl" 20 | import "pkl:reflect" 21 | 22 | local class Person { 23 | name: String 24 | hobbies: List 25 | hidden talent: String 26 | } 27 | 28 | facts { 29 | ["getFields ignores hidden members"] { 30 | local fields = ClassGen.getFields(reflect.Class(Person), List()) 31 | fields.keys == Set("name", "hobbies") 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /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 | 67 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | import "fixtures/types.pkl" 21 | import "fixtures/types2.pkl" 22 | import "fixtures/types4.pkl" 23 | import "../internal/gatherer.pkl" 24 | 25 | // it's important that these classes are defined in another module because they gather the type 26 | // declarations of their enclosing module. 27 | facts { 28 | ["gather type declarations"] { 29 | gatherer.gatherTypeDeclarations(reflect.Class(types.Bug), List()).map((c) -> c.name) 30 | == List("Bug", "Person", "Bike", "ModuleClass", "Being", "Cyclic", "BugKind", "SymbolKind") 31 | } 32 | ["gather type declarations - listing arguments"] { 33 | gatherer.gatherTypeDeclarations(reflect.Class(types2.Person), List()).map((c) -> c.name) 34 | == List("Person", "Bike", "ModuleClass", "ModuleClass") 35 | } 36 | ["gather type declarations - type params with unions"] { 37 | gatherer.gatherTypeDeclarations(reflect.Class(types4.Foo), List()).map((c) -> c.name) 38 | == List("Foo", "ModuleClass") 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /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 | my multiline 36 | 37 | string 38 | """) == """ 39 | `my multiline 40 | 41 | string` 42 | """ 43 | utils.toGoString(""" 44 | multiline string 45 | 46 | with `backticks` 47 | """) 48 | == #""multiline string\n\nwith `backticks`""# 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /docs/antora.yml: -------------------------------------------------------------------------------- 1 | name: go 2 | title: Pkl Go Bindings 3 | version: &version 0.11.0 4 | nav: 5 | - nav.adoc 6 | asciidoc: 7 | attributes: 8 | version: *version 9 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/decode_map.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) decodeMap(inType reflect.Type) (*reflect.Value, error) { 25 | _, code, err := d.decodeObjectPreamble() 26 | if err != nil { 27 | return nil, err 28 | } 29 | if code == codeSet { 30 | return d.decodeSet(inType) 31 | } 32 | if code != codeMap && code != codeMapping { 33 | return nil, fmt.Errorf("invalid code for maps: %d", code) 34 | } 35 | return d.decodeMapImpl(inType) 36 | } 37 | 38 | func (d *decoder) decodeMapImpl(inType reflect.Type) (*reflect.Value, error) { 39 | mapLen, err := d.dec.DecodeMapLen() 40 | if err != nil { 41 | return nil, err 42 | } 43 | ret := reflect.MakeMapWithSize(inType, mapLen) 44 | keyType := inType.Key() 45 | valueType := inType.Elem() 46 | for i := 0; i < mapLen; i++ { 47 | key, err := d.Decode(keyType) 48 | if err != nil { 49 | return nil, err 50 | } 51 | value, err := d.Decode(valueType) 52 | if err != nil { 53 | return nil, err 54 | } 55 | ret.SetMapIndex(*key, *value) 56 | } 57 | return &ret, nil 58 | } 59 | 60 | var emptyMirror = reflect.ValueOf(empty) 61 | 62 | // decodeSet decodes into `map[T]struct{}` 63 | func (d *decoder) decodeSet(inType reflect.Type) (*reflect.Value, error) { 64 | length, err := d.dec.DecodeArrayLen() 65 | if err != nil { 66 | return nil, err 67 | } 68 | ret := reflect.MakeMapWithSize(inType, length) 69 | keyType := inType.Key() 70 | for i := 0; i < length; i++ { 71 | elem, err := d.Decode(keyType) 72 | if err != nil { 73 | return nil, err 74 | } 75 | ret.SetMapIndex(*elem, emptyMirror) 76 | } 77 | return &ret, nil 78 | } 79 | -------------------------------------------------------------------------------- /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 != codeList && code != codeListing { 33 | return nil, fmt.Errorf("invalid code for slices: %d. Expected %d or %d", code, codeList, codeListing) 34 | } 35 | return d.decodeSliceImpl(inType) 36 | } 37 | 38 | func (d *decoder) decodeSliceImpl(inType reflect.Type) (*reflect.Value, error) { 39 | sliceLen, err := d.dec.DecodeArrayLen() 40 | if err != nil { 41 | return nil, err 42 | } 43 | elemType := inType.Elem() 44 | ret := reflect.MakeSlice(reflect.SliceOf(elemType), sliceLen, sliceLen) 45 | for i := 0; i < sliceLen; i++ { 46 | v := ret.Index(i) 47 | decoded, err := d.Decode(elemType) 48 | if err != nil { 49 | return nil, err 50 | } 51 | v.Set(*decoded) 52 | } 53 | return &ret, nil 54 | } 55 | -------------------------------------------------------------------------------- /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/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 | // +build unix 19 | 20 | package pkl 21 | 22 | import ( 23 | "os" 24 | "os/exec" 25 | "syscall" 26 | ) 27 | 28 | func (e *execEvaluator) getStartCommand() *exec.Cmd { 29 | exe, arg := e.getCommandAndArgStrings() 30 | cmd := exec.Command(exe, append(arg, "server")...) 31 | cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} 32 | return cmd 33 | } 34 | 35 | // killProcess kills the process's entire group 36 | func killProcess(proc *os.Process) error { 37 | pgid, err := syscall.Getpgid(proc.Pid) 38 | if err != nil { 39 | return err 40 | } 41 | // negative pid indicates to send the signal to the whole pg 42 | return syscall.Kill(-pgid, syscall.SIGKILL) 43 | } 44 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /pkl/external_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 | "context" 21 | "path/filepath" 22 | "runtime" 23 | "testing" 24 | 25 | "github.com/stretchr/testify/assert" 26 | ) 27 | 28 | const externalReaderTest1 = ` 29 | import "pkl:test" 30 | 31 | fib5 = read("fib:5").text.toInt() 32 | fib10 = read("fib:10").text.toInt() 33 | fib100 = read("fib:20").text.toInt() 34 | 35 | fibErrA = test.catch(() -> read("fib:%20")) 36 | fibErrB = test.catch(() -> read("fib:abc")) 37 | fibErrC = test.catch(() -> read("fib:-10")) 38 | ` 39 | 40 | func TestExternalReaderE2E(t *testing.T) { 41 | manager := NewEvaluatorManager() 42 | defer manager.Close() 43 | version, err := manager.(*evaluatorManager).getVersion() 44 | if err != nil { 45 | t.Fatal(err) 46 | } 47 | if pklVersion0_27.isGreaterThan(version) { 48 | t.SkipNow() 49 | } 50 | 51 | tempDir := t.TempDir() 52 | writeFile(t, tempDir+"/test.pkl", externalReaderTest1) 53 | 54 | _, filename, _, ok := runtime.Caller(0) 55 | if !ok { 56 | panic("can't find caller") 57 | } 58 | projectRoot := filepath.Join(filepath.Dir(filename), "../cmd/internal/test-external-reader/test-external-reader.go") 59 | 60 | evaluator, err := manager.NewEvaluator( 61 | context.Background(), 62 | PreconfiguredOptions, 63 | WithExternalResourceReader("fib", ExternalReader{ 64 | Executable: "go", 65 | Arguments: []string{"run", projectRoot}, 66 | }), 67 | ) 68 | if !assert.NoError(t, err) { 69 | return 70 | } 71 | 72 | output, err := evaluator.EvaluateOutputText(context.Background(), FileSource(tempDir+"/test.pkl")) 73 | assert.NoError(t, err) 74 | assert.Equal(t, output, `fib5 = 5 75 | fib10 = 55 76 | fib100 = 6765 77 | fibErrA = "I/O error reading resource `+"`fib:%20`"+`. IOException: input uri must be in format fib:: non-positive value" 78 | fibErrB = "I/O error reading resource `+"`fib:abc`"+`. IOException: input uri must be in format fib:: non-positive value" 79 | fibErrC = "I/O error reading resource `+"`fib:-10`"+`. IOException: input uri must be in format fib:: non-positive value" 80 | `) 81 | } 82 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/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/module_source.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 | "net/url" 21 | "os" 22 | "path" 23 | ) 24 | 25 | // ModuleSource represents a source for Pkl evaluation. 26 | type ModuleSource struct { 27 | // Uri is the URL of the resource. 28 | Uri *url.URL 29 | 30 | // Contents is the text contents of the resource, if any. 31 | // 32 | // If Contents is empty, it gets resolved by Pkl during evaluation time. 33 | // If the scheme of the Uri matches a ModuleReader, it will be used to resolve the module. 34 | Contents string 35 | } 36 | 37 | // FileSource builds a ModuleSource, treating its arguments as paths on the file system. 38 | // 39 | // If the provided path is not an absolute path, it will be resolved against the current working 40 | // directory. 41 | // 42 | // If multiple path arguments are provided, they are joined as multiple elements of the path. 43 | // 44 | // It panics if the current working directory cannot be resolved. 45 | func FileSource(pathElems ...string) *ModuleSource { 46 | src := path.Join(pathElems...) 47 | if !path.IsAbs(src) { 48 | p, err := os.Getwd() 49 | if err != nil { 50 | panic(err) 51 | } 52 | src = path.Join(p, src) 53 | } 54 | return &ModuleSource{ 55 | Uri: &url.URL{ 56 | Scheme: "file", 57 | Path: src, 58 | }, 59 | } 60 | } 61 | 62 | // TextSource builds a ModuleSource whose contents are the provided text. 63 | func TextSource(text string) *ModuleSource { 64 | return &ModuleSource{ 65 | // repl:text 66 | Uri: &url.URL{ 67 | Scheme: "repl", 68 | Opaque: "text", 69 | }, 70 | Contents: text, 71 | } 72 | } 73 | 74 | // UriSource builds a ModuleSource using the input uri. 75 | // 76 | // It panics if the uri is not valid. 77 | func UriSource(uri string) *ModuleSource { 78 | parsedUri, err := url.Parse(uri) 79 | if err != nil { 80 | panic(err) 81 | } 82 | return &ModuleSource{ 83 | Uri: parsedUri, 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | // RegisterMapping associates the type given the Pkl name to the corresponding Go type. 24 | // 25 | //goland:noinspection GoUnusedExportedFunction 26 | func RegisterMapping(name string, value any) { 27 | schemas[name] = reflect.TypeOf(value) 28 | } 29 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | myAnimal: Animal = new Greyhound { 28 | name = "Uni" 29 | barks = false 30 | canRoach = true 31 | } 32 | 33 | house: House = new { 34 | area = 2000 35 | bedrooms = 3 36 | bathrooms = 2 37 | } 38 | 39 | abstract class Animal { 40 | name: String 41 | } 42 | 43 | open class Dog extends Animal { 44 | barks: Boolean 45 | breed: String 46 | } 47 | 48 | class Greyhound extends Dog { 49 | breed = "Greyhound" 50 | canRoach: Boolean 51 | } 52 | 53 | class Cat extends Animal { 54 | meows: Boolean 55 | } 56 | 57 | class House { 58 | area: Int 59 | bedrooms: Int 60 | bathrooms: Int 61 | } 62 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 38 | return nil, err 39 | } 40 | return &ret, nil 41 | } 42 | -------------------------------------------------------------------------------- /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/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.RegisterMapping("any", Any{}) 8 | pkl.RegisterMapping("any#Person", Person{}) 9 | } 10 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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)(nil) 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/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 | MyAnimal Animal `pkl:"myAnimal"` 14 | 15 | House *House `pkl:"house"` 16 | } 17 | 18 | // LoadFromPath loads the pkl module at the given path and evaluates it into a Classes 19 | func LoadFromPath(ctx context.Context, path string) (ret *Classes, err error) { 20 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 21 | if err != nil { 22 | return nil, 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 Classes 35 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (*Classes, error) { 36 | var ret Classes 37 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 38 | return nil, err 39 | } 40 | return &ret, nil 41 | } 42 | -------------------------------------------------------------------------------- /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)(nil) 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 | -------------------------------------------------------------------------------- /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)(nil) 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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.RegisterMapping("classes", Classes{}) 8 | pkl.RegisterMapping("classes#House", House{}) 9 | pkl.RegisterMapping("classes#Dog", DogImpl{}) 10 | pkl.RegisterMapping("classes#Greyhound", GreyhoundImpl{}) 11 | pkl.RegisterMapping("classes#Cat", CatImpl{}) 12 | } 13 | -------------------------------------------------------------------------------- /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 | 38 | // LoadFromPath loads the pkl module at the given path and evaluates it into a Collections 39 | func LoadFromPath(ctx context.Context, path string) (ret *Collections, err error) { 40 | evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions) 41 | if err != nil { 42 | return nil, err 43 | } 44 | defer func() { 45 | cerr := evaluator.Close() 46 | if err == nil { 47 | err = cerr 48 | } 49 | }() 50 | ret, err = Load(ctx, evaluator, pkl.FileSource(path)) 51 | return ret, err 52 | } 53 | 54 | // Load loads the pkl module at the given source and evaluates it with the given evaluator into a Collections 55 | func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (*Collections, error) { 56 | var ret Collections 57 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 58 | return nil, err 59 | } 60 | return &ret, nil 61 | } 62 | -------------------------------------------------------------------------------- /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.RegisterMapping("collections", Collections{}) 8 | } 9 | -------------------------------------------------------------------------------- /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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 56 | return nil, err 57 | } 58 | return &ret, nil 59 | } 60 | -------------------------------------------------------------------------------- /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.RegisterMapping("datasize", Datasize{}) 8 | } 9 | -------------------------------------------------------------------------------- /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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 48 | return nil, err 49 | } 50 | return &ret, nil 51 | } 52 | -------------------------------------------------------------------------------- /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.RegisterMapping("duration", Duration{}) 8 | } 9 | -------------------------------------------------------------------------------- /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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 34 | return nil, err 35 | } 36 | return &ret, nil 37 | } 38 | -------------------------------------------------------------------------------- /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/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.RegisterMapping("dynamic", Dynamic{}) 8 | pkl.RegisterMapping("dynamic#MyClass", MyClass{}) 9 | } 10 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 92 | return nil, err 93 | } 94 | return &ret, nil 95 | } 96 | -------------------------------------------------------------------------------- /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.RegisterMapping("nullables", Nullables{}) 8 | pkl.RegisterMapping("nullables#MyClass", MyClass{}) 9 | } 10 | -------------------------------------------------------------------------------- /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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 60 | return nil, err 61 | } 62 | return &ret, nil 63 | } 64 | -------------------------------------------------------------------------------- /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.RegisterMapping("primitives", Primitives{}) 8 | } 9 | -------------------------------------------------------------------------------- /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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 38 | return nil, err 39 | } 40 | return &ret, nil 41 | } 42 | -------------------------------------------------------------------------------- /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.RegisterMapping("unions", Unions{}) 8 | } 9 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 nil, 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 | if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil { 34 | return nil, err 35 | } 36 | return &ret, nil 37 | } 38 | -------------------------------------------------------------------------------- /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.RegisterMapping("unknown_type", UnknownType{}) 8 | } 9 | -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/any.pkl.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/96eb7a1df6cfaf39770fb907b99ba80277413665/pkl/test_fixtures/msgpack/any.pkl.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/classes.pkl.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/96eb7a1df6cfaf39770fb907b99ba80277413665/pkl/test_fixtures/msgpack/classes.pkl.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/collections.pkl.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/96eb7a1df6cfaf39770fb907b99ba80277413665/pkl/test_fixtures/msgpack/collections.pkl.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/collections.res1.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/96eb7a1df6cfaf39770fb907b99ba80277413665/pkl/test_fixtures/msgpack/collections.res1.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/collections.res2.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/96eb7a1df6cfaf39770fb907b99ba80277413665/pkl/test_fixtures/msgpack/collections.res2.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/collections.res9.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/96eb7a1df6cfaf39770fb907b99ba80277413665/pkl/test_fixtures/msgpack/collections.res9.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/datasize.pkl.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/96eb7a1df6cfaf39770fb907b99ba80277413665/pkl/test_fixtures/msgpack/datasize.pkl.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/duration.pkl.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/96eb7a1df6cfaf39770fb907b99ba80277413665/pkl/test_fixtures/msgpack/duration.pkl.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/dynamic.pkl.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/96eb7a1df6cfaf39770fb907b99ba80277413665/pkl/test_fixtures/msgpack/dynamic.pkl.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/nullables.pkl.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/96eb7a1df6cfaf39770fb907b99ba80277413665/pkl/test_fixtures/msgpack/nullables.pkl.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/primitives.pkl.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/96eb7a1df6cfaf39770fb907b99ba80277413665/pkl/test_fixtures/msgpack/primitives.pkl.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/unions.pkl.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/96eb7a1df6cfaf39770fb907b99ba80277413665/pkl/test_fixtures/msgpack/unions.pkl.msgpack -------------------------------------------------------------------------------- /pkl/test_fixtures/msgpack/unknown_type.pkl.msgpack: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apple/pkl-go/96eb7a1df6cfaf39770fb907b99ba80277413665/pkl/test_fixtures/msgpack/unknown_type.pkl.msgpack -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /pkl/version_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 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-alpha", "2.0.0-beta")) 44 | assert.Equal(t, 1, compareVersions("2.0.0-alpha", "2.0.0-aaa")) 45 | assert.Equal(t, 0, compareVersions("2.0.0-alpha", "2.0.0-alpha")) 46 | assert.Equal(t, 0, compareVersions("2.0.0-1.2.3", "2.0.0-1.2.3")) 47 | assert.Equal(t, 1, compareVersions("2.0.0-1.2.3", "2.0.0-1.2.2")) 48 | assert.Equal(t, 0, compareVersions("2.0.0-a.b.3", "2.0.0-a.b.3")) 49 | assert.Equal(t, 1, compareVersions("2.0.0-1.2.3.4", "2.0.0-1.2.3")) 50 | assert.Equal(t, 0, compareVersions("2.0.0+foo", "2.0.0+bar")) 51 | } 52 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------