token

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package token provides a tool to convert a string to Tokens that represent GO code.

Index

Constants

View Source
const (
	Delimiter = "%"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Chunker

type Chunker struct {
}

func NewChunker

func NewChunker() *Chunker

func (*Chunker) Chunks

func (c *Chunker) Chunks(s string) ([]string, error)

Chunks splits text into a slice. It finds substrings surrounded by percent marks ("%"). An empty string returns a 1-length slice always.

chunker.Chunks("%firstname% %lastname%") // []string{"%firstname%", " ", "%lastname%"}
chunker.Chunks("")                       // []string{""}

type FactoryFunction

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

FactoryFunction handles %env(ENV_VAR)%.

func NewFactoryFunction

func NewFactoryFunction(
	a aliaser,
	fn string,
	goImport string,
	goFn string,
) *FactoryFunction

func (*FactoryFunction) Create

func (f *FactoryFunction) Create(expr string) (Token, error)

func (*FactoryFunction) Supports

func (f *FactoryFunction) Supports(expr string) bool

type FactoryPercentMark

type FactoryPercentMark struct{}

FactoryPercentMark handles %%.

func (FactoryPercentMark) Create

func (f FactoryPercentMark) Create(string) (Token, error)

func (FactoryPercentMark) Supports

func (f FactoryPercentMark) Supports(expr string) bool

type FactoryReference

type FactoryReference struct{}

FactoryReference handles %my.param%.

func (FactoryReference) Create

func (FactoryReference) Create(s string) (Token, error)

func (FactoryReference) Supports

func (FactoryReference) Supports(s string) bool

type FactoryString

type FactoryString struct{}

func (FactoryString) Create

func (FactoryString) Create(expr string) (Token, error)

func (FactoryString) Supports

func (FactoryString) Supports(string) bool

type FactoryUnexpectedFunction

type FactoryUnexpectedFunction struct {
}

func (FactoryUnexpectedFunction) Create

func (FactoryUnexpectedFunction) Create(expr string) (t Token, _ error)

func (FactoryUnexpectedFunction) Supports

func (FactoryUnexpectedFunction) Supports(expr string) bool

type FactoryUnexpectedToken

type FactoryUnexpectedToken struct {
}

func (FactoryUnexpectedToken) Create

func (f FactoryUnexpectedToken) Create(expr string) (t Token, _ error)

func (FactoryUnexpectedToken) Supports

func (FactoryUnexpectedToken) Supports(expr string) bool

type FuncRegisterer

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

func NewFuncRegisterer

func NewFuncRegisterer(
	p interface{ Prepend(s tokenFactoryStrategy) },
	a aliaser,
) *FuncRegisterer

func (*FuncRegisterer) RegisterFunc

func (f *FuncRegisterer) RegisterFunc(fnAlias string, goImport string, goFn string)

type Kind

type Kind uint
const (
	KindString    Kind = iota // raw string
	KindReference             // e.g. %name%
	KindFunc                  // e.g. %env("APP_HOST")%
)

type StrategyFactory

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

func NewStrategyFactory

func NewStrategyFactory(strategies ...tokenFactoryStrategy) *StrategyFactory

func (*StrategyFactory) Create

func (f *StrategyFactory) Create(i string) (t Token, _ error)

func (*StrategyFactory) Prepend

func (f *StrategyFactory) Prepend(s tokenFactoryStrategy)

type Token

type Token struct {
	Kind      Kind
	Raw       string
	DependsOn []string // list of dependencies for KindReference
	Code      string   // GO code in the following format of func: func() (interface{}, error) { ... }
}

type Tokenizer

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

func NewTokenizer

func NewTokenizer(ch chunker, f factory) *Tokenizer

func (*Tokenizer) Tokenize

func (t *Tokenizer) Tokenize(s string) (r Tokens, _ error)

type Tokens

type Tokens []Token

func (Tokens) GoCode

func (tkns Tokens) GoCode() (string, error)

GoCode returns Go code that is such func `func() (interface{}, error)`, suffixed with `()`, e.g.:

func() (interface{}, error) { return "hello world", nil }()

Jump to

Keyboard shortcuts

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