parse

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2023 License: MIT Imports: 5 Imported by: 13

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
var (
	Relaxed = &Restrictions{false, false, false}
	NoEmpty = &Restrictions{false, true, false}
	NoUnset = &Restrictions{true, false, false}
	Strict  = &Restrictions{true, true, false}
)

Restrictions specifier

Functions

This section is empty.

Types

type Env

type Env []string

func (Env) Get

func (e Env) Get(name string) string

func (Env) Has

func (e Env) Has(name string) bool

func (Env) Lookup

func (e Env) Lookup(name string) (string, bool)

type Mode added in v1.2.0

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 []string, 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
}

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