Reference
Syntax Reference
A compact map of common Pkl syntax for modules, expressions, objects, and types.
Syntax Reference
This is a compact syntax map for reading and authoring Pkl. It is not a full grammar listing; use the official language reference when exact grammar details matter.
Module Forms
module app.configamends "base.pkl"extends "template.pkl"import "db.pkl" as dbCommon module forms:
-
module declarations
-
amendsandextends -
import declarations with aliases
-
top-level properties
-
module-level
localbindings -
class declarations
-
function declarations
-
typealias declarations
Literals and Values
name = "api"count = 3enabled = truemissing = nullCommon string escapes include \n, \t, \r, \", and \\.
Expressions
Common expression families include:
-
identifiers and member access
-
safe member access
-
subscript access
-
arithmetic and comparison operators
-
boolean operators
-
null coalescing
-
isandastype operands -
if (...) ... else ... -
object literals
-
typed object literals
-
listings and mappings
-
calls and lambdas
-
import("...") -
non-null assertions
-
object amendments
Object Bodies
server { host = "localhost" port = 8080}Object bodies are the center of Pkl authoring. Use Object Model for amendments, late binding, and receiver keywords.
Callable Syntax
function add(x: Int, y: Int): Int = x + yinc = (x: Int): Int -> x + 1Move anonymous functions into named declarations once the logic becomes shared.
Type Syntax
name: String = "api"maybeName: String? = nullports: Listing<Int> = new Listing { 8080 }value: String | Int = "api"Type annotations make object contracts visible to readers, editor tools, and host-language integrations.