Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ResolveString
deprecated
added in
v0.1.0
Types ¶
type Token ¶ added in v0.1.0
type Token int
Token represents a lexical token type identified during parsing. Tokens are the basic building blocks used to construct the AST.
const ( TokenInvalid Token = iota // Invalid or unrecognized token TokenVariable // Identifier/variable name (e.g., "foo", "myVar") TokenNumber // Numeric literal (integer or float) TokenStringConstant // String literal delimiter (", ', or `) TokenVariableEnd // End of variable expression: }} // Operators TokenDot // Member access: . TokenAdd // Addition: + TokenSubtract // Subtraction: - TokenMultiply // Multiplication: * TokenDivide // Division: / TokenModulo // Modulo: % TokenEqual // Equality comparison: == TokenDifferent // Inequality comparison: != TokenLess // Less than: < TokenLessEqual // Less than or equal: <= TokenGreater // Greater than: > TokenGreaterEqual // Greater than or equal: >= TokenNot // Logical NOT: ! TokenBitwiseNot // Bitwise NOT: ~ TokenOr // Bitwise OR: | TokenLogicOr // Logical OR: || TokenAnd // Bitwise AND: & TokenLogicAnd // Logical AND: && TokenXor // Bitwise XOR: ^ TokenShiftLeft // Left shift: << TokenShiftRight // Right shift: >> )
Token type constants representing all recognized lexical elements.
func (Token) MathOp ¶ added in v0.1.0
MathOp returns the string representation of a math/logic operator token. Returns an empty string if the token is not a recognized operator.
func (Token) Precedence ¶ added in v0.1.3
Precedence returns the operator precedence for this token. Lower values bind tighter (higher precedence). Returns 0 for non-operator tokens.
type Var ¶ added in v0.1.0
type Var interface {
// Resolve evaluates this variable in the given context and returns its value.
Resolve(context.Context) (any, error)
// IsStatic returns true if the value is constant (does not depend on context).
IsStatic() bool
}
Var is the interface for all resolvable variable expressions. Implementations represent different node types in the expression AST, from simple static values to complex operations.
func ParseString ¶ added in v0.1.0
ParseString parses a string that may contain embedded variable expressions. Variable expressions are delimited by {{ and }}. The mode parameter controls how nested variables are handled:
- "text": variables are resolved to their string representation
- "json": variables are automatically JSON-encoded when embedded
func ParseVariable ¶ added in v0.1.0
ParseVariable parses a variable expression (the content typically found inside {{}}). This handles variable names, operators, and nested expressions directly.