compiler

package
v0.9.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SourceError added in v0.8.0

func SourceError(pos Position, format string, args ...any) error

SourceError formats a parse- or compile-time error with a source position. Every message has the shape "file:line:col: msg", the same convention used by go/parser and gopls, so editors and human readers both get the familiar format.

The error kind is BadRequest, which every transport in the Nexss ecosystem maps to HTTP 400 without further inspection.

Types

type AssertExpr added in v0.8.0

type AssertExpr struct {
	Condition string
	Message   string
}

type AtomExpr

type AtomExpr struct {
	Name      string
	Profile   string
	Prompt    string
	Targets   []string
	Excludes  []string
	Params    map[string]string // from (key=value) — literal strings
	Inputs    map[string]string // from (key=value) where value has a dot
	Args      map[string]*Value // from @{ key: value } — typed
	Modifiers []string
}

AtomExpr is a single action reference in the pipeline.

Modifiers come from the `:key=value` syntax. Params and Inputs come from the older `(key=value, ...)` syntax and remain for backward compatibility. Args come from `@{ key: value }` and carry full typed structure (see Value).

type ConditionalExpr

type ConditionalExpr struct {
	Gate   Expr
	Target Expr
	Else   Expr
}

ConditionalExpr is `gate ? target` or `gate ? target : else`. Else is nil in the two-arm form.

type Expr

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

type FallbackExpr

type FallbackExpr struct {
	Left  Expr
	Right Expr
}

type Lexer

type Lexer struct {
	// contains filtered or unexported fields
}

func NewLexer

func NewLexer(input string) *Lexer

func (*Lexer) Next

func (l *Lexer) Next() Token

type LoopExpr

type LoopExpr struct {
	Body  Expr
	Until string
}

type MapEntry added in v0.8.0

type MapEntry struct {
	Key   string
	Value *Value
}

MapEntry is one key-value pair inside a nested map.

type NeedsPipelineError added in v0.8.0

type NeedsPipelineError struct {
	Reason string
}

NeedsPipelineError is returned by ParseArrowDSL when the AST contains a construct the static DAG model cannot represent.

The three constructs that trigger it are loop(), conditional (? :), and fallback (||). They are runtime compositions, not graph topology: a DAG is by definition acyclic and cannot encode an unbounded loop, a data-dependent branch, or a try-then-else chain. CompilePipeline handles all three by composing actions, so callers that can execute a composed action should detect this error and fall back.

Callers should use errors.As to test for this type:

var npe *compiler.NeedsPipelineError
if errors.As(err, &npe) {
    // fall back to CompilePipeline
}

func (*NeedsPipelineError) Error added in v0.8.0

func (e *NeedsPipelineError) Error() string

type Node

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

type ParallelExpr

type ParallelExpr struct {
	Children []Expr
}

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser walks the token stream produced by Lexer and builds an AST.

The parser is split across four files:

parser.go              — Parser struct, token advance, entry points
parser_precedence.go   — the operator precedence chain
parser_atom.go         — atoms, modifiers, ternary-colon detection
parser_blocks.go       — brace / paren / bracket scanning, projections,
                         loops, asserts

The split mirrors the grammar: each file owns one level of the language.

func NewParser

func NewParser(input string) *Parser

func NewParserWithFile added in v0.8.0

func NewParserWithFile(input, file string) *Parser

func (*Parser) ParseExpression

func (p *Parser) ParseExpression() (Expr, error)

ParseExpression parses a complete pipeline expression and requires that the token stream is exhausted when it returns.

type PipelineExpr

type PipelineExpr struct {
	Left  Expr
	Right Expr
}

type Position added in v0.8.0

type Position struct {
	File string
	Line int
	Col  int
}

Position identifies a source location inside a .nflow file. It is the lowest-level error-position type in the flow stack; higher layers (flow, runner) re-export it so callers do not need to import compiler directly.

func (Position) String added in v0.8.0

func (p Position) String() string

String renders the position as "path/to/file.nflow:12:5". An empty File is rendered as "<input>" so test fixtures and in-memory DSL strings still produce a usable location.

type ProjectionExpr

type ProjectionExpr struct {
	Raw string
}

type Token

type Token struct {
	Type   TokenType
	Lit    string
	Line   int
	Col    int
	Offset int
}

type TokenType

type TokenType int
const (
	TokenEOF TokenType = iota
	TokenIdent
	TokenString
	TokenNumber
	TokenArrow
	TokenPipe
	TokenOr
	TokenAmpersand
	TokenLParen
	TokenRParen
	TokenLBrace
	TokenRBrace
	TokenQuestion
	TokenColon
	TokenAssign
	TokenAtPrompt // @text  — free-form prompt annotation
	TokenAtBrace  // @{...} — structural inline arguments
	TokenHash
	TokenTilde
	TokenComma
	TokenLBracket // [
	TokenRBracket // ]
	TokenInvalid
)

func (TokenType) String

func (t TokenType) String() string

type Value added in v0.8.0

type Value struct {
	Kind  ValueKind
	Str   string     // ValueString
	Num   float64    // ValueNumber
	Bool  bool       // ValueBool
	Ref   string     // ValueRef: "user.name" (leading dot stripped)
	Map   []MapEntry // ValueMap: ordered, so error messages and diffs are stable
	Slice []*Value   // ValueSlice
}

Value is a typed value inside an @{} block. It is the compile-time representation of a DSL argument: at execution the parser resolves it into a concrete Go value (string, float64, bool, map[string]any, []any, or a reference looked up in the pipeline state).

func (*Value) IsWholeStateRef added in v0.8.0

func (v *Value) IsWholeStateRef() bool

IsWholeStateRef reports whether this value is a bare "." reference, meaning "the entire state as it arrived". The compiler treats this specially: it snapshots the state before injecting other args, so the reference never captures a self-modifying map.

type ValueKind added in v0.8.0

type ValueKind uint8

ValueKind identifies the type of a parsed @{} argument.

const (
	ValueString ValueKind = iota
	ValueNumber
	ValueBool
	ValueNull
	ValueRef   // .foo.bar  → Ref = "foo.bar"
	ValueMap   // { key: value, ... }
	ValueSlice // [ a, b, c ]
)

Jump to

Keyboard shortcuts

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