ast

package
v0.0.0-...-4704126 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2026 License: BSD-3-Clause Imports: 3 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sexpr

func Sexpr(n Node) string

String renders a node as a compact, parenthesized s-expression. The form is stable and lossless enough to assert parser output against in tests; it is not Puppet source. A nil node renders as "nil".

Types

type Access

type Access struct {
	Base
	Operand Node
	Keys    []Node
}

Access is `operand[key, ...]` — element access and, on a QualifiedReference, a parameterized data type such as `Integer[1,10]`.

type Array

type Array struct {
	Base
	Elements []Node
}

Array is a `[...]` literal list.

type Assignment

type Assignment struct {
	Base
	Op     string
	Target Node
	Value  Node
}

Assignment is `target op value` with op `=`, `+=` or `-=`.

type AttributeOp

type AttributeOp struct {
	Name  string
	Op    string
	Value Node
	Splat bool
}

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.

func (Base) Pos

func (b Base) Pos() Position

Pos returns the embedded position.

type Binary

type Binary struct {
	Base
	Op          string
	Left, Right Node
}

Binary is an infix operation: arithmetic (`+ - * / %`), shift/append (`<<`), comparison (`== != < > <= >=`), match (`=~ !~`), membership (`in`) and boolean (`and or`).

type Boolean

type Boolean struct {
	Base
	Value bool
}

Boolean is a `true`/`false` literal.

type Call

type Call struct {
	Base
	Functor Node
	Args    []Node
	Lambda  *Lambda
	RVal    bool
}

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

type CaseOption struct {
	Values []Node
	Body   []Node
}

CaseOption is one `values : { body }` arm of a Case.

type ClassDefinition

type ClassDefinition struct {
	Base
	Name   string
	Params []Parameter
	Parent string
	Body   []Node
}

ClassDefinition is `class name (params) inherits parent { body }`.

type Collector

type Collector struct {
	Base
	Type     Node
	Query    Node
	Exported bool
}

Collector is a resource collector: `Type <| query |>` (virtual) or `Type <<| query |>>` (exported). Query may be nil for the empty query.

type Concat

type Concat struct {
	Base
	Parts []Node
}

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 Default

type Default struct{ Base }

Default is the literal `default`.

type DefineDefinition

type DefineDefinition struct {
	Base
	Name   string
	Params []Parameter
	Body   []Node
}

DefineDefinition is `define name (params) { body }`.

type Float

type Float struct {
	Base
	Value float64
}

Float is a floating-point literal.

type FunctionDefinition

type FunctionDefinition struct {
	Base
	Name       string
	Params     []Parameter
	ReturnType Node
	Body       []Node
}

FunctionDefinition is `function name(params) >> ReturnType { body }`.

type Hash

type Hash struct {
	Base
	Entries []KeyedEntry
}

Hash is a `{...}` literal hash.

type Heredoc

type Heredoc struct {
	Base
	Syntax string
	Text   Node
}

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 If

type If struct {
	Base
	Cond Node
	Then []Node
	Else []Node
}

If is `if/elsif/else`. Else holds either a body, a single nested If (elsif) or nil.

type Integer

type Integer struct {
	Base
	Value int64
	Radix int
}

Integer is an integer literal; Radix records 8, 10 or 16 as written.

type KeyedEntry

type KeyedEntry struct {
	Key   Node
	Value Node
}

KeyedEntry is one `key => value` pair of a Hash.

type Lambda

type Lambda struct {
	Base
	Params []Parameter
	Body   []Node
}

Lambda is a `|params| { body }` block.

type MethodCall

type MethodCall struct {
	Base
	Receiver Node
	Method   string
	Args     []Node
	Lambda   *Lambda
}

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

type NodeDefinition struct {
	Base
	Matches []Node
	Body    []Node
}

NodeDefinition is `node matches { body }`. Matches are name/regexp/default literals.

type Parameter

type Parameter struct {
	Type         Node
	Name         string
	Default      Node
	CapturesRest bool
}

Parameter is one formal parameter: optional data-type, `$name`, optional default, and CapturesRest for `*$rest`.

type PlanDefinition

type PlanDefinition struct {
	Base
	Name   string
	Params []Parameter
	Body   []Node
}

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

type Position struct {
	Offset int
	Line   int
	Column int
}

Position is a location in a source file: a 0-based byte offset plus the 1-based line and column it falls on.

func (Position) String

func (p Position) String() string

String renders the position as line:column.

type Program

type Program struct {
	Base
	Body []Node
}

Program is the root: the ordered top-level body of a manifest.

type QualifiedName

type QualifiedName struct {
	Base
	Value string
}

QualifiedName is a bareword (lower-case) name, e.g. a resource type, function name or a case/selector value such as `present`.

type QualifiedReference

type QualifiedReference struct {
	Base
	Value string
}

QualifiedReference is a type reference (starts upper-case), e.g. `Integer` or `Foo::Bar`.

type Regexp

type Regexp struct {
	Base
	Value string
}

Regexp is a `/.../ ` regular-expression literal (source without slashes).

type Relationship

type Relationship struct {
	Base
	Op          string
	Left, Right Node
}

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

type SelectorEntry struct {
	Match Node
	Value Node
}

SelectorEntry is one arm of a Selector.

type String

type String struct {
	Base
	Value string
}

String is a single-quoted (non-interpolating) string literal, or a fully static double-quoted string with no interpolation.

type Unary

type Unary struct {
	Base
	Op      string
	Operand Node
}

Unary is a prefix `-x`, `!x` or splat `*x`.

type Undef

type Undef struct{ Base }

Undef is the literal `undef`.

type Unless

type Unless struct {
	Base
	Cond Node
	Then []Node
	Else []Node
}

Unless is `unless cond { } else { }`.

type Variable

type Variable struct {
	Base
	Name string
}

Variable is `$name` (name has no leading `$`; `::` top-scope kept).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL