twigparser

package
v0.0.27 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutoescapeNode

type AutoescapeNode struct {
	Strategy string   // e.g. "html"
	Children NodeList // content within the autoescape block
}

AutoescapeNode represents an autoescape block in the template.

func (*AutoescapeNode) Dump

func (a *AutoescapeNode) Dump() string

func (*AutoescapeNode) String

func (a *AutoescapeNode) String(indent string) string

type BlockNode

type BlockNode struct {
	Name     string
	Children NodeList
}

BlockNode represents a Twig block (with opening tag {% block <name> %} and ending tag {% endblock %}), and contains nested child nodes.

func (*BlockNode) Dump

func (b *BlockNode) Dump() string

func (*BlockNode) String

func (b *BlockNode) String(indent string) string

type DeprecatedNode

type DeprecatedNode struct {
	Message string
}

DeprecatedNode represents a deprecated tag in the template.

func (*DeprecatedNode) Dump

func (d *DeprecatedNode) Dump() string

func (*DeprecatedNode) String

func (d *DeprecatedNode) String(indent string) string

type ForNode

type ForNode struct {
	Var        string
	Collection string
	Children   NodeList
}

ForNode represents a for-loop in the template.

func (*ForNode) Dump

func (f *ForNode) Dump() string

func (*ForNode) String

func (f *ForNode) String(indent string) string

type Node

type Node interface {
	// String provides a debug representation with indentation.
	String(indent string) string
	// Dump outputs the node (and its children) back into source code.
	Dump() string
}

Node represents an AST node.

type NodeList

type NodeList []Node

func ParseTemplate

func ParseTemplate(input string) (NodeList, error)

ParseTemplate is the entry point that builds an AST for the template.

func (NodeList) BlockNames

func (nl NodeList) BlockNames() []string

func (NodeList) Dump

func (nl NodeList) Dump() string

func (NodeList) Extends

func (nl NodeList) Extends() *SwExtendsNode

func (NodeList) Find

func (nl NodeList) Find(predicate func(Node) bool) NodeList

func (NodeList) FindBlock

func (nl NodeList) FindBlock(name string) *BlockNode

func (NodeList) RemoveWhitespace

func (nl NodeList) RemoveWhitespace() NodeList

func (NodeList) String

func (nl NodeList) String() string

func (NodeList) Traverse

func (nl NodeList) Traverse(visitor func(Node) Node) NodeList

type ParentNode

type ParentNode struct{}

ParentNode represents the Twig expression {{ parent() }}.

func (*ParentNode) Dump

func (p *ParentNode) Dump() string

func (*ParentNode) String

func (p *ParentNode) String(indent string) string

type PrintNode

type PrintNode struct {
	Expression string
}

PrintNode represents an expression that prints a variable.

func (*PrintNode) Dump

func (p *PrintNode) Dump() string

func (*PrintNode) String

func (p *PrintNode) String(indent string) string

type SetNode

type SetNode struct {
	Variables []string // left-hand side variable(s)
	Values    []string // right-hand side expression(s) for inline assignment; empty when IsBlock is true
	IsBlock   bool     // true when using block assignment
	Children  NodeList // block assignment content
}

SetNode represents a 'set' assignment in the template.

func (*SetNode) Dump

func (s *SetNode) Dump() string

func (*SetNode) String

func (s *SetNode) String(indent string) string

type SwExtendsNode

type SwExtendsNode struct {
	Template string
	Scopes   []string
}

SwExtendsNode represents the Twig tag for extending a template. It supports both simple and object-literal syntaxes.

func (*SwExtendsNode) Dump

func (s *SwExtendsNode) Dump() string

func (*SwExtendsNode) String

func (s *SwExtendsNode) String(indent string) string

type TextNode

type TextNode struct {
	Text string
}

TextNode holds non‑whitespace plain text.

func (*TextNode) Dump

func (t *TextNode) Dump() string

func (*TextNode) String

func (t *TextNode) String(indent string) string

type TypesNode

type TypesNode struct {
	Types map[string]string
}

TypesNode represents a types definition tag such as {% types score: 'number' %}

func (*TypesNode) Dump

func (t *TypesNode) Dump() string

func (*TypesNode) String

func (t *TypesNode) String(indent string) string

type WhitespaceNode

type WhitespaceNode struct {
	Text string
}

WhitespaceNode holds a text fragment that consists solely of whitespace (spaces, tabs, newlines, etc).

func (*WhitespaceNode) Dump

func (w *WhitespaceNode) Dump() string

func (*WhitespaceNode) String

func (w *WhitespaceNode) String(indent string) string

Jump to

Keyboard shortcuts

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