Documentation
¶
Overview ¶
Package ast defines the abstract-syntax model for the Puppet language — the Go analogue of Puppet's Puppet::Pops::Model. Every node produced by the parser implements Node; concrete node kinds are plain data structs so an evaluator can dispatch on them with a type switch. Positions are carried by an embedded Base so error messages can point at source.
Index ¶
- func Sexpr(n Node) string
- type Access
- type Array
- type Assignment
- type AttributeOp
- type Base
- type Binary
- type Boolean
- type Call
- type Case
- type CaseOption
- type ClassDefinition
- type Collector
- type Concat
- type Default
- type DefineDefinition
- type Float
- type FunctionDefinition
- type Hash
- type Heredoc
- type If
- type Integer
- type KeyedEntry
- type Lambda
- type MethodCall
- type Node
- type NodeDefinition
- type Parameter
- type PlanDefinition
- type Position
- type Program
- type QualifiedName
- type QualifiedReference
- type Regexp
- type Relationship
- type Resource
- type ResourceBody
- type ResourceDefaults
- type ResourceForm
- type ResourceOverride
- type Selector
- type SelectorEntry
- type String
- type Unary
- type Undef
- type Unless
- type Variable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Access ¶
Access is `operand[key, ...]` — element access and, on a QualifiedReference, a parameterized data type such as `Integer[1,10]`.
type Assignment ¶
Assignment is `target op value` with op `=`, `+=` or `-=`.
type AttributeOp ¶
AttributeOp is one attribute operation inside a resource body. Op is `=>` or `+>`. Splat marks `* => hash`.
type Base ¶
type Base struct{ P Position }
Base carries a source position; every concrete node embeds it.
type Binary ¶
Binary is an infix operation: arithmetic (`+ - * / %`), shift/append (`<<`), comparison (`== != < > <= >=`), match (`=~ !~`), membership (`in`) and boolean (`and or`).
type Call ¶
Call is a function call. Functor is the callee (QualifiedName for a normal call). RVal marks a parenthesized (value) call vs a statement-style call (`include foo`). Lambda is an optional trailing block.
type Case ¶
type Case struct {
Base
Test Node
Options []CaseOption
}
Case is `case test { values: { body } ... }`.
type CaseOption ¶
CaseOption is one `values : { body }` arm of a Case.
type ClassDefinition ¶
ClassDefinition is `class name (params) inherits parent { body }`.
type Collector ¶
Collector is a resource collector: `Type <| query |>` (virtual) or `Type <<| query |>>` (exported). Query may be nil for the empty query.
type Concat ¶
Concat is an interpolating string: an ordered list of parts, each either a String (literal text) or an arbitrary embedded expression from `${...}` or `$var`.
type DefineDefinition ¶
DefineDefinition is `define name (params) { body }`.
type FunctionDefinition ¶
FunctionDefinition is `function name(params) >> ReturnType { body }`.
type Heredoc ¶
Heredoc is a heredoc string. Syntax is the optional tag (e.g. "json"); Text is a String or Concat holding the (already dedented) body.
type KeyedEntry ¶
KeyedEntry is one `key => value` pair of a Hash.
type MethodCall ¶
MethodCall is `receiver.method(args) |block|` (a `.`-chained call). A bare `$x.foo` is a MethodCall with no args.
type Node ¶
type Node interface {
// Pos returns the node's source position.
Pos() Position
// contains filtered or unexported methods
}
Node is implemented by every AST node.
type NodeDefinition ¶
NodeDefinition is `node matches { body }`. Matches are name/regexp/default literals.
type Parameter ¶
Parameter is one formal parameter: optional data-type, `$name`, optional default, and CapturesRest for `*$rest`.
type PlanDefinition ¶
PlanDefinition is a Bolt `plan name(params) { body }`. A plan is like a function whose body runs orchestration (run_task/apply/…) rather than producing a catalog.
type Position ¶
Position is a location in a source file: a 0-based byte offset plus the 1-based line and column it falls on.
type QualifiedName ¶
QualifiedName is a bareword (lower-case) name, e.g. a resource type, function name or a case/selector value such as `present`.
type QualifiedReference ¶
QualifiedReference is a type reference (starts upper-case), e.g. `Integer` or `Foo::Bar`.
type Relationship ¶
Relationship is a chaining operator between two references: `->`, `~>`, `<-` or `<~`.
type Resource ¶
type Resource struct {
Base
Type Node
Bodies []ResourceBody
Form ResourceForm
}
Resource is a resource declaration `type { title: attr => val ; ... }`.
type ResourceBody ¶
type ResourceBody struct {
Title Node
Ops []AttributeOp
}
ResourceBody is one `title: attributes` clause of a Resource.
type ResourceDefaults ¶
type ResourceDefaults struct {
Base
Type Node
Ops []AttributeOp
}
ResourceDefaults is `Type { attr => val }` — defaults for a resource type.
type ResourceForm ¶
type ResourceForm int
ResourceForm distinguishes regular, virtual (`@`) and exported (`@@`) resource declarations.
const ( // Regular is an ordinary resource declaration. Regular ResourceForm = iota // Virtual is an `@`-prefixed virtual resource. Virtual // Exported is an `@@`-prefixed exported resource. Exported )
type ResourceOverride ¶
type ResourceOverride struct {
Base
Resource Node
Ops []AttributeOp
}
ResourceOverride is `Type[title] { attr => val }` — an override.
type Selector ¶
type Selector struct {
Base
Operand Node
Entries []SelectorEntry
}
Selector is `operand ? { match => value, ... }`.
type SelectorEntry ¶
SelectorEntry is one arm of a Selector.
type String ¶
String is a single-quoted (non-interpolating) string literal, or a fully static double-quoted string with no interpolation.