parser

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReleaseAST

func ReleaseAST(node Node)

ReleaseAST recursively releases all pooled nodes in an AST back to their pools. This should be called when a template is no longer needed to enable node reuse. Non-pooled node types are ignored and will be garbage collected normally.

func ReleaseAttributeNode

func ReleaseAttributeNode(n *AttributeNode)

ReleaseAttributeNode returns an AttributeNode to the pool

func ReleaseBinaryOpNode

func ReleaseBinaryOpNode(n *BinaryOpNode)

ReleaseBinaryOpNode returns a BinaryOpNode to the pool

func ReleaseCallNode

func ReleaseCallNode(n *CallNode)

ReleaseCallNode returns a CallNode to the pool

func ReleaseFilterNode

func ReleaseFilterNode(n *FilterNode)

ReleaseFilterNode returns a FilterNode to the pool

func ReleaseGetItemNode

func ReleaseGetItemNode(n *GetItemNode)

ReleaseGetItemNode returns a GetItemNode to the pool

func ReleaseIdentifierNode

func ReleaseIdentifierNode(n *IdentifierNode)

ReleaseIdentifierNode returns an IdentifierNode to the pool

func ReleaseLiteralNode

func ReleaseLiteralNode(n *LiteralNode)

ReleaseLiteralNode returns a LiteralNode to the pool

func ReleaseNode

func ReleaseNode(node Node)

ReleaseNode releases a node back to its appropriate pool. This is a convenience function that handles type dispatching. For complex ASTs, use ReleaseAST which recursively releases all nodes.

func ReleaseUnaryOpNode

func ReleaseUnaryOpNode(n *UnaryOpNode)

ReleaseUnaryOpNode returns a UnaryOpNode to the pool

Types

type AssignmentNode

type AssignmentNode struct {
	Target ExpressionNode // Can be identifier or attribute/item access
	Value  ExpressionNode
	// contains filtered or unexported fields
}

AssignmentNode represents assignment expressions (set a = b)

func NewAssignmentNode

func NewAssignmentNode(target, value ExpressionNode, line, column int) *AssignmentNode

func (*AssignmentNode) Column

func (n *AssignmentNode) Column() int

func (*AssignmentNode) ExpressionNode

func (n *AssignmentNode) ExpressionNode()

func (*AssignmentNode) Line

func (n *AssignmentNode) Line() int

func (*AssignmentNode) String

func (n *AssignmentNode) String() string

type AttributeNode

type AttributeNode struct {
	Object    ExpressionNode
	Attribute string
	// contains filtered or unexported fields
}

AttributeNode represents attribute access (obj.attr)

func AcquireAttributeNode

func AcquireAttributeNode(obj ExpressionNode, attr string, line, column int) *AttributeNode

AcquireAttributeNode gets an AttributeNode from the pool

func NewAttributeNode

func NewAttributeNode(obj ExpressionNode, attr string, line, column int) *AttributeNode

func (*AttributeNode) Column

func (n *AttributeNode) Column() int

func (*AttributeNode) ExpressionNode

func (n *AttributeNode) ExpressionNode()

func (*AttributeNode) Line

func (n *AttributeNode) Line() int

func (*AttributeNode) String

func (n *AttributeNode) String() string

type AutoescapeNode

type AutoescapeNode struct {
	Enabled bool // true for autoescape on, false for off
	Body    []Node
	// contains filtered or unexported fields
}

AutoescapeNode represents autoescape blocks {% autoescape true %}...{% endautoescape %}

func NewAutoescapeNode

func NewAutoescapeNode(enabled bool, line, column int) *AutoescapeNode

func (*AutoescapeNode) Column

func (n *AutoescapeNode) Column() int

func (*AutoescapeNode) Line

func (n *AutoescapeNode) Line() int

func (*AutoescapeNode) StatementNode

func (n *AutoescapeNode) StatementNode()

func (*AutoescapeNode) String

func (n *AutoescapeNode) String() string

type BaseNode

type BaseNode struct {
	Line   int
	Column int
}

BaseNode is the exported version of baseNode for extensions

type BinaryOpNode

type BinaryOpNode struct {
	Left     ExpressionNode
	Operator string
	Right    ExpressionNode
	// contains filtered or unexported fields
}

BinaryOpNode represents binary operations (a + b, a > b, etc.)

func AcquireBinaryOpNode

func AcquireBinaryOpNode(left ExpressionNode, op string, right ExpressionNode, line, column int) *BinaryOpNode

AcquireBinaryOpNode gets a BinaryOpNode from the pool

func NewBinaryOpNode

func NewBinaryOpNode(left ExpressionNode, op string, right ExpressionNode, line, column int) *BinaryOpNode

func (*BinaryOpNode) Column

func (n *BinaryOpNode) Column() int

func (*BinaryOpNode) ExpressionNode

func (n *BinaryOpNode) ExpressionNode()

func (*BinaryOpNode) Line

func (n *BinaryOpNode) Line() int

func (*BinaryOpNode) String

func (n *BinaryOpNode) String() string

type BlockNode

type BlockNode struct {
	Name string
	Body []Node
	// contains filtered or unexported fields
}

BlockNode represents template blocks

func NewBlockNode

func NewBlockNode(name string, line, column int) *BlockNode

func (*BlockNode) Column

func (n *BlockNode) Column() int

func (*BlockNode) Line

func (n *BlockNode) Line() int

func (*BlockNode) StatementNode

func (n *BlockNode) StatementNode()

func (*BlockNode) String

func (n *BlockNode) String() string

type BlockSetNode

type BlockSetNode struct {
	Variable string
	Body     []Node // The content between {% set var %} and {% endset %}
	// contains filtered or unexported fields
}

BlockSetNode represents block assignment ({% set var %}content{% endset %})

func NewBlockSetNode

func NewBlockSetNode(variable string, body []Node, line, column int) *BlockSetNode

func (*BlockSetNode) Column

func (n *BlockSetNode) Column() int

func (*BlockSetNode) Line

func (n *BlockSetNode) Line() int

func (*BlockSetNode) StatementNode

func (n *BlockSetNode) StatementNode()

func (*BlockSetNode) String

func (n *BlockSetNode) String() string

type BreakNode

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

BreakNode represents break statements in loops

func NewBreakNode

func NewBreakNode(line, column int) *BreakNode

func (*BreakNode) Column

func (n *BreakNode) Column() int

func (*BreakNode) Line

func (n *BreakNode) Line() int

func (*BreakNode) StatementNode

func (n *BreakNode) StatementNode()

func (*BreakNode) String

func (n *BreakNode) String() string

type CallBlockNode

type CallBlockNode struct {
	Call ExpressionNode // The function/macro call
	Body []Node         // The content between {% call %} and {% endcall %}
	// contains filtered or unexported fields
}

CallBlockNode represents call blocks {% call macro_name() %}content{% endcall %}

func NewCallBlockNode

func NewCallBlockNode(call ExpressionNode, body []Node, line, column int) *CallBlockNode

func (*CallBlockNode) Column

func (n *CallBlockNode) Column() int

func (*CallBlockNode) Line

func (n *CallBlockNode) Line() int

func (*CallBlockNode) StatementNode

func (n *CallBlockNode) StatementNode()

func (*CallBlockNode) String

func (n *CallBlockNode) String() string

type CallNode

type CallNode struct {
	Function  ExpressionNode
	Arguments []ExpressionNode
	Keywords  map[string]ExpressionNode
	// contains filtered or unexported fields
}

CallNode represents function/macro calls

func AcquireCallNode

func AcquireCallNode(function ExpressionNode, line, column int) *CallNode

AcquireCallNode gets a CallNode from the pool

func NewCallNode

func NewCallNode(function ExpressionNode, line, column int) *CallNode

func (*CallNode) Column

func (n *CallNode) Column() int

func (*CallNode) ExpressionNode

func (n *CallNode) ExpressionNode()

func (*CallNode) Line

func (n *CallNode) Line() int

func (*CallNode) String

func (n *CallNode) String() string

type CommentNode

type CommentNode struct {
	Content string
	// contains filtered or unexported fields
}

CommentNode represents template comments {# comment #}

func NewCommentNode

func NewCommentNode(content string, line, column int) *CommentNode

func (*CommentNode) Column

func (n *CommentNode) Column() int

func (*CommentNode) FastEval

func (n *CommentNode) FastEval(e interface{}, ctx interface{}) (interface{}, error)

FastEval for CommentNode - returns empty string

func (*CommentNode) Line

func (n *CommentNode) Line() int

func (*CommentNode) String

func (n *CommentNode) String() string

type ComprehensionNode

type ComprehensionNode struct {
	Expression ExpressionNode
	Variable   string
	Iterable   ExpressionNode
	Condition  ExpressionNode // optional filter condition
	IsDict     bool           // true for dict comprehensions
	KeyExpr    ExpressionNode // for dict comprehensions
	// contains filtered or unexported fields
}

ComprehensionNode represents list/dict comprehensions

func NewComprehensionNode

func NewComprehensionNode(expr ExpressionNode, variable string, iterable ExpressionNode, line, column int) *ComprehensionNode

func (*ComprehensionNode) Column

func (n *ComprehensionNode) Column() int

func (*ComprehensionNode) ExpressionNode

func (n *ComprehensionNode) ExpressionNode()

func (*ComprehensionNode) Line

func (n *ComprehensionNode) Line() int

func (*ComprehensionNode) String

func (n *ComprehensionNode) String() string

type ConditionalNode

type ConditionalNode struct {
	Condition ExpressionNode
	TrueExpr  ExpressionNode
	FalseExpr ExpressionNode
	// contains filtered or unexported fields
}

ConditionalNode represents ternary conditional expressions (condition ? true_expr : false_expr)

func NewConditionalNode

func NewConditionalNode(condition, trueExpr, falseExpr ExpressionNode, line, column int) *ConditionalNode

func (*ConditionalNode) Column

func (n *ConditionalNode) Column() int

func (*ConditionalNode) ExpressionNode

func (n *ConditionalNode) ExpressionNode()

func (*ConditionalNode) Line

func (n *ConditionalNode) Line() int

func (*ConditionalNode) String

func (n *ConditionalNode) String() string

type ContinueNode

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

ContinueNode represents continue statements in loops

func NewContinueNode

func NewContinueNode(line, column int) *ContinueNode

func (*ContinueNode) Column

func (n *ContinueNode) Column() int

func (*ContinueNode) Line

func (n *ContinueNode) Line() int

func (*ContinueNode) StatementNode

func (n *ContinueNode) StatementNode()

func (*ContinueNode) String

func (n *ContinueNode) String() string

type DoNode

type DoNode struct {
	Expression ExpressionNode
	// contains filtered or unexported fields
}

DoNode represents a do statement that executes an expression for side effects only

func NewDoNode

func NewDoNode(expr ExpressionNode, line, column int) *DoNode

func (*DoNode) Column

func (n *DoNode) Column() int

func (*DoNode) Line

func (n *DoNode) Line() int

func (*DoNode) StatementNode

func (n *DoNode) StatementNode()

func (*DoNode) String

func (n *DoNode) String() string

type ExpressionNode

type ExpressionNode interface {
	Node
	ExpressionNode()
}

ExpressionNode represents various expressions

type ExtendsNode

type ExtendsNode struct {
	Template ExpressionNode
	// contains filtered or unexported fields
}

ExtendsNode represents template inheritance

func NewExtendsNode

func NewExtendsNode(template ExpressionNode, line, column int) *ExtendsNode

func (*ExtendsNode) Column

func (n *ExtendsNode) Column() int

func (*ExtendsNode) Line

func (n *ExtendsNode) Line() int

func (*ExtendsNode) StatementNode

func (n *ExtendsNode) StatementNode()

func (*ExtendsNode) String

func (n *ExtendsNode) String() string

type ExtensionNode

type ExtensionNode struct {
	ExtensionName string
	TagName       string
	Arguments     []ExpressionNode
	Body          []Node
	Properties    map[string]interface{}
	EvaluateFunc  func(node *ExtensionNode, ctx interface{}) (interface{}, error)
	// contains filtered or unexported fields
}

ExtensionNode represents a custom tag node in the AST

func NewExtensionNode

func NewExtensionNode(extensionName, tagName string, line, column int) *ExtensionNode

func (*ExtensionNode) AddArgument

func (n *ExtensionNode) AddArgument(arg ExpressionNode)

AddArgument adds an argument to the extension node

func (*ExtensionNode) AddBodyNode

func (n *ExtensionNode) AddBodyNode(node Node)

AddBodyNode adds a node to the body

func (*ExtensionNode) Column

func (n *ExtensionNode) Column() int

func (*ExtensionNode) Evaluate

func (n *ExtensionNode) Evaluate(ctx interface{}) (interface{}, error)

Evaluate evaluates the extension node with the given context

func (*ExtensionNode) GetProperty

func (n *ExtensionNode) GetProperty(key string) (interface{}, bool)

GetProperty gets a custom property

func (*ExtensionNode) Line

func (n *ExtensionNode) Line() int

func (*ExtensionNode) SetEvaluateFunc

func (n *ExtensionNode) SetEvaluateFunc(fn func(*ExtensionNode, interface{}) (interface{}, error))

SetEvaluateFunc sets the evaluation function

func (*ExtensionNode) SetProperty

func (n *ExtensionNode) SetProperty(key string, value interface{})

SetProperty sets a custom property

func (*ExtensionNode) StatementNode

func (n *ExtensionNode) StatementNode()

func (*ExtensionNode) String

func (n *ExtensionNode) String() string

type FastEvaluator

type FastEvaluator interface {
	SetUndefinedBehavior(behavior interface{})
	SetImportSystem(importSystem interface{})
}

FastEvalNode interface is defined in runtime package to avoid circular dependencies We use a local type alias here for convenience

type FilterBlockNode

type FilterBlockNode struct {
	FilterChain []FilterNode // Chain of filters to apply
	Body        []Node       // Template content to filter
	// contains filtered or unexported fields
}

FilterBlockNode represents filter blocks {% filter upper %}...{% endfilter %}

func NewFilterBlockNode

func NewFilterBlockNode(filterChain []FilterNode, line, column int) *FilterBlockNode

func (*FilterBlockNode) Column

func (n *FilterBlockNode) Column() int

func (*FilterBlockNode) Line

func (n *FilterBlockNode) Line() int

func (*FilterBlockNode) StatementNode

func (n *FilterBlockNode) StatementNode()

func (*FilterBlockNode) String

func (n *FilterBlockNode) String() string

type FilterNode

type FilterNode struct {
	Expression ExpressionNode
	FilterName string
	Arguments  []ExpressionNode
	NamedArgs  map[string]ExpressionNode
	// contains filtered or unexported fields
}

FilterNode represents filter application (value|filter)

func AcquireFilterNode

func AcquireFilterNode(expr ExpressionNode, filterName string, args []ExpressionNode, line, column int) *FilterNode

AcquireFilterNode gets a FilterNode from the pool

func NewFilterNode

func NewFilterNode(expr ExpressionNode, filterName string, args []ExpressionNode, line, column int) *FilterNode

func (*FilterNode) Column

func (n *FilterNode) Column() int

func (*FilterNode) ExpressionNode

func (n *FilterNode) ExpressionNode()

func (*FilterNode) Line

func (n *FilterNode) Line() int

func (*FilterNode) String

func (n *FilterNode) String() string

type ForNode

type ForNode struct {
	Variables []string // Support multiple variables for unpacking
	Iterable  ExpressionNode
	Condition ExpressionNode // Optional conditional for filtered iteration
	Body      []Node
	Else      []Node
	Recursive bool
	// contains filtered or unexported fields
}

ForNode represents for loops

func NewForNode

func NewForNode(variables []string, iterable ExpressionNode, line, column int) *ForNode

func NewSingleForNode

func NewSingleForNode(variable string, iterable ExpressionNode, line, column int) *ForNode

NewSingleForNode creates a for node with a single variable (backward compatibility)

func (*ForNode) Column

func (n *ForNode) Column() int

func (*ForNode) Line

func (n *ForNode) Line() int

func (*ForNode) StatementNode

func (n *ForNode) StatementNode()

func (*ForNode) String

func (n *ForNode) String() string

type FromNode

type FromNode struct {
	Template ExpressionNode    // The template to import from
	Names    []string          // The names to import
	Aliases  map[string]string // Optional aliases for imported names (name -> alias)
	// contains filtered or unexported fields
}

FromNode represents from-import statements ({% from 'template.html' import item1, item2 %})

func NewFromNode

func NewFromNode(line, column int, template ExpressionNode, names []string, aliases map[string]string) *FromNode

func (*FromNode) Column

func (n *FromNode) Column() int

func (*FromNode) Line

func (n *FromNode) Line() int

func (*FromNode) StatementNode

func (n *FromNode) StatementNode()

func (*FromNode) String

func (n *FromNode) String() string

type GetItemNode

type GetItemNode struct {
	Object ExpressionNode
	Key    ExpressionNode
	// contains filtered or unexported fields
}

GetItemNode represents item access (obj[key])

func AcquireGetItemNode

func AcquireGetItemNode(obj, key ExpressionNode, line, column int) *GetItemNode

AcquireGetItemNode gets a GetItemNode from the pool

func NewGetItemNode

func NewGetItemNode(obj, key ExpressionNode, line, column int) *GetItemNode

func (*GetItemNode) Column

func (n *GetItemNode) Column() int

func (*GetItemNode) ExpressionNode

func (n *GetItemNode) ExpressionNode()

func (*GetItemNode) Line

func (n *GetItemNode) Line() int

func (*GetItemNode) String

func (n *GetItemNode) String() string

type IdentifierNode

type IdentifierNode struct {
	Name string
	// contains filtered or unexported fields
}

IdentifierNode represents variable names and identifiers

func AcquireIdentifierNode

func AcquireIdentifierNode(name string, line, column int) *IdentifierNode

AcquireIdentifierNode gets an IdentifierNode from the pool

func NewIdentifierNode

func NewIdentifierNode(name string, line, column int) *IdentifierNode

func (*IdentifierNode) Column

func (n *IdentifierNode) Column() int

func (*IdentifierNode) ExpressionNode

func (n *IdentifierNode) ExpressionNode()

func (*IdentifierNode) Line

func (n *IdentifierNode) Line() int

func (*IdentifierNode) String

func (n *IdentifierNode) String() string

type IfNode

type IfNode struct {
	Condition ExpressionNode
	Body      []Node
	ElseIfs   []*IfNode
	Else      []Node
	// contains filtered or unexported fields
}

IfNode represents if/elif/else statements

func NewIfNode

func NewIfNode(condition ExpressionNode, line, column int) *IfNode

func (*IfNode) Column

func (n *IfNode) Column() int

func (*IfNode) Line

func (n *IfNode) Line() int

func (*IfNode) StatementNode

func (n *IfNode) StatementNode()

func (*IfNode) String

func (n *IfNode) String() string

type ImportNode

type ImportNode struct {
	Template ExpressionNode // The template to import
	Alias    string         // The alias name for the imported template
	// contains filtered or unexported fields
}

ImportNode represents import statements ({% import 'template.html' as name %})

func NewImportNode

func NewImportNode(line, column int, template ExpressionNode, alias string) *ImportNode

func (*ImportNode) Column

func (n *ImportNode) Column() int

func (*ImportNode) Line

func (n *ImportNode) Line() int

func (*ImportNode) StatementNode

func (n *ImportNode) StatementNode()

func (*ImportNode) String

func (n *ImportNode) String() string

type IncludeNode

type IncludeNode struct {
	Template      ExpressionNode
	Context       ExpressionNode // optional
	IgnoreMissing bool
	// contains filtered or unexported fields
}

IncludeNode represents template inclusion

func NewIncludeNode

func NewIncludeNode(template ExpressionNode, line, column int) *IncludeNode

func (*IncludeNode) Column

func (n *IncludeNode) Column() int

func (*IncludeNode) Line

func (n *IncludeNode) Line() int

func (*IncludeNode) StatementNode

func (n *IncludeNode) StatementNode()

func (*IncludeNode) String

func (n *IncludeNode) String() string

type ListNode

type ListNode struct {
	Elements []ExpressionNode
	// contains filtered or unexported fields
}

ListNode represents list literals [1, 2, 3]

func NewListNode

func NewListNode(elements []ExpressionNode, line, column int) *ListNode

func (*ListNode) Column

func (n *ListNode) Column() int

func (*ListNode) ExpressionNode

func (n *ListNode) ExpressionNode()

func (*ListNode) Line

func (n *ListNode) Line() int

func (*ListNode) String

func (n *ListNode) String() string

type LiteralNode

type LiteralNode struct {
	Value interface{}
	Raw   string
	// contains filtered or unexported fields
}

LiteralNode represents literal values (strings, numbers, booleans)

func AcquireLiteralNode

func AcquireLiteralNode(value interface{}, raw string, line, column int) *LiteralNode

AcquireLiteralNode gets a LiteralNode from the pool

func NewLiteralNode

func NewLiteralNode(value interface{}, raw string, line, column int) *LiteralNode

func (*LiteralNode) Column

func (n *LiteralNode) Column() int

func (*LiteralNode) ExpressionNode

func (n *LiteralNode) ExpressionNode()

func (*LiteralNode) FastEval

func (n *LiteralNode) FastEval(e interface{}, ctx interface{}) (interface{}, error)

FastEval for LiteralNode - direct value return

func (*LiteralNode) Line

func (n *LiteralNode) Line() int

func (*LiteralNode) String

func (n *LiteralNode) String() string

type MacroNode

type MacroNode struct {
	Name       string
	Parameters []string
	Defaults   map[string]ExpressionNode
	Body       []Node
	// contains filtered or unexported fields
}

MacroNode represents macro definitions

func NewMacroNode

func NewMacroNode(name string, line, column int) *MacroNode

func (*MacroNode) Column

func (n *MacroNode) Column() int

func (*MacroNode) Line

func (n *MacroNode) Line() int

func (*MacroNode) StatementNode

func (n *MacroNode) StatementNode()

func (*MacroNode) String

func (n *MacroNode) String() string

type Node

type Node interface {
	String() string
	Line() int
	Column() int
}

type NodePoolStats

type NodePoolStats struct {
	LiteralNodes    int
	IdentifierNodes int
	BinaryOpNodes   int
	FilterNodes     int
	UnaryOpNodes    int
	AttributeNodes  int
	GetItemNodes    int
	CallNodes       int
}

NodePoolStats returns statistics about node pool usage. This is useful for debugging and performance tuning.

func GetNodePoolStats

func GetNodePoolStats() NodePoolStats

Note: sync.Pool doesn't expose internal statistics, so this function is a placeholder for future instrumentation. For now, pool effectiveness should be measured via benchmarks.

type Parser

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

Parser parses tokens into an AST

func NewParser

func NewParser(tokens []*lexer.Token) *Parser

NewParser creates a new parser with the given tokens

func (*Parser) Advance

func (p *Parser) Advance() *lexer.Token

Advance exposes the advance method for extensions

func (*Parser) Check

func (p *Parser) Check(tokenType lexer.TokenType) bool

Check exposes the check method for extensions

func (*Parser) CheckAny

func (p *Parser) CheckAny(types ...lexer.TokenType) bool

CheckAny exposes the checkAny method for extensions

func (*Parser) ErrorPublic

func (p *Parser) ErrorPublic(message string) error

ErrorPublic exposes the error method for extensions

func (*Parser) GetCurrentPosition

func (p *Parser) GetCurrentPosition() int

GetCurrentPosition returns the current parser position for extensions

func (*Parser) GetErrors

func (p *Parser) GetErrors() []string

GetErrors returns any errors encountered during parsing

func (*Parser) GetTokens

func (p *Parser) GetTokens() []*lexer.Token

GetTokens returns the token slice for extensions

func (*Parser) IsAtEnd

func (p *Parser) IsAtEnd() bool

IsAtEnd exposes the isAtEnd method for extensions

func (*Parser) Parse

func (p *Parser) Parse() (*TemplateNode, error)

Parse parses the tokens into a template AST

func (*Parser) ParseBlockStatementPublic

func (p *Parser) ParseBlockStatementPublic() (Node, error)

ParseBlockStatementPublic exposes parseBlockStatement for extensions

func (*Parser) ParseExpressionPublic

func (p *Parser) ParseExpressionPublic() (ExpressionNode, error)

ParseExpressionPublic exposes parseExpression for extensions

func (*Parser) ParseTopLevelPublic

func (p *Parser) ParseTopLevelPublic() (Node, error)

ParseTopLevelPublic exposes parseTopLevel for extensions

func (*Parser) Peek

func (p *Parser) Peek() *lexer.Token

Additional public methods for extension parser support Peek exposes the peek method for extensions

func (*Parser) PeekBlockTypePublic

func (p *Parser) PeekBlockTypePublic() lexer.TokenType

PeekBlockTypePublic exposes peekBlockType for extensions

func (*Parser) SetCurrentPosition

func (p *Parser) SetCurrentPosition(pos int)

SetCurrentPosition sets the current parser position for extensions

type RawNode

type RawNode struct {
	Content string
	// contains filtered or unexported fields
}

RawNode represents raw blocks {% raw %}...{% endraw %}

func NewRawNode

func NewRawNode(content string, line, column int) *RawNode

func (*RawNode) Column

func (n *RawNode) Column() int

func (*RawNode) FastEval

func (n *RawNode) FastEval(e interface{}, ctx interface{}) (interface{}, error)

FastEval for RawNode - returns content as-is

func (*RawNode) Line

func (n *RawNode) Line() int

func (*RawNode) String

func (n *RawNode) String() string

type SetNode

type SetNode struct {
	Targets []ExpressionNode // Support multiple targets for tuple unpacking (can be identifiers or attributes)
	Value   ExpressionNode   // The value expression to assign
	// contains filtered or unexported fields
}

SetNode represents variable assignment (supports both single and multiple assignment)

func NewMultiSetNode

func NewMultiSetNode(variables []string, value ExpressionNode, line, column int) *SetNode

func NewSetNode

func NewSetNode(variable string, value ExpressionNode, line, column int) *SetNode

func NewSetNodeWithTargets

func NewSetNodeWithTargets(targets []ExpressionNode, value ExpressionNode, line, column int) *SetNode

func (*SetNode) Column

func (n *SetNode) Column() int

func (*SetNode) Line

func (n *SetNode) Line() int

func (*SetNode) StatementNode

func (n *SetNode) StatementNode()

func (*SetNode) String

func (n *SetNode) String() string

type SliceNode

type SliceNode struct {
	Object ExpressionNode
	Start  ExpressionNode // optional
	End    ExpressionNode // optional
	Step   ExpressionNode // optional
	// contains filtered or unexported fields
}

SliceNode represents slice expressions (array[start:end:step])

func NewSliceNode

func NewSliceNode(object ExpressionNode, line, column int) *SliceNode

func (*SliceNode) Column

func (n *SliceNode) Column() int

func (*SliceNode) ExpressionNode

func (n *SliceNode) ExpressionNode()

func (*SliceNode) Line

func (n *SliceNode) Line() int

func (*SliceNode) String

func (n *SliceNode) String() string

type StatementNode

type StatementNode interface {
	Node
	StatementNode()
}

StatementNode represents template statements

type SuperNode

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

SuperNode represents super() calls in template inheritance

func NewSuperNode

func NewSuperNode(line, column int) *SuperNode

func (*SuperNode) Column

func (n *SuperNode) Column() int

func (*SuperNode) ExpressionNode

func (n *SuperNode) ExpressionNode()

func (*SuperNode) Line

func (n *SuperNode) Line() int

func (*SuperNode) String

func (n *SuperNode) String() string

type TemplateNode

type TemplateNode struct {
	Name     string
	Children []Node
	// contains filtered or unexported fields
}

TemplateNode represents the root of a template AST

func NewTemplateNode

func NewTemplateNode(name string, line, column int) *TemplateNode

func (*TemplateNode) Column

func (n *TemplateNode) Column() int

func (*TemplateNode) Line

func (n *TemplateNode) Line() int

func (*TemplateNode) String

func (n *TemplateNode) String() string

type TestNode

type TestNode struct {
	Expression ExpressionNode
	TestName   string
	Arguments  []ExpressionNode
	Negated    bool // for "is not" tests
	// contains filtered or unexported fields
}

TestNode represents test expressions (variable is defined, value is none)

func NewTestNode

func NewTestNode(expr ExpressionNode, testName string, line, column int) *TestNode

func (*TestNode) Column

func (n *TestNode) Column() int

func (*TestNode) ExpressionNode

func (n *TestNode) ExpressionNode()

func (*TestNode) Line

func (n *TestNode) Line() int

func (*TestNode) String

func (n *TestNode) String() string

type TextNode

type TextNode struct {
	Content string
	// contains filtered or unexported fields
}

TextNode represents plain text content

func NewTextNode

func NewTextNode(content string, line, column int) *TextNode

func (*TextNode) Column

func (n *TextNode) Column() int

func (*TextNode) FastEval

func (n *TextNode) FastEval(e interface{}, ctx interface{}) (interface{}, error)

FastEval for TextNode - the most common node type Simply returns the text content without any processing

func (*TextNode) Line

func (n *TextNode) Line() int

func (*TextNode) String

func (n *TextNode) String() string

type UnaryOpNode

type UnaryOpNode struct {
	Operator string
	Operand  ExpressionNode
	// contains filtered or unexported fields
}

UnaryOpNode represents unary operations (not x, -x)

func AcquireUnaryOpNode

func AcquireUnaryOpNode(op string, operand ExpressionNode, line, column int) *UnaryOpNode

AcquireUnaryOpNode gets a UnaryOpNode from the pool

func NewUnaryOpNode

func NewUnaryOpNode(op string, operand ExpressionNode, line, column int) *UnaryOpNode

func (*UnaryOpNode) Column

func (n *UnaryOpNode) Column() int

func (*UnaryOpNode) ExpressionNode

func (n *UnaryOpNode) ExpressionNode()

func (*UnaryOpNode) Line

func (n *UnaryOpNode) Line() int

func (*UnaryOpNode) String

func (n *UnaryOpNode) String() string

type VariableNode

type VariableNode struct {
	Expression Node
	// contains filtered or unexported fields
}

VariableNode represents variable interpolation {{ var }}

func NewVariableNode

func NewVariableNode(expr Node, line, column int) *VariableNode

func (*VariableNode) Column

func (n *VariableNode) Column() int

func (*VariableNode) Line

func (n *VariableNode) Line() int

func (*VariableNode) String

func (n *VariableNode) String() string

type WithNode

type WithNode struct {
	Assignments map[string]ExpressionNode // Variable assignments like var1=expr1, var2=expr2
	Body        []Node                    // The content between {% with %} and {% endwith %}
	// contains filtered or unexported fields
}

WithNode represents with statements {% with var = expr %}...{% endwith %}

func NewWithNode

func NewWithNode(assignments map[string]ExpressionNode, body []Node, line, column int) *WithNode

func (*WithNode) Column

func (n *WithNode) Column() int

func (*WithNode) Line

func (n *WithNode) Line() int

func (*WithNode) StatementNode

func (n *WithNode) StatementNode()

func (*WithNode) String

func (n *WithNode) String() string

Jump to

Keyboard shortcuts

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