Help us shape the future of Go! Take the 2026 Go Developer Survey

ast

package
v0.22.0-test2 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0, Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package ast is the parsed form of a writ policy file, a direct port of the retired Rust spike's ast.rs (the porting reference named by SPEC §12.11). It preserves the shape the spec's IL depends on: allow rules carry plain expressions, deny rules carry negatable ones, so a negated allow is unrepresentable rather than validated away.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AllowRule

type AllowRule struct {
	Users    Expr
	Accounts Expr
	Hosts    Expr
	Clauses  []Clause
	Pos      diag.Pos
}

AllowRule carries plain expressions: negation on the allow path is unrepresentable, mirroring the IL's MatchSet / NegatableMatchSet split.

type Any

type Any struct {
	P diag.Pos
}

Any is `*` — matches everything; kept distinct from a glob per the spec (a surface `*` compiles to {"any": true}, never {"glob": "*"}).

func (*Any) Pos

func (a *Any) Pos() diag.Pos

type Atom

type Atom interface {
	Pos() diag.Pos
}

Atom is one matcher in an expression: *MacroRef, *TagMatcher, *Name, *Labels, or *Any.

type Clause

type Clause interface {
	Keyword() string
	Pos() diag.Pos
}

Clause is one tail clause: *Require, *When, *Until, *TTL, *Notify, or *Label.

type DenyRule

type DenyRule struct {
	Users    NegExpr
	Accounts NegExpr
	Hosts    NegExpr
	Clauses  []Clause
	Pos      diag.Pos
}

DenyRule carries negatable expressions in all three positions.

type Expr

type Expr struct {
	Atoms     []Atom
	Bracketed bool
	Pos       diag.Pos
}

Expr is a union of atoms. Singletons parse to a one-element list; Bracketed records whether the author wrote `[...]` (for the formatter, later).

type File

type File struct {
	Items []Item
}

File is a parsed policy file: a sequence of macro definitions and rules.

type Item

type Item interface {
	// contains filtered or unexported methods
}

Item is one statement: *MacroDef, *AllowRule, or *DenyRule.

type Kind

type Kind int

Kind is one of the three matcher kinds. A macro declares one; every expression position implies one.

const (
	KindUser Kind = iota
	KindAccount
	KindHost
)

func (Kind) String

func (k Kind) String() string

type Label

type Label struct {
	Value Value
	P     diag.Pos
}

Label is a human-readable alias for the rule; cosmetic only.

func (*Label) Keyword

func (c *Label) Keyword() string

func (*Label) Pos

func (c *Label) Pos() diag.Pos

type LabelPair

type LabelPair struct {
	Key   Value
	Value Value
}

LabelPair is one `key=value` entry in a label selector.

type Labels

type Labels struct {
	Pairs []LabelPair
	P     diag.Pos
}

Labels is `{k=v, ...}` — host position only; entries AND.

func (*Labels) Pos

func (a *Labels) Pos() diag.Pos

type MacroDef

type MacroDef struct {
	Kind Kind
	Name string
	Body Expr
	Pos  diag.Pos
}

MacroDef binds a name to a match expression of a declared kind.

type MacroRef

type MacroRef struct {
	Name string
	P    diag.Pos
}

MacroRef is `$name` — a splice of a same-kind macro.

func (*MacroRef) Pos

func (a *MacroRef) Pos() diag.Pos

type Name

type Name struct {
	Value Value
}

Name is a bare or quoted account/host name; bare names may glob (`*`, `?`).

func (*Name) Pos

func (a *Name) Pos() diag.Pos

type NegExpr

type NegExpr struct {
	Not bool
	Expr
}

NegExpr is an expression plus a bit; `!` applies to the whole expression, never to an atom inside a list.

type Notify

type Notify struct {
	Targets []Value
	P       diag.Pos
}

Notify names fire-and-forget notification targets.

func (*Notify) Keyword

func (c *Notify) Keyword() string

func (*Notify) Pos

func (c *Notify) Pos() diag.Pos

type Require

type Require struct {
	Names []Value
	P     diag.Pos
}

Require names async facts that must all be satisfied (allow-only).

func (*Require) Keyword

func (c *Require) Keyword() string

func (*Require) Pos

func (c *Require) Pos() diag.Pos

type TTL

type TTL struct {
	Seconds uint64
	P       diag.Pos
}

TTL overrides the deployment-default cert TTL (allow-only).

func (*TTL) Keyword

func (c *TTL) Keyword() string

func (*TTL) Pos

func (c *TTL) Pos() diag.Pos

type Tag

type Tag int

Tag is one of the five user-matcher prefixes.

const (
	TagID Tag = iota
	TagGroup
	TagType
	TagDept
	TagOrg
)

func TagOf

func TagOf(s string) (Tag, bool)

TagOf maps a tag word to its Tag, reporting whether s names one.

func (Tag) String

func (t Tag) String() string

type TagMatcher

type TagMatcher struct {
	Tag   Tag
	Value Value
}

TagMatcher is `tag:value` — user position only.

func (*TagMatcher) Pos

func (a *TagMatcher) Pos() diag.Pos

type Until

type Until struct {
	TS Value
	P  diag.Pos
}

Until stops the rule matching at the given instant (allow-only).

func (*Until) Keyword

func (c *Until) Keyword() string

func (*Until) Pos

func (c *Until) Pos() diag.Pos

type Value

type Value struct {
	Text   string
	Quoted bool
	Pos    diag.Pos
}

Value is a scalar. Quoted matters for well-formedness: a quoted attribute value is always a literal, while a bare `*`/`?` in an attribute-value position is an error (SPEC §7 error 11).

type When

type When struct {
	Names []Value
	P     diag.Pos
}

When names sync flags that must all currently hold.

func (*When) Keyword

func (c *When) Keyword() string

func (*When) Pos

func (c *When) Pos() diag.Pos

Jump to

Keyboard shortcuts

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