Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Pkl #6718

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,9 @@
[submodule "vendor/grammars/language-pcb"]
path = vendor/grammars/language-pcb
url = https://github.com/Alhadis/language-pcb
[submodule "vendor/grammars/language-pkl"]
path = vendor/grammars/language-pkl
url = https://github.com/nishtahir/language-pkl.git
[submodule "vendor/grammars/language-povray"]
path = vendor/grammars/language-povray
url = https://github.com/c-lipka/language-povray
Expand Down Expand Up @@ -1353,3 +1356,6 @@
[submodule "vendor/grammars/zephir-sublime"]
path = vendor/grammars/zephir-sublime
url = https://github.com/phalcon/zephir-sublime
[submodule "vendor/grammars/language-pkl"]
path = vendor/grammars/language-pkl
url = https://github.com/nishtahir/language-pkl.git
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops. There should only be one new addition and the file should be alphabetised (that's what the script/add-grammar script does. This last entry shouldn't be here.

2 changes: 2 additions & 0 deletions grammars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,8 @@ vendor/grammars/language-pcb:
- source.pcb.board
- source.pcb.schematic
- source.pcb.sexp
vendor/grammars/language-pkl:
- source.pkl
vendor/grammars/language-povray:
- source.pov-ray sdl
vendor/grammars/language-property-list:
Expand Down
5 changes: 5 additions & 0 deletions lib/linguist/heuristics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,11 @@ disambiguations:
pattern: '<\?hh'
- language: PHP
pattern: '<\?[^h]'
- extensions: ['.pkl']
rules:
- language: Pkl
pattern: 'new|class|function|import|module|(\w+\s*({|=))'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks waaaay too loose as it'll match those first few strings anywhere in the line, eg it'll match "this new language is pkl" or "I came first in my class" or "this functionality is awesome" or "imported cheese smells". You probably don't want this 😉.

- language: Pickle
- extensions: ['.pl']
rules:
- language: Prolog
Expand Down
10 changes: 10 additions & 0 deletions lib/linguist/languages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5240,6 +5240,16 @@ Pike:
tm_scope: source.pike
ace_mode: text
language_id: 287
Pkl:
type: programming
color: "#6b9543"
extensions:
- ".pkl"
interpreters:
- pkl
tm_scope: source.pkl
ace_mode: text
language_id: 502403550
PlantUML:
type: data
color: "#fbbd16"
Expand Down
38 changes: 38 additions & 0 deletions samples/Pkl/app-config.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// ===----------------------------------------------------------------------===//
// Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ===----------------------------------------------------------------------===//
// This sample is taken from https://github.com/apple/pkl-go-examples and showcases
// the use of PKL for configuration of a Go app, see the original repository for
// more information

/// Application configuration for the Pkl Go Example application.
///
/// See generated sources in the gen/ directory.
@go.Package { name = "github.com/apple/pkl-go-examples/gen/appconfig" }
module org.pkl.golang.example.AppConfig

import "package://pkg.pkl-lang.org/pkl-go/pkl.golang@0.5.0#/go.pkl"
import "RedisConfig.pkl"

typealias Port = UInt16(this > 0)

/// The host to listen on
host: String = "127.0.0.1"

/// The application port to listen on
port: Port = 5051

/// Redis settings for this application
redis: RedisConfig
101 changes: 101 additions & 0 deletions samples/Pkl/frontend.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
//===----------------------------------------------------------------------===//
// Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//===----------------------------------------------------------------------===//
// This sample is taken from https://github.com/apple/pkl-k8s-examples and showcases
// the use of PKL to generate YAML manifests for K8s, see the original repository for
// additional information

import "@k8s/K8sResource.pkl"
import "@k8s/api/apps/v1/Deployment.pkl"
import "@k8s/api/core/v1/Service.pkl"

resources: Listing<K8sResource> = new {
new Service {
metadata {
name = "frontend"
labels {
["app"] = "guestbook"
["tier"] = "frontend"
}
}
spec {
type = "NodePort"
ports {
new {
port = 80
}
}
selector {
["app"] = "guestbook"
["tier"] = "frontend"
}
}
}

new Deployment {
metadata {
name = "frontend"
}
spec {
selector {
matchLabels {
["app"] = "guestbook"
["tier"] = "frontend"
}
}
replicas = 3
template {
metadata {
labels {
["app"] = "guestbook"
["tier"] = "frontend"
}
}
spec {
containers {
new {
name = "php-redis"
image = "gcr.io/google-samples/gb-frontend:v4"
resources {
requests {
["cpu"] = "100m"
["memory"] = "100Mi"
}
}
env {
new {
name = "GET_HOSTS_FROM"
value = "dns"
}
}
ports {
new {
containerPort = 80
}
}
}
}
}
}
}
}
}

output {
value = resources
renderer = (K8sResource.output.renderer as YamlRenderer) {
isStream = true
}
}
1 change: 1 addition & 0 deletions vendor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ This is a list of grammars that Linguist selects to provide syntax highlighting
- **PicoLisp:** [textmate/lisp.tmbundle](https://github.com/textmate/lisp.tmbundle)
- **PigLatin:** [goblindegook/sublime-text-pig-latin](https://github.com/goblindegook/sublime-text-pig-latin)
- **Pike:** [hww3/pike-textmate](https://github.com/hww3/pike-textmate)
- **Pkl:** [nishtahir/language-pkl](https://github.com/nishtahir/language-pkl)
- **PlantUML:** [qjebbs/vscode-plantuml](https://github.com/qjebbs/vscode-plantuml)
- **Pod 6:** [perl6/atom-language-perl6](https://github.com/perl6/atom-language-perl6)
- **PogoScript:** [featurist/PogoScript.tmbundle](https://github.com/featurist/PogoScript.tmbundle)
Expand Down
1 change: 1 addition & 0 deletions vendor/grammars/language-pkl
Submodule language-pkl added at 05b590