ast

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package ast defines the Abstract Syntax Tree node types for ClassAds expressions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendQuoteAttributeName added in v0.2.0

func AppendQuoteAttributeName(dst []byte, name string) []byte

AppendQuoteAttributeName appends QuoteAttributeName(name) to dst and returns the extended slice, the append-to-buffer variant used when rendering many attribute names into a shared buffer (record keys, scoped/selected attr refs) without a per-name string allocation.

func AppendQuoteString added in v0.2.0

func AppendQuoteString(dst []byte, s string) []byte

AppendQuoteString appends QuoteString(s) to dst and returns the extended slice, so a caller building a larger buffer (e.g. an ad's "Name = Value" line) does not allocate an intermediate string per value.

func AppendQuoteStringBytes added in v0.2.0

func AppendQuoteStringBytes(dst, s []byte) []byte

AppendQuoteStringBytes is AppendQuoteString for a value that already lives in a byte slice (e.g. a string literal's bytes inside a wire buffer): it quotes s without first copying it into a Go string, producing output identical to AppendQuoteString(dst, string(s)). The common no-escape case is a plain byte copy; the escape path iterates runes via `range string(s)`, which the compiler lowers without allocating a string.

func AppendQuoteStringOld added in v0.10.0

func AppendQuoteStringOld(dst []byte, s string) []byte

AppendQuoteStringOld quotes s as an OLD-ClassAd string literal: it wraps s in double quotes and escapes ONLY an embedded double-quote (as \"). A backslash is emitted literally, because old-ClassAd string lexing (C++ Lexer::tokenizeStringOld) does no escape processing and treats every backslash as a literal character -- so this is the exact inverse of that lexer (and of the collections old-ClassAd ingest fast path).

This is the correct serialization for values sent over the wire in old-ClassAd form, e.g. a collector forwarding a startd ad whose OSIssue is the two bytes `\` `S`. Using the new-ClassAd quoter (AppendQuoteString) there would double the backslash to `\\` on every hop, and for a value ending in a backslash would emit an unterminated string the receiver rejects (a forwarding connection reset). A value ending in a lone backslash, or containing a backslash immediately before a quote, cannot be represented unambiguously in old-ClassAd at all -- the same inherent limitation C++ has; such values do not occur in the machine/job ads this serves.

func AppendQuoteStringOldBytes added in v0.10.0

func AppendQuoteStringOldBytes(dst, s []byte) []byte

AppendQuoteStringOldBytes is AppendQuoteStringOld for a value already in a byte slice (e.g. a string literal's bytes inside a wire buffer), quoting it without first copying it into a Go string.

func QuoteAttributeName added in v0.1.0

func QuoteAttributeName(name string) string

QuoteAttributeName renders an attribute name so it re-parses: a valid bare identifier is returned as-is; anything else (empty, non-identifier characters, or a name that would lex as a reserved keyword/literal) is single-quoted with '\” and '\\' escaped, matching the lexer's quoted-attribute-name unescaping.

func QuoteString added in v0.1.0

func QuoteString(s string) string

Types

type AttributeAssignment

type AttributeAssignment struct {
	Name  string
	Value Expr
}

AttributeAssignment represents an attribute assignment (name = expr).

func (*AttributeAssignment) String

func (a *AttributeAssignment) String() string

type AttributeReference

type AttributeReference struct {
	Name  string
	Scope AttributeScope
	// contains filtered or unexported fields
}

AttributeReference represents a reference to an attribute by name.

func NewAttributeReference added in v0.5.3

func NewAttributeReference(name string, scope AttributeScope) *AttributeReference

NewAttributeReference builds an attribute reference with its case-folded name precomputed, so evaluation can resolve it without a per-lookup allocation.

func (*AttributeReference) NormalizedName added in v0.5.3

func (a *AttributeReference) NormalizedName() string

NormalizedName returns the case-folded attribute name used for lookup. It returns the value precomputed by NewAttributeReference when present, else lowercases Name on demand (for nodes built via a struct literal).

func (*AttributeReference) String

func (a *AttributeReference) String() string

type AttributeScope

type AttributeScope int

AttributeScope represents the scope of an attribute reference.

const (
	// NoScope represents an unscoped attribute reference
	NoScope AttributeScope = iota
	// MyScope represents MY.attr (current ClassAd)
	MyScope
	// TargetScope represents TARGET.attr (target ClassAd in matching)
	TargetScope
	// ParentScope represents PARENT.attr (parent ClassAd)
	ParentScope
)

type BinaryOp

type BinaryOp struct {
	Op    string
	Left  Expr
	Right Expr
}

BinaryOp represents a binary operation (e.g., +, -, *, /, &&, ||, ==, etc.).

func (*BinaryOp) String

func (b *BinaryOp) String() string

type BooleanLiteral

type BooleanLiteral struct {
	Value bool
}

BooleanLiteral represents a boolean constant (true or false).

func (*BooleanLiteral) String

func (b *BooleanLiteral) String() string

type ClassAd

type ClassAd struct {
	Attributes []*AttributeAssignment
}

ClassAd represents a complete ClassAd (a record of attribute assignments).

func (*ClassAd) String

func (c *ClassAd) String() string

type ConditionalExpr

type ConditionalExpr struct {
	Condition Expr
	TrueExpr  Expr
	FalseExpr Expr
}

ConditionalExpr represents a ternary conditional expression (cond ? true_expr : false_expr).

func (*ConditionalExpr) String

func (c *ConditionalExpr) String() string

type ElvisExpr

type ElvisExpr struct {
	Left  Expr // The expression to test for undefined
	Right Expr // The fallback expression if Left is undefined
}

ElvisExpr represents the Elvis operator (expr1 ?: expr2). If expr1 evaluates to undefined, returns expr2; otherwise returns expr1.

func (*ElvisExpr) String

func (e *ElvisExpr) String() string

type ErrorLiteral

type ErrorLiteral struct{}

ErrorLiteral represents an error value.

func (*ErrorLiteral) String

func (e *ErrorLiteral) String() string

type Expr

type Expr interface {
	Node
	// contains filtered or unexported methods
}

Expr represents a ClassAd expression.

func Parenthesize added in v0.1.0

func Parenthesize(e Expr) Expr

Parenthesize wraps an expression in a ParenExpr, recording that the source parenthesized it so unparsing can echo the parentheses (matching the reference engine). The wrapped expression is returned for use in grammar actions.

type FunctionCall

type FunctionCall struct {
	Name string
	Args []Expr
}

FunctionCall represents a function call with arguments.

func (*FunctionCall) String

func (f *FunctionCall) String() string

type IntegerLiteral

type IntegerLiteral struct {
	Value int64
}

IntegerLiteral represents an integer constant.

func (*IntegerLiteral) String

func (i *IntegerLiteral) String() string

type ListLiteral

type ListLiteral struct {
	Elements []Expr
}

ListLiteral represents a list of expressions.

func (*ListLiteral) String

func (l *ListLiteral) String() string

type Node

type Node interface {
	String() string
}

Node is the base interface for all AST nodes.

type ParenExpr added in v0.1.0

type ParenExpr struct {
	Inner Expr
}

ParenExpr is an expression wrapped in explicit source parentheses. The reference engine echoes parentheses verbatim when unparsing -- around any expression, including primaries ((x), (5)) and nested ((x)) -- so they are preserved as a node rather than a flag. Evaluation is transparent (the inner expression's value).

func (*ParenExpr) String added in v0.1.0

func (p *ParenExpr) String() string

String is transparent: the AST's String() methods are a debug representation that already always-parenthesizes operators, so echoing the explicit source parentheses here would double them. The reference-faithful unparser (classad/unparse.go) is what emits the preserved parentheses.

type RealLiteral

type RealLiteral struct {
	Value float64
}

RealLiteral represents a floating-point constant.

func (*RealLiteral) String

func (r *RealLiteral) String() string

type RecordLiteral

type RecordLiteral struct {
	ClassAd *ClassAd
}

RecordLiteral represents a record (nested ClassAd).

func (*RecordLiteral) String

func (r *RecordLiteral) String() string

type SelectExpr

type SelectExpr struct {
	Record Expr
	Attr   string
}

SelectExpr represents attribute selection (expr.attr).

func (*SelectExpr) String

func (s *SelectExpr) String() string

type StringLiteral

type StringLiteral struct {
	Value string
}

StringLiteral represents a string constant.

func (*StringLiteral) String

func (s *StringLiteral) String() string

type SubscriptExpr

type SubscriptExpr struct {
	Container Expr
	Index     Expr
}

SubscriptExpr represents list/record subscripting (expr[index]).

func (*SubscriptExpr) String

func (s *SubscriptExpr) String() string

type UnaryOp

type UnaryOp struct {
	Op   string
	Expr Expr
}

UnaryOp represents a unary operation (e.g., -, !, ~).

func (*UnaryOp) String

func (u *UnaryOp) String() string

type UndefinedLiteral

type UndefinedLiteral struct{}

UndefinedLiteral represents an undefined value.

func (*UndefinedLiteral) String

func (u *UndefinedLiteral) String() string

Jump to

Keyboard shortcuts

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