tmpl

package
v0.0.1 Latest Latest
Warning

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

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

Documentation

Overview

Package tmpl is responsible for parsing the combined templates for git.dresden.micronet24.de/toolkit/template

As these templates support multiple languages (go's text/template and perls/pythons Template::Toolkit), the tokenizer and lexer work in multiple stages. Each have an outer part for the template itself and an inner part for expressions of on of the template languages.

The outer tokenizer breaks the input on (configurable) tokens marking the start or the end of a template expression. Everything between those expressions is handled as static text, everything within these expressions is parsed and lexed by the corresponding tokenizer/lexer for that template language as in git.dresden.micronet24.de/toolkit/template/text or git.dresden.micronet24.de/toolkit/template/toolkit.

The outer lexer receives the individual tokens in form from git.dresden.micronet24.de/toolkit/template/itemcontrol.ItemControl and ensures the overall consistency and finally creates the resulting list of Functions.

For communication between the outer and inner parsers, a TmplEnv is needed, which consists of a channel of ParserMsg, which are used to qualify the individual tokens.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorItem

type ErrorItem struct {
	itemcontrol.BasePosItem
	// contains filtered or unexported fields
}

func CreateErrorItem

func CreateErrorItem(pos itemcontrol.Position, err string) *ErrorItem

func (*ErrorItem) Error

func (e *ErrorItem) Error() string

func (*ErrorItem) HasError

func (e *ErrorItem) HasError() bool

type ParserMsg

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

ParserMsg is an item containing one token from the inner parsers to the outer

type TemplateBlockManager

type TemplateBlockManager interface {
	GetBlock(name string) ([]itemcontrol.TmplFunc, error)
	AddBlock(name string, ctnt itemcontrol.ItemControlMulti) error
}

type TmplEnv

type TmplEnv interface {
	itemcontrol.PositionName
	DeriveInner() TmplEnv
	SetOption(opt ...TmplOption) TmplEnv
	StartScope()
	Scope() *itemcontrol.ItemScope
	EndScope() error
	SendMsg(msg ParserMsg)
	SendContent(id int, ctnt itemcontrol.ItemControl)
	Close()
	UpdatePosition(msg string)
	Error(err string)
	ErrorAt(pos itemcontrol.Position, err string)
	ClearErrors()
	Parse() ([]itemcontrol.TmplFunc, error)
	GetFunction(typ itemcontrol.FuncType, name string) (any, error)
	OnMissingHdl() itemcontrol.SelectOnMissingHdl
	OnErrorHdl() itemcontrol.OnErrorHdl
}

func CreateTmplEnv

func CreateTmplEnv(ch chan ParserMsg, name string, fn itemcontrol.FuncLookup) TmplEnv

CreateTmplEnv generates a new TmplEnv with a given channel and name of the template (file) which is parsed

type TmplEnvInner

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

func (*TmplEnvInner) ClearErrors

func (e *TmplEnvInner) ClearErrors()

clear all previously gathered errors

func (*TmplEnvInner) Close

func (e *TmplEnvInner) Close()

func (*TmplEnvInner) Column

func (e *TmplEnvInner) Column() int

Column returns the current column within the template

func (*TmplEnvInner) DeriveInner

func (e *TmplEnvInner) DeriveInner() TmplEnv

func (*TmplEnvInner) EndScope

func (e *TmplEnvInner) EndScope() error

func (*TmplEnvInner) Error

func (e *TmplEnvInner) Error(err string)

func (*TmplEnvInner) ErrorAt

func (e *TmplEnvInner) ErrorAt(pos itemcontrol.Position, err string)

func (*TmplEnvInner) GetFunction

func (e *TmplEnvInner) GetFunction(typ itemcontrol.FuncType, name string) (any, error)

func (*TmplEnvInner) Line

func (e *TmplEnvInner) Line() int

Line returns the current line within the template

func (*TmplEnvInner) Name

func (e *TmplEnvInner) Name() string

Name returns the name of the current template

func (*TmplEnvInner) OnErrorHdl

func (e *TmplEnvInner) OnErrorHdl() itemcontrol.OnErrorHdl

OnErrorHdl returns the error-handle currently set

func (*TmplEnvInner) OnMissingHdl

func (e *TmplEnvInner) OnMissingHdl() itemcontrol.SelectOnMissingHdl

func (*TmplEnvInner) Parse

func (e *TmplEnvInner) Parse() ([]itemcontrol.TmplFunc, error)

func (*TmplEnvInner) Scope

func (e *TmplEnvInner) Scope() *itemcontrol.ItemScope

func (*TmplEnvInner) SendContent

func (e *TmplEnvInner) SendContent(id int, ctnt itemcontrol.ItemControl)

func (*TmplEnvInner) SendMsg

func (e *TmplEnvInner) SendMsg(msg ParserMsg)

func (*TmplEnvInner) SetOption

func (e *TmplEnvInner) SetOption(opt ...TmplOption) TmplEnv

func (*TmplEnvInner) StartScope

func (e *TmplEnvInner) StartScope()

func (*TmplEnvInner) String

func (e *TmplEnvInner) String() string

String returns all stored errors

func (*TmplEnvInner) UpdatePosition

func (e *TmplEnvInner) UpdatePosition(msg string)

type TmplEnvOuter

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

TmplEnv provides the environment for parsing a template

func (*TmplEnvOuter) ClearErrors

func (e *TmplEnvOuter) ClearErrors()

clear all previously gathered errors

func (*TmplEnvOuter) Close

func (e *TmplEnvOuter) Close()

Close closes the communication channel - signals end of template

func (*TmplEnvOuter) Column

func (e *TmplEnvOuter) Column() int

Column returns the current column within the template

func (*TmplEnvOuter) Create

func (e *TmplEnvOuter) Create(ch chan ParserMsg, name string, fn itemcontrol.FuncLookup) TmplEnv

Create (re-)initializes a TmplEnv with a new channel ch and template name

func (*TmplEnvOuter) DeriveInner

func (e *TmplEnvOuter) DeriveInner() TmplEnv

Derive inner TmplEnv from outer one

func (*TmplEnvOuter) EndScope

func (e *TmplEnvOuter) EndScope() error

EndScope closes the current scope and returns to the outer scope

func (*TmplEnvOuter) Error

func (e *TmplEnvOuter) Error(err string)

Error stores a new parser error

func (*TmplEnvOuter) ErrorAt

func (e *TmplEnvOuter) ErrorAt(pos itemcontrol.Position, err string)

ErrorAt stores a new parser error at a given position

func (*TmplEnvOuter) GetFunction

func (e *TmplEnvOuter) GetFunction(typ itemcontrol.FuncType, name string) (any, error)

func (*TmplEnvOuter) Lex

func (e *TmplEnvOuter) Lex(lval *yySymType) int

Lex provides the compatiblity function for yyLex

the function will return the next item in the lexer channel

func (*TmplEnvOuter) Line

func (e *TmplEnvOuter) Line() int

Line returns the current line within the template

func (*TmplEnvOuter) Name

func (e *TmplEnvOuter) Name() string

Name returns the name of the current template

func (*TmplEnvOuter) OnErrorHdl

func (e *TmplEnvOuter) OnErrorHdl() itemcontrol.OnErrorHdl

OnErrorHdl returns the error-handle currently set

func (*TmplEnvOuter) OnMissingHdl

func (e *TmplEnvOuter) OnMissingHdl() itemcontrol.SelectOnMissingHdl

func (*TmplEnvOuter) Parse

func (e *TmplEnvOuter) Parse() ([]itemcontrol.TmplFunc, error)

Parse triggers the parsing process

func (*TmplEnvOuter) Scope

func (e *TmplEnvOuter) Scope() *itemcontrol.ItemScope

Scope returns the currently active scope

func (*TmplEnvOuter) SendContent

func (e *TmplEnvOuter) SendContent(id int, ctnt itemcontrol.ItemControl)

SendContent transmits an ItemControl ctnt with corresponding id over the channel to the outer grammar

func (*TmplEnvOuter) SendMsg

func (e *TmplEnvOuter) SendMsg(msg ParserMsg)

SendMsg transmits a new token via the channel to the outer grammar

func (*TmplEnvOuter) SetBlockManager

func (e *TmplEnvOuter) SetBlockManager(mgr TemplateBlockManager) (TmplEnv, error)

func (*TmplEnvOuter) SetOnMissingHdl

func (e *TmplEnvOuter) SetOnMissingHdl(hdl itemcontrol.SelectOnMissingHdl) *TmplEnvOuter

func (*TmplEnvOuter) SetOption

func (e *TmplEnvOuter) SetOption(opt ...TmplOption) TmplEnv

SetOption will set the given TmplOption elements

func (*TmplEnvOuter) StartScope

func (e *TmplEnvOuter) StartScope()

StartScope will create a new scope (for variables)

func (*TmplEnvOuter) String

func (e *TmplEnvOuter) String() string

String returns all stored errors

func (*TmplEnvOuter) UpdatePosition

func (e *TmplEnvOuter) UpdatePosition(msg string)

UpdatePosition will update the embedded position information based on the text parsed (passed via msg)

type TmplOptBlock

type TmplOptBlock struct {
	Mgr TemplateBlockManager
}

TmplOptBlock is the option to set a TemplateBlockManager to use with the template

func (*TmplOptBlock) SetTmplOption

func (o *TmplOptBlock) SetTmplOption(t TmplEnv)

type TmplOptFunc

type TmplOptFunc struct {
	Fn itemcontrol.FuncLookup
}

TmplOptFunc is the option to set a FunctionManager via its LookupFunction

the same can be done using the Create() function, but this can also modify the manager afterwards or set a special manager in TmplEnvInner

func (*TmplOptFunc) SetTmplOption

func (o *TmplOptFunc) SetTmplOption(t TmplEnv)

type TmplOptFuncMgr

type TmplOptFuncMgr struct {
	Mgr *itemcontrol.FuncManager
}

TmplOptFuncMgr is the option to set a FunctionManager directly

similar to TmplOptFunc

func (*TmplOptFuncMgr) SetTmplOption

func (o *TmplOptFuncMgr) SetTmplOption(t TmplEnv)

type TmplOptOnError

type TmplOptOnError struct {
	Hdl itemcontrol.OnErrorHdl
}

TmplOptOnError is the option to set the OnErrorHdl

if a nil-handle is passed, nothing will be changed

func (*TmplOptOnError) SetTmplOption

func (o *TmplOptOnError) SetTmplOption(t TmplEnv)

type TmplOptSelect

type TmplOptSelect struct {
	Hdl itemcontrol.SelectOnMissingHdl
}

TmplOptSelect is the option to set the SelectOnMissingHdl

if a nil-handle is passed, nothing will be changed

func (*TmplOptSelect) SetTmplOption

func (o *TmplOptSelect) SetTmplOption(t TmplEnv)

type TmplOption

type TmplOption interface {
	SetTmplOption(t TmplEnv)
}

TmplOption is the interface for an Option-Helper to be used with SetOption

If there is an error with the option or the TmplEnv, SetTmplOption() is expected to panic

Jump to

Keyboard shortcuts

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