goexpression

package
v0.3.1118 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrContainerFuncNotFound    = errors.New("parser error: templ container function not found")
	ErrExpectedNodeNotFound     = errors.New("parser error: expected node not found")
	ErrTerminatingTokenNotFound = errors.New("parser error: terminating token not found")
)

Functions

func Case

func Case(content []byte) (start, end int, err error)

func Expression

func Expression(src []byte) (start, end int, err error)

func For

func For(content []byte) (start, end int, err error)

func Func

func Func(content []byte) (name, expr string, err error)

Func returns the Go code up to the opening brace of the function body. The content starts after the "func " keyword.

When the signature parses with an empty body, only the signature is parsed, not the templ code that follows it. When the signature has a syntax error, the whole of content is parsed and the error is ignored, so that the Go compiler reports it against the generated code, which maps back to its position in the templ file.

func If

func If(content []byte) (start, end int, err error)

func SliceArgs

func SliceArgs(content []byte) (expr string, err error)

SliceArgs returns the Go code up to the closing brace of a templ expression.

When the arguments parse, only the code up to the closing brace is parsed, not the templ code that follows it. When the arguments have a syntax error, the whole of content is parsed and the error is ignored, so that the Go compiler reports it against the generated code.

func Switch

func Switch(content []byte) (start, end int, err error)

func TemplExpression

func TemplExpression(src []byte) (start, end int, err error)

Types

type ErrUnbalanced

type ErrUnbalanced struct {
	Token token.Token
}

func (ErrUnbalanced) Error

func (e ErrUnbalanced) Error() string

type ExpressionParser

type ExpressionParser struct {
	Stack    Stack[token.Token]
	End      int
	Previous token.Token
	Fns      Stack[int] // Stack of function depths.
}

func NewExpressionParser

func NewExpressionParser() *ExpressionParser

func (*ExpressionParser) Insert

func (ep *ExpressionParser) Insert(
	pos token.Pos,
	tok token.Token,
	lit string,
) (stop bool, err error)

type Extractor

type Extractor func(body []ast.Stmt) (start, end int, err error)

Extract a Go expression from the content. The Go expression starts at "start" and ends at "end". The reader should skip until "length" to pass over the expression and into the next logical block.

type Stack

type Stack[T any] []T

func (*Stack[T]) Peek

func (s *Stack[T]) Peek() (v T)

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() (v T)

func (*Stack[T]) Push

func (s *Stack[T]) Push(v T)

Jump to

Keyboard shortcuts

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