parse

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Most of the code in this package taken from golang/text/template/parse

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error added in v1.0.2

func Error(err string, code string) *interErr

envsubst internal error, with error code wrapped.

Types

type Env

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

func NewEnv

func NewEnv(env []string) *Env

func (*Env) Get

func (e *Env) Get(key string) string

func (*Env) Has

func (e *Env) Has(key string) bool

type Mode

type Mode int

A mode value is a set of flags (or 0). They control parser behavior.

const (
	Quick     Mode = iota // stop parsing after first error encoutered and return
	AllErrors             // report all errors
)

Mode for parser behaviour

type Node

type Node interface {
	Type() NodeType
	String() (string, error)
}

type NodeType

type NodeType int

NodeType identifies the type of a node.

const (
	NodeText NodeType = iota
	NodeSubstitution
	NodeVariable
)

func (NodeType) Type

func (t NodeType) Type() NodeType

Type returns itself and provides an easy default implementation for embedding in a Node. Embedded in all non-trivial Nodes.

type Parser

type Parser struct {
	Name     string // name of the processing template
	Env      *Env
	Restrict *Restrictions
	Mode     Mode
	// contains filtered or unexported fields
}

Parser type initializer

func New

func New(name string, env *Env, r *Restrictions) *Parser

New allocates a new Parser with the given name.

func (*Parser) Parse

func (p *Parser) Parse(text string) (string, error)

Parse parses the given string.

type Pos

type Pos int

Pos represents a byte position in the original input text from which this template was parsed.

type Restrictions

type Restrictions struct {
	NoUnset    bool
	NoEmpty    bool
	NoDigit    bool
	VarMatcher varMatcher
}

The restrictions option controls the parsring restriction.

type SubstitutionNode

type SubstitutionNode struct {
	NodeType
	ExpType  itemType
	Variable *VariableNode
	Default  Node // Default could be variable or text
}

func (*SubstitutionNode) String

func (t *SubstitutionNode) String() (string, error)

type TextNode

type TextNode struct {
	NodeType
	Text string
}

func NewText

func NewText(text string) *TextNode

func (*TextNode) String

func (t *TextNode) String() (string, error)

type VariableNode

type VariableNode struct {
	NodeType
	Ident    string
	Env      *Env
	Restrict *Restrictions
}

func NewVariable

func NewVariable(ident string, env *Env, restrict *Restrictions) *VariableNode

func (*VariableNode) String

func (t *VariableNode) String() (string, error)

Jump to

Keyboard shortcuts

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