parser

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Name   string   `json:"name"`
	Params []*Param `json:"params,omitempty"`
	Steps  []*Call  `json:"steps,omitempty"`
}

Action is a named reusable sequence of plugin calls.

type Assertion

type Assertion struct {
	// Expression assertion field
	Expr Expr `json:"expr,omitempty"` // boolean expression (invariants)

	// Path assertion fields
	Expected Expr   `json:"expected,omitempty"` // expected value
	Target   string `json:"target,omitempty"`   // field path or locator name
	Plugin   string `json:"plugin,omitempty"`   // plugin namespace (from @ syntax)
	Property string `json:"property,omitempty"` // assertion property name
}

Assertion is a check. Two forms:

  • Path assertion (then blocks): Target + Expected are set. E.g. "from.balance: 70"
  • Expression assertion (invariants): Expr is set. E.g. "output.from.balance >= 0"

type Assignment

type Assignment struct {
	Value Expr   `json:"value,omitempty"`
	Path  string `json:"path"`
}

Assignment sets a concrete value: field: value

type BinaryOp

type BinaryOp struct {
	Left  Expr   `json:"left,omitempty"`
	Right Expr   `json:"right,omitempty"`
	Op    string `json:"op"` // ==, !=, >, <, >=, <=, +, -, *, &&, ||
}

type Block

type Block struct {
	Assignments []*Assignment `json:"assignments,omitempty"` // concrete values (given blocks)
	Predicates  []Expr        `json:"predicates,omitempty"`  // when-predicate conditions (when blocks)
	Assertions  []*Assertion  `json:"assertions,omitempty"`  // then-block checks
}

Block is a braced section containing assignments, predicates, or assertions.

type Call

type Call struct {
	Namespace string `json:"namespace,omitempty"` // plugin name, empty for local actions
	Method    string `json:"method"`
	Args      []Expr `json:"args,omitempty"`
}

Call is an invocation: plugin.verb(args...) or action(args...)

type Contract

type Contract struct {
	Input  []*Field `json:"input,omitempty"`
	Output []*Field `json:"output,omitempty"`
}

Contract defines the input/output boundary of the system under test.

type EnvRef

type EnvRef struct {
	Var     string `json:"var"`
	Default string `json:"default,omitempty"`

} // env(VAR) or env(VAR, "default")

type Expr

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

Expr is an expression node.

type Field

type Field struct {
	Constraint Expr     `json:"constraint,omitempty"` // optional constraint expression (nil when absent)
	Name       string   `json:"name"`
	Type       TypeExpr `json:"type"`
}

Field is a typed field with an optional constraint.

type FieldRef

type FieldRef struct {
	Path string `json:"path"` // e.g., "input.from.balance", "output.error"
}

type ImportRegistry added in v1.2.0

type ImportRegistry map[string]ImportResolver

ImportRegistry maps adapter names (e.g., "openapi") to their resolvers.

type ImportResolver added in v1.2.0

type ImportResolver interface {
	Resolve(absPath string) ([]*Model, []*Scope, error)
}

ImportResolver converts an external schema file into speclang AST nodes.

type Invariant

type Invariant struct {
	When       Expr         `json:"when,omitempty"` // optional guard predicate (nil when absent)
	Name       string       `json:"name"`
	Assertions []*Assertion `json:"assertions,omitempty"` // body assertions
}

Invariant is a universal property that must hold across all valid inputs.

type LenExpr added in v1.2.0

type LenExpr struct {
	Arg Expr `json:"arg"`
}

type LiteralBool

type LiteralBool struct {
	Value bool `json:"value"`
}

type LiteralFloat added in v1.2.0

type LiteralFloat struct {
	Value float64 `json:"value"`
}

type LiteralInt

type LiteralInt struct {
	Value int `json:"value"`
}

type LiteralNull

type LiteralNull struct{}

type LiteralString

type LiteralString struct {
	Value string `json:"value"`
}

type Model

type Model struct {
	Name   string   `json:"name"`
	Fields []*Field `json:"fields,omitempty"`
}

Model defines a named data structure.

type ObjField

type ObjField struct {
	Value Expr   `json:"value,omitempty"`
	Key   string `json:"key"`
}

type ObjectLiteral

type ObjectLiteral struct {
	Fields []*ObjField `json:"fields,omitempty"` // ordered key-value pairs
}

type Param

type Param struct {
	Name string   `json:"name"`
	Type TypeExpr `json:"type"`
}

Param is a named, typed parameter.

type RegexLiteral

type RegexLiteral struct {
	Pattern string `json:"pattern"`
}

type Scenario

type Scenario struct {
	Given *Block `json:"given,omitempty"` // concrete values
	When  *Block `json:"when,omitempty"`  // predicate block (generative)
	Then  *Block `json:"then,omitempty"`  // assertions
	Name  string `json:"name"`
}

Scenario is a test case -- concrete (given) or generative (when-predicate).

type Scope

type Scope struct {
	Name       string          `json:"name"`
	Config     map[string]Expr `json:"config,omitempty"` // opaque key-value pairs, interpreted by adapter
	Contract   *Contract       `json:"contract,omitempty"`
	Invariants []*Invariant    `json:"invariants,omitempty"`
	Scenarios  []*Scenario     `json:"scenarios,omitempty"`
}

Scope is a named grouping that owns a contract, invariants, and scenarios. The Config block is opaque key-value pairs interpreted by the adapter.

type Spec

type Spec struct {
	Uses        []string          `json:"uses,omitempty"`
	Name        string            `json:"name"`
	Description string            `json:"description,omitempty"`
	Target      *Target           `json:"target,omitempty"`
	Locators    map[string]string `json:"locators,omitempty"`
	Models      []*Model          `json:"models,omitempty"`
	Actions     []*Action         `json:"actions,omitempty"`
	Scopes      []*Scope          `json:"scopes,omitempty"`
}

Spec is the top-level AST node for a parsed spec file.

func Parse

func Parse(source string) (*Spec, error)

Parse parses spec source text into an AST.

func ParseFile

func ParseFile(path string) (*Spec, error)

ParseFile reads a spec file, resolves includes, and returns the AST.

func ParseFileWithImports added in v1.2.0

func ParseFileWithImports(path string, imports ImportRegistry) (*Spec, error)

ParseFileWithImports reads a spec file, resolves includes, and returns the AST. The imports registry maps adapter names to import resolvers for the import directive.

type Target

type Target struct {
	Fields map[string]Expr `json:"fields,omitempty"` // key -> value expression (may be EnvRef, LiteralString, etc.)
}

Target holds configuration for the system under test.

type Token

type Token struct {
	Value string
	Type  TokenType
	File  string
	Line  int
	Col   int
}

Token represents a lexical token.

func Lex

func Lex(source string) ([]Token, error)

Lex tokenizes spec source text.

func (Token) String

func (t Token) String() string

type TokenType

type TokenType int
const (
	// Literals
	TokenIdent TokenType = iota
	TokenInt
	TokenFloat
	TokenString
	TokenBool

	// Keywords
	TokenUse
	TokenSpec
	TokenModel
	TokenContract
	TokenInput
	TokenOutput
	TokenAction
	TokenInvariant
	TokenScenario
	TokenGiven
	TokenWhen
	TokenThen
	TokenTarget
	TokenLocators
	TokenPlugin
	TokenNull
	TokenScope
	TokenConfig
	TokenEnv
	TokenInclude
	TokenImport

	// Symbols
	TokenLBrace   // {
	TokenRBrace   // }
	TokenLParen   // (
	TokenRParen   // )
	TokenLBracket // [
	TokenRBracket // ]
	TokenColon    // :
	TokenComma    // ,
	TokenDot      // .
	TokenAt       // @
	TokenQuestion // ?

	// Operators
	TokenEq     // ==
	TokenNeq    // !=
	TokenGt     // >
	TokenLt     // <
	TokenGte    // >=
	TokenLte    // <=
	TokenPlus   // +
	TokenMinus  // -
	TokenStar   // *
	TokenAnd    // &&
	TokenOr     // ||
	TokenNot    // !
	TokenAssign // =

	// Special
	TokenComment
	TokenEOF
)

func (TokenType) String

func (t TokenType) String() string

type TypeExpr

type TypeExpr struct {
	Name     string    `json:"name"`                // "int", "string", "bool", "float", "bytes", "array", "map", or model name
	ElemType *TypeExpr `json:"elem_type,omitempty"` // element type for arrays
	KeyType  *TypeExpr `json:"key_type,omitempty"`  // key type for maps
	ValType  *TypeExpr `json:"val_type,omitempty"`  // value type for maps
	Optional bool      `json:"optional,omitempty"`  // trailing ?
}

TypeExpr represents a type in the spec language.

type UnaryOp

type UnaryOp struct {
	Operand Expr   `json:"operand,omitempty"`
	Op      string `json:"op"` // !, -
}

Jump to

Keyboard shortcuts

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