tpl

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicLit added in v1.3.7

func BasicLit(this any) *ast.BasicLit

BasicLit converts the matching result of a basic literal to an ast.BasicLit expression.

func BinaryExpr added in v1.3.7

func BinaryExpr(recursive bool, in []any) ast.Expr

BinaryExpr converts the matching result of (X % op) to a binary expression. X % op means X *(op X)

func BinaryExprNR added in v1.3.7

func BinaryExprNR(in []any) ast.Expr

func BinaryExprR added in v1.3.7

func BinaryExprR(in []any) ast.Expr

func BinaryOp added in v1.3.7

func BinaryOp(recursive bool, in []any, fn func(op *Token, x, y any) any) any

func BinaryOpNR added in v1.3.7

func BinaryOpNR(in []any, fn func(op *Token, x, y any) any) any

func BinaryOpR added in v1.3.7

func BinaryOpR(in []any, fn func(op *Token, x, y any) any) any

func Dump

func Dump(result any, omitSemi ...bool)

func Fdump

func Fdump(w io.Writer, ret any, prefix, indent string, omitSemi bool)

func Ident added in v1.3.7

func Ident(this any) *ast.Ident

Ident converts the matching result of an identifier to an ast.Ident expression.

func List added in v1.3.7

func List(in []any) []any

List converts the matching result of (R % ",") to a flat list. R % "," means R *("," R)

func Panic added in v1.3.7

func Panic(pos token.Pos, msg string)

Panic panics with a matcher error.

func RangeOp added in v1.3.7

func RangeOp(in []any, fn func(v any))

RangeOp travels the matching result of (R % ",") and call fn(result of R). R % "," means R *("," R)

func Relocate added in v1.3.8

func Relocate(err error, filename string, line, col int) error

Relocate relocates the error positions.

func ShowConflict added in v1.3.8

func ShowConflict(f bool) int

ShowConflict sets the flag to show or hide conflicts.

func UnaryExpr added in v1.3.7

func UnaryExpr(in []any) ast.Expr

UnaryExpr converts the matching result of (op X) to a unary expression.

Types

type Compiler

type Compiler struct {
	cl.Result
}

Compiler represents a TPL compiler.

func FromFile

func FromFile(fset *token.FileSet, filename string, src any, conf *cl.Config) (ret Compiler, err error)

FromFile creates a new TPL compiler from a file. fset can be nil.

func New

func New(src any, params ...any) (ret Compiler, err error)

New creates a new TPL compiler. params: ruleName1, retProc1, ..., ruleNameN, retProcN

func NewEx added in v1.3.8

func NewEx(src any, filename string, line, col int, params ...any) (ret Compiler, err error)

NewEx creates a new TPL compiler. params: ruleName1, retProc1, ..., ruleNameN, retProcN

func (*Compiler) Match

func (p *Compiler) Match(filename string, src any, conf *Config) (ms MatchState, result any, err error)

Match matches a source file.

func (*Compiler) Parse

func (p *Compiler) Parse(filename string, src any, conf *Config) (result any, err error)

Parse parses a source file.

func (*Compiler) ParseExpr

func (p *Compiler) ParseExpr(x string, conf *Config) (result any, err error)

ParseExpr parses an expression.

func (*Compiler) ParseExprFrom

func (p *Compiler) ParseExprFrom(filename string, src any, conf *Config) (result any, err error)

ParseExprFrom parses an expression from a file.

type Config

type Config struct {
	Scanner          Scanner
	ScanErrorHandler scanner.ErrorHandler
	ScanMode         scanner.Mode
	Fset             *token.FileSet
}

Config represents a parsing configuration of Compiler.Parse.

type Error added in v1.3.8

type Error = matcher.Error

Error represents a matching error.

type MatchState added in v1.3.7

type MatchState struct {
	Toks []*Token
	Ctx  *matcher.Context
	N    int
}

MatchState represents a matching state.

func (*MatchState) Next added in v1.3.7

func (p *MatchState) Next() *Token

Next returns the next token.

type Scanner

type Scanner interface {
	Scan() Token
	Init(file *token.File, src []byte, err scanner.ErrorHandler, mode scanner.Mode)
}

Scanner represents a TPL scanner.

type Token

type Token = types.Token

A Token is a lexical unit returned by Scan.

Directories

Path Synopsis
encoding
csv
xml

Jump to

Keyboard shortcuts

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