ccl

package
v0.2.13 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bind added in v0.2.11

func Bind(n cclNode, colNameMap map[string]int) (cclNode, error)

Bind traverses the AST and resolves column references to indices. It returns a new AST with resolved nodes.

func Evaluate

func Evaluate(n cclNode, ctx Context) (any, error)

Evaluate evaluates a CCL node with the given context.

func GetAssignmentTarget added in v0.2.9

func GetAssignmentTarget(n cclNode) (string, bool)

GetAssignmentTarget returns the target column name/index if the node is an assignment

func GetExpressionNode added in v0.2.11

func GetExpressionNode(n cclNode) cclNode

GetExpressionNode returns the underlying expression node

func GetNewColInfo added in v0.2.9

func GetNewColInfo(n cclNode) (string, cclNode, bool)

GetNewColInfo returns the new column info if the node is a NEW function

func IsAssignmentNode added in v0.2.9

func IsAssignmentNode(n cclNode) bool

IsAssignmentNode checks if the node is an assignment

func IsNewColNode added in v0.2.9

func IsNewColNode(n cclNode) bool

IsNewColNode checks if the node is a NEW column creation

func IsRowDependent added in v0.2.11

func IsRowDependent(n cclNode) bool

IsRowDependent checks if the expression depends on the current row.

func RegisterStandardFunctions added in v0.2.11

func RegisterStandardFunctions()

RegisterStandardFunctions registers the standard library of CCL functions. This includes logical functions (IF, AND, OR), string functions (CONCAT), and aggregate functions (SUM, AVG, COUNT, MAX, MIN).

func ResetEvalDepth

func ResetEvalDepth()

ResetEvalDepth 重置全域評估深度變數

func ResetFuncCallDepth

func ResetFuncCallDepth()

Types

type AggFunc added in v0.2.11

type AggFunc = func(args ...[]any) (any, error)

type CCLNode added in v0.2.9

type CCLNode = cclNode

CCLNode is the exported type alias for compiled CCL AST nodes. This allows external packages to store and reuse compiled formulas.

func CompileExpression added in v0.2.11

func CompileExpression(expression string) (CCLNode, error)

CompileExpression compiles a CCL expression string into an AST. It checks for forbidden syntax (assignment, NEW) for expression mode.

func CompileMultiline added in v0.2.11

func CompileMultiline(script string) ([]CCLNode, error)

CompileMultiline compiles a multi-line CCL script into a list of AST nodes. It splits the script by ';' or newline and compiles each statement individually.

type ColumnRange added in v0.2.11

type ColumnRange struct {
	Start int
	End   int
}

ColumnRange represents a range of column indices [Start, End]

type Context added in v0.2.11

type Context interface {
	// GetCol returns the value of the column at the given index for the current row.
	GetCol(index int) any

	// GetColByName returns the value of the column with the given name for the current row.
	GetColByName(name string) (any, error)

	// GetRowIndex returns the index of the current row.
	GetRowIndex() int

	// GetCurrentRow returns the current row data (e.g., as []any or map).
	// This is used for the @ operator.
	GetCurrentRow() any

	// GetCell returns the value at the specified column index and row index.
	// Used for the . operator (e.g., A.prev).
	GetCell(colIndex, rowIndex int) (any, error)

	// GetCellByName returns the value at the specified column name and row index.
	// Used for the . operator (e.g., 'Col'.prev).
	GetCellByName(colName string, rowIndex int) (any, error)

	// GetRowAt returns the row data at the specified row index.
	// Used for @.prev.
	GetRowAt(rowIndex int) (any, error)

	// GetRowIndexByName returns the index of the row with the given name.
	// Used for row name references in the . operator.
	GetRowIndexByName(rowName string) (int, error)

	// GetColData returns the entire data of the column at the given index.
	// Used for aggregate functions.
	GetColData(index int) ([]any, error)

	// GetColDataByName returns the entire data of the column with the given name.
	// Used for aggregate functions.
	GetColDataByName(name string) ([]any, error)

	// GetColIndexByName returns the index of the column with the given name.
	GetColIndexByName(colName string) (int, error)

	// GetColCount returns the total number of columns in the context.
	GetColCount() int

	// GetRowCount returns the total number of rows in the context.
	GetRowCount() int

	// SetRowIndex sets the current row index for the context.
	// This is used for iterating over rows during aggregation of complex expressions.
	SetRowIndex(index int) error

	// GetAllData returns all data in the context as a single flattened slice.
	// This is used for the @ operator in aggregate functions (e.g., SUM(@)).
	GetAllData() ([]any, error)
}

Context defines the interface for data access in CCL. Implement this interface to allow CCL to operate on your custom data structures.

type EvaluationResult added in v0.2.9

type EvaluationResult struct {
	Value        any    // The computed value (for expressions)
	IsAssignment bool   // Whether this was an assignment
	Target       string // Assignment target column (if IsAssignment)
	IsNewCol     bool   // Whether this creates a new column
	NewColName   string // New column name (if IsNewCol)
}

EvaluationResult represents the result of evaluating a CCL statement

func EvaluateStatement added in v0.2.9

func EvaluateStatement(n cclNode, ctx Context) (*EvaluationResult, error)

EvaluateStatement evaluates a CCL statement and returns detailed result

type Func

type Func = func(args ...any) (any, error)

type MapContext added in v0.2.11

type MapContext struct {
	Data          map[string][]any
	Rows          int
	CurrentRowIdx int
	ColNameMap    map[string]int // Optional: if we want to support index access, we need an order
	ColNames      []string       // To support index access
}

MapContext implements Context for a map of columns (map[string][]any). This allows using CCL with native Go maps and slices.

func NewMapContext added in v0.2.11

func NewMapContext(data map[string][]any) (*MapContext, error)

NewMapContext creates a new MapContext from a map of columns.

func (*MapContext) GetAllData added in v0.2.11

func (c *MapContext) GetAllData() ([]any, error)

func (*MapContext) GetCell added in v0.2.11

func (c *MapContext) GetCell(colIndex, rowIndex int) (any, error)

func (*MapContext) GetCellByName added in v0.2.11

func (c *MapContext) GetCellByName(colName string, rowIndex int) (any, error)

func (*MapContext) GetCol added in v0.2.11

func (c *MapContext) GetCol(index int) any

func (*MapContext) GetColByName added in v0.2.11

func (c *MapContext) GetColByName(name string) (any, error)

func (*MapContext) GetColCount added in v0.2.11

func (c *MapContext) GetColCount() int

func (*MapContext) GetColData added in v0.2.11

func (c *MapContext) GetColData(index int) ([]any, error)

func (*MapContext) GetColDataByName added in v0.2.11

func (c *MapContext) GetColDataByName(name string) ([]any, error)

func (*MapContext) GetColIndexByName added in v0.2.11

func (c *MapContext) GetColIndexByName(colName string) (int, error)

func (*MapContext) GetCurrentRow added in v0.2.11

func (c *MapContext) GetCurrentRow() any

func (*MapContext) GetRowAt added in v0.2.11

func (c *MapContext) GetRowAt(rowIndex int) (any, error)

func (*MapContext) GetRowCount added in v0.2.11

func (c *MapContext) GetRowCount() int

func (*MapContext) GetRowIndex added in v0.2.11

func (c *MapContext) GetRowIndex() int

func (*MapContext) GetRowIndexByName added in v0.2.11

func (c *MapContext) GetRowIndexByName(rowName string) (int, error)

func (*MapContext) SetRowIndex added in v0.2.11

func (c *MapContext) SetRowIndex(index int) error

type RowRange added in v0.2.11

type RowRange struct {
	Start int
	End   int
}

RowRange represents a range of row indices [Start, End]

Jump to

Keyboard shortcuts

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