parse

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 4 more Imports: 7 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

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

Index

Constants

View Source
const (
	Quick            Mode = iota // stop parsing after first error encoutered and return
	AllErrors                    // report all errors
	IncludeSensitive = "\\|"
	IncludeSeparator = "|"
	Include          = "_INCLUDE_"
	Indent           = "nindent"
	AbsSign          = "#/---//---//Nocalhost//---//---/"

	ErrTmpl = `` /* 185-byte string literal not displayed */

)

Mode for parser behaviour

Variables

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

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 Includation

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

type Mode

type Mode int

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

type Node

type Node interface {
	Type() NodeType
	String() (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, envs [][]string, r *Restrictions) *Parser

New allocates a new Parser with the given name. envs means support multi source env[] the priority rely by the order

func (*Parser) Parse

func (p *Parser) Parse(text string, absPath string, hasBeenInclude []string) (string, error)

Parse parses the given string.

func (*Parser) ParseWithoutIncludation

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

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
}

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, string, error)

func (*SubstitutionNode) StringWithDefault

func (t *SubstitutionNode) StringWithDefault() (k string, v string, err error)

type TextNode

type TextNode struct {
	NodeType
	Text string
}

func NewText

func NewText(text string) *TextNode

func (*TextNode) String

func (t *TextNode) String() (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, string, error)

Jump to

Keyboard shortcuts

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