go-pcore

Puppet's Pcore type system in pure Go โ€” the type calculus, parser, value model and assignability lattice, no cgo.

pure Go ยท zero cgo Pcore type calculus type parser IsInstance IsAssignable Infer rich-data ToData/FromData round-trippable String() 100% coverage 6 arches
Documentation GitHub
Documentation (MkDocs Material + mike) License: BSD-3-Clause Go 1.26.4+ Coverage 100%

go-pcore is a pure-Go (no cgo) reimplementation of Pcore, the data-type and value model that underpins Puppet, Hiera and Facter values. It gives a Go program the Puppet type calculus โ€” a type model, a type parser (Parse(string) (Type, error)), a value model, and the load-bearing operations: IsInstance (value โˆˆ type), IsAssignable (subtype), Infer, Generalize, CommonType, and the rich-data ToData / FromData serialization. Type names and semantics track Puppet's Puppet::Pops::Types, so it is a drop-in for Puppet type expressions. It is the foundational type layer for go-puppet and go-ruby-puppet โ€” differential in spirit with the Puppet spec, 100% coverage, CI green across 6 arches.

Type model ready

The Pcore type calculus as Go types: scalar (Integer[min,max], Float, Numeric, String[min,max], Boolean, Undef, Default, Scalar, ScalarData, Data, Any), collection (Array, Hash, Tuple, Struct, Collection) and abstract (Variant, Optional, NotUndef, Enum, Pattern, Regexp, Type, Sensitive), plus Timestamp / Timespan / Binary.

Type parser ready

Parse(string) (Type, error) โ€” a lexer + recursive-descent parser for the Pcore type grammar, matching Puppet’s spelling. Every Type.String() is canonical and round-trips: Parse(t.String()) reproduces t.

Value model ready

Plain Go scalars (bool, int64, float64, string), []Value arrays and *Hash, plus wrappers โ€” Undef, Default, Sensitive (redacts on String() and on serialization), Regexp, Binary, Timestamp, Timespan.

Operations ready

The load-bearing lattice: IsInstance(t, v) (value โˆˆ type), IsAssignable(a, b) (subtype), Infer(v) (a value’s most specific type), Generalize and CommonType. The assignability arms are covered exhaustively by tests.

Rich-data serialization ready

ToData / FromData implement Pcore’s rich-data protocol (the __ptype / __pvalue tagging): round-trippable through the data-only tree, with Sensitive redacted by design.

Type aliases & TypeSet ready

Named, recursive type aliases and TypeSet (grouped, referenceable type definitions) via a Loader type environment, resolved transparently through Parse / IsInstance / IsAssignable / Infer. Timestamp / Timespan range parameters, SemVer / SemVerRange, Init, Object, Runtime, URI, Iterable / Iterator, Error and Callable are implemented too.

A faithful port of Puppet's Pcore type system in pure Go, cgo disabled, so it cross-compiles and embeds anywhere. Every Type.String() is canonical and round-trips through Parse; the assignability lattice is covered exhaustively by tests. It is a standalone, reusable module and the type layer for the sibling org github.com/go-puppet.