parse

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2017 License: MIT Imports: 5 Imported by: 16

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 NoEmpty = &Restrictions{false, true}
View Source
var NoUnset = &Restrictions{true, false}
View Source
var Relaxed = &Restrictions{false, false}
View Source
var Strict = &Restrictions{true, true}

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 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
	// contains filtered or unexported fields
}

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
}

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