ast

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Lexer = lexer.MustStateful(lexer.Rules{
	"Root": {
		{Name: "Comment", Pattern: `//[^\n]*|#[^\n]*`, Action: nil},
		{Name: "Whitespace", Pattern: `\s+`, Action: nil},
		{Name: "Float", Pattern: `\d+\.\d+`, Action: nil},
		{Name: "Int", Pattern: `\d+`, Action: nil},
		{Name: "String", Pattern: `"(?:\\.|[^"])*"|'(?:\\.|[^'])*'`, Action: nil},
		{Name: "LogicalOp", Pattern: `&&|\|\||!`, Action: nil},
		{Name: "Arrow", Pattern: `->`, Action: nil},
		{Name: "Operator", Pattern: `==|!=|>=|<=|>|<|\+|-|\*|/|%`, Action: nil},
		{Name: "VarRef", Pattern: `\$[a-zA-Z_][a-zA-Z0-9_]*`, Action: nil},
		{Name: "FactPath", Pattern: `[a-zA-Z_][a-zA-Z0-9_]*(?:\.[a-zA-Z_][a-zA-Z0-9_]*|\[\d+\])+`, Action: nil},
		{Name: "Ident", Pattern: `[a-zA-Z_][a-zA-Z0-9_]*`, Action: nil},
		{Name: "Punct", Pattern: `[(),\[\].:?=]`, Action: nil},
		{Name: "Braces", Pattern: `[{}]`, Action: nil},
	},
})

Lexer defines the token rules for parsing Effectus files.

Functions

This section is empty.

Types

type ArgValue

type ArgValue struct {
	Pos      lexer.Position
	VarRef   string          `parser:"  @VarRef"`
	PathExpr *PathExpression `parser:"| @@"`
	Literal  *Literal        `parser:"| @@"`
}

ArgValue represents the value of an argument, which can be a literal, a variable reference, or a fact path

type Effect

type Effect struct {
	Pos      lexer.Position
	BindName string     `parser:"(@Ident '=')?"` // Optional variable binding
	Verb     string     `parser:"@Ident"`
	Args     []*StepArg `parser:"'(' @@? (',' @@)* ')'"`
}

Effect represents a verb and its arguments

type EffectBlock

type EffectBlock struct {
	Pos     lexer.Position
	Effects []*Effect `parser:"@@*"`
}

EffectBlock represents a block of effects

type File

type File struct {
	Pos   lexer.Position
	Rules []*Rule `parser:"@@*"`
	Flows []*Flow `parser:"@@*"`
}

File represents a parsed rule file, containing either Rules or Flows

type Flow

type Flow struct {
	Pos      lexer.Position
	Name     string          `parser:"'flow' @String"`
	Priority int             `parser:"'priority' @Int '{'"`
	When     *PredicateBlock `parser:"'when' '{' @@? '}'"`
	Steps    *StepBlock      `parser:"'steps' '{' @@? '}'"`
	End      string          `parser:"'}'"`
}

Flow represents a flow-style rule (when-steps)

func (*Flow) PostProcess

func (f *Flow) PostProcess()

PostProcess normalizes parsed flow names.

type Literal

type Literal struct {
	Pos    lexer.Position
	String *string     `parser:"@String"`
	Int    *int        `parser:"| @Int"`
	Float  *float64    `parser:"| @Float"`
	Bool   *bool       `parser:"| @('true' | 'false')"`
	List   []Literal   `parser:"| '[' @@* ']'"`
	Map    []*MapEntry `parser:"| '{' @@* '}'"`
}

Literal represents a literal value (string, number, boolean, etc.)

func (*Literal) PostProcess

func (l *Literal) PostProcess()

PostProcess normalizes string literals.

type MapEntry

type MapEntry struct {
	Pos   lexer.Position
	Key   string  `parser:"@Ident ':'"`
	Value Literal `parser:"@@"`
}

MapEntry represents a key-value pair in a map

type PathExpression

type PathExpression struct {
	Path string `parser:"@(FactPath | Ident)"` // The path string
}

PathExpression represents a path in the AST

func (*PathExpression) GetFullPath

func (p *PathExpression) GetFullPath() string

GetFullPath returns the path string

type PathSegmentInfo

type PathSegmentInfo struct {
	Name  string // The segment name
	Index *int   // Optional array index (nil if not indexed)
}

PathSegmentInfo contains information about a segment in a path, including indexing

type PredicateBlock

type PredicateBlock struct {
	Pos        lexer.Position
	Expression string `parser:"@(Ident | Float | Int | String | Operator | LogicalOp | Punct | VarRef | FactPath)+(?=@Braces)"`
}

PredicateBlock represents a block of predicates as a raw expression string

func (*PredicateBlock) GetExpression

func (p *PredicateBlock) GetExpression() string

GetExpression returns the expression string

func (*PredicateBlock) PostProcess

func (p *PredicateBlock) PostProcess()

PostProcess processes the raw expression to create a clean expression string

type Rule

type Rule struct {
	Pos      lexer.Position
	Name     string           `parser:"'rule' @String"`
	Priority int              `parser:"'priority' @Int '{'"`
	Blocks   []*WhenThenBlock `parser:"@@*"`
	End      string           `parser:"'}'"`
}

Rule represents a list-style rule (when-then)

func (*Rule) PostProcess

func (r *Rule) PostProcess()

PostProcess normalizes parsed rule names.

type Step

type Step struct {
	Pos      lexer.Position
	BindName string     `parser:"(@Ident '=')?"` // Optional variable binding
	Verb     string     `parser:"@Ident"`
	Args     []*StepArg `parser:"'(' @@? (',' @@)* ')'"`
	Arrow    string     `parser:"('->' @Ident)?"`
}

Step represents a single step in a flow

type StepArg

type StepArg struct {
	Pos   lexer.Position
	Name  string    `parser:"@Ident ':'"`
	Value *ArgValue `parser:"@@"`
}

StepArg represents an argument to a step or effect

type StepBlock

type StepBlock struct {
	Pos   lexer.Position
	Steps []*Step `parser:"@@*"`
}

StepBlock represents a block of steps

type WhenThenBlock

type WhenThenBlock struct {
	Pos  lexer.Position
	When *PredicateBlock `parser:"'when' '{' @@? '}'"`
	Then *EffectBlock    `parser:"'then' '{' @@? '}'"`
}

WhenThenBlock represents a when-then pair within a rule

Jump to

Keyboard shortcuts

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