ast

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayExpr

type ArrayExpr struct {
	Pos      Position
	Elements []ExprNode
}

ArrayExpr constructs an array literal: [1, 2, 3]

func (*ArrayExpr) ExprPos

func (e *ArrayExpr) ExprPos() Position

type BinaryExpr

type BinaryExpr struct {
	Pos   Position
	Op    string // "+", "-", "*", "/", "%", "==", "!=", ">", "<", ">=", "<=", "&&", "||", "++"
	Left  ExprNode
	Right ExprNode
}

BinaryExpr represents a binary operation: a + b, x > 0, a && b, s ++ t

func (*BinaryExpr) ExprPos

func (e *BinaryExpr) ExprPos() Position

type CoalesceExpr

type CoalesceExpr struct {
	Pos   Position
	Left  ExprNode
	Right ExprNode
}

CoalesceExpr provides null coalescing: a ?? b

func (*CoalesceExpr) ExprPos

func (e *CoalesceExpr) ExprPos() Position

type ComparisonPattern

type ComparisonPattern struct {
	Pos   Position
	Op    string   // "<", ">", "<=", ">=", "==", "!="
	Value ExprNode // the operand to compare against
}

ComparisonPattern matches a comparison: when < 0, when >= 100

func (*ComparisonPattern) PatternPos

func (p *ComparisonPattern) PatternPos() Position

type ExprNode

type ExprNode interface {
	ExprPos() Position
	// contains filtered or unexported methods
}

ExprNode is the interface for all expression nodes.

type ExprStmt

type ExprStmt struct {
	Pos  Position
	Expr ExprNode
}

ExprStmt wraps an expression used as a statement (typically the last expression in a block acts as the implicit return value).

func (*ExprStmt) StmtPos

func (s *ExprStmt) StmtPos() Position

type FieldAccessExpr

type FieldAccessExpr struct {
	Pos      Position
	Object   ExprNode
	Field    string
	Optional bool // true for ?. (optional chaining)
}

FieldAccessExpr accesses a field on an object: obj.field

func (*FieldAccessExpr) ExprPos

func (e *FieldAccessExpr) ExprPos() Position

type FnAST

type FnAST struct {
	Pos        Position
	Name       string
	Params     []ParamNode
	ReturnType TypeNode
	Body       []StmtNode    // one or more statements
	IsOneLiner bool          // true for => syntax
	TypeDefs   []TypeDefStmt // local type aliases defined before fn
}

FnAST is the root AST node for a DTL function definition.

type FnCallExpr

type FnCallExpr struct {
	Pos  Position
	Name string // can be namespaced: "shared::analytics::anomaly"
	Args []ExprNode
}

FnCallExpr represents a function call: func_name(args)

func (*FnCallExpr) ExprPos

func (e *FnCallExpr) ExprPos() Position

type ForExpr

type ForExpr struct {
	Pos      Position
	Variable string   // loop variable name
	Index    string   // optional index variable (empty if not used)
	Iterable ExprNode // expression yielding an array
	Body     ExprNode // body evaluated per iteration
}

ForExpr represents a for-in expression that maps over a collection: for item in items: item.price * item.quantity for item, idx in items: {index: idx, value: item} Returns an array. Desugars semantically to map().

func (*ForExpr) ExprPos

func (e *ForExpr) ExprPos() Position

type IdentExpr

type IdentExpr struct {
	Pos  Position
	Name string
}

IdentExpr references a variable by name.

func (*IdentExpr) ExprPos

func (e *IdentExpr) ExprPos() Position

type IfExpr

type IfExpr struct {
	Pos       Position
	Condition ExprNode
	Then      ExprNode
	Else      ExprNode // nil if no else branch
}

IfExpr represents a conditional expression: if cond then a else b Else can be another IfExpr for else-if chains.

func (*IfExpr) ExprPos

func (e *IfExpr) ExprPos() Position

type InExpr

type InExpr struct {
	Pos        Position
	Value      ExprNode // left-hand value to test
	Collection ExprNode // right-hand array/object to check membership in
}

InExpr represents a membership test: status in ["active", "pending"]

func (*InExpr) ExprPos

func (e *InExpr) ExprPos() Position

type IndexExpr

type IndexExpr struct {
	Pos    Position
	Object ExprNode
	Index  ExprNode
}

IndexExpr accesses an element by index: arr[0], map["key"]

func (*IndexExpr) ExprPos

func (e *IndexExpr) ExprPos() Position

type InterpolatedStringExpr

type InterpolatedStringExpr struct {
	Pos   Position
	Parts []ExprNode // LiteralExpr (string parts) interspersed with expression nodes
}

InterpolatedStringExpr represents a string with embedded expressions: "hello {name}, temp is {temp | round(1)}" Parts alternate between string literals and evaluated expressions.

func (*InterpolatedStringExpr) ExprPos

func (e *InterpolatedStringExpr) ExprPos() Position

type LambdaExpr

type LambdaExpr struct {
	Pos    Position
	Params []string
	Body   ExprNode
}

LambdaExpr represents an anonymous function: (x, y) => x + y Also used for desugared pipe shorthand: > 0 becomes (x) => x > 0

func (*LambdaExpr) ExprPos

func (e *LambdaExpr) ExprPos() Position

type LetStmt

type LetStmt struct {
	Pos   Position
	Name  string
	Value ExprNode
}

LetStmt represents an immutable variable binding: let x = expr

func (*LetStmt) StmtPos

func (s *LetStmt) StmtPos() Position

type LiteralExpr

type LiteralExpr struct {
	Pos   Position
	Value any    // Go-native value: int64, float64, string, bool, nil
	Type  string // "int", "float", "string", "bool", "null"
}

LiteralExpr represents a literal value: 42, 3.14, "hello", true, null

func (*LiteralExpr) ExprPos

func (e *LiteralExpr) ExprPos() Position

type LiteralPattern

type LiteralPattern struct {
	Pos   Position
	Value any // Go-native literal
}

LiteralPattern matches a single literal value: when "OK", when 42

func (*LiteralPattern) PatternPos

func (p *LiteralPattern) PatternPos() Position

type MatchArm

type MatchArm struct {
	Pos     Position
	Pattern PatternNode
	Body    ExprNode
}

MatchArm pairs a pattern with a result expression.

type MatchExpr

type MatchExpr struct {
	Pos     Position
	Subject ExprNode
	Arms    []MatchArm
}

MatchExpr represents pattern matching: match value: when ...

func (*MatchExpr) ExprPos

func (e *MatchExpr) ExprPos() Position

type ObjectExpr

type ObjectExpr struct {
	Pos    Position
	Fields []ObjectField
}

ObjectExpr constructs an object literal: { key: value, ... } Fields is an ordered slice to preserve insertion order.

func (*ObjectExpr) ExprPos

func (e *ObjectExpr) ExprPos() Position

type ObjectField

type ObjectField struct {
	Key   string
	Value ExprNode
}

ObjectField is a single key-value pair in an object literal.

type ParamNode

type ParamNode struct {
	Pos      Position
	Name     string
	Type     TypeNode
	Default  ExprNode // nil if no default
	Variadic bool     // true for ...name syntax
}

ParamNode describes a single function parameter.

type PatternNode

type PatternNode interface {
	PatternPos() Position
	// contains filtered or unexported methods
}

PatternNode is the interface for match-arm patterns.

type PipeExpr

type PipeExpr struct {
	Pos      Position
	Input    ExprNode
	Function string // function name (may include namespace)
	Args     []ExprNode
}

PipeExpr represents a pipe chain: expr | func(args) The input is implicitly prepended to the function's argument list.

func (*PipeExpr) ExprPos

func (e *PipeExpr) ExprPos() Position

type Position

type Position struct {
	Line   int `json:"line"`
	Column int `json:"column"`
}

Position tracks source location for error reporting.

type QueryExpr

type QueryExpr struct {
	Pos     Position
	Dataset ExprNode   // expression that evaluates to dataset name
	Chain   []PipeExpr // downstream pipe operations (where, select, etc.)
}

QueryExpr represents a dataset query. Two spellings parse to this same node:

  • the `query` keyword form: query("dataset_name")
  • the namespaced sugar: dataset::query("dataset_name")

The chain is populated when the query is piped into operators (where, select, etc.).

func (*QueryExpr) ExprPos

func (e *QueryExpr) ExprPos() Position

type RaiseExpr

type RaiseExpr struct {
	Pos     Position
	Message ExprNode // expression that evaluates to error message
}

RaiseExpr represents a user-defined error: raise "Temperature exceeds limit"

func (*RaiseExpr) ExprPos

func (e *RaiseExpr) ExprPos() Position

type RangePattern

type RangePattern struct {
	Pos  Position
	Low  ExprNode
	High ExprNode
}

RangePattern matches an inclusive range: when 1..10

func (*RangePattern) PatternPos

func (p *RangePattern) PatternPos() Position

type RecordField

type RecordField struct {
	Pos      Position
	Name     string
	Type     TypeNode // recursive — supports nested records
	Optional bool     // true if the field is optional (name?: type)
}

RecordField describes a single field in a record type.

type ReturnStmt

type ReturnStmt struct {
	Pos   Position
	Value ExprNode
}

ReturnStmt represents an explicit return: return expr

func (*ReturnStmt) StmtPos

func (s *ReturnStmt) StmtPos() Position

type StmtNode

type StmtNode interface {
	StmtPos() Position
	// contains filtered or unexported methods
}

StmtNode is the interface for all statement nodes.

type TryExpr

type TryExpr struct {
	Pos     Position
	Expr    ExprNode
	Default ExprNode
}

TryExpr handles errors gracefully: try expr catch default

func (*TryExpr) ExprPos

func (e *TryExpr) ExprPos() Position

type TypeDefStmt

type TypeDefStmt struct {
	Pos  Position
	Name string   // the alias name (e.g. "Person")
	Type TypeNode // the record type definition
}

TypeDefStmt represents a local type alias: type Name = record { ... }

func (*TypeDefStmt) StmtPos

func (s *TypeDefStmt) StmtPos() Position

type TypeNode

type TypeNode struct {
	Pos     Position
	Name    string        // "float", "string", "object", "record", named type, etc.
	IsArray bool          // true if declared as e.g. "float[]"
	Fields  []RecordField // non-nil only when Name == "record" (inline record definition)
}

TypeNode represents a type annotation: "float", "string[]", "record { ... }", etc.

type UnaryExpr

type UnaryExpr struct {
	Pos     Position
	Op      string // "-", "!", "not"
	Operand ExprNode
}

UnaryExpr represents a unary operation: -x, !flag, not flag

func (*UnaryExpr) ExprPos

func (e *UnaryExpr) ExprPos() Position

type UseStmt

type UseStmt struct {
	Pos       Position
	Namespace string // the namespace to import (e.g., "maintenance")
}

UseStmt imports a namespace shortcut: use maintenance → makes app:maintenance:: functions callable without prefix

func (*UseStmt) StmtPos

func (s *UseStmt) StmtPos() Position

type WildcardPattern

type WildcardPattern struct {
	Pos Position
}

WildcardPattern matches anything: when _

func (*WildcardPattern) PatternPos

func (p *WildcardPattern) PatternPos() Position

Jump to

Keyboard shortcuts

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