parse

package
v0.0.0-...-20e2382 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2015 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoolNode

type BoolNode struct {
	NodeType
	Pos

	True bool // The value of the boolean constant.
	// contains filtered or unexported fields
}

BoolNode holds a boolean constant.

func (*BoolNode) Copy

func (b *BoolNode) Copy() Node

func (*BoolNode) String

func (b *BoolNode) String() string

type Config

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

func (*Config) GetArray

func (c *Config) GetArray(path string) (vals []*Config, err error)

func (*Config) GetBool

func (c *Config) GetBool(path string) (val bool, err error)

func (*Config) GetComplex

func (c *Config) GetComplex(path string) (val complex128, err error)

func (*Config) GetDefaultBool

func (c *Config) GetDefaultBool(path string, defaultVal bool) bool

func (*Config) GetDefaultComplex

func (c *Config) GetDefaultComplex(path string, defaultVal complex128) complex128

func (*Config) GetDefaultFloat

func (c *Config) GetDefaultFloat(path string, defaultVal float64) float64

func (*Config) GetDefaultInt

func (c *Config) GetDefaultInt(path string, defaultVal int64) int64

func (*Config) GetDefaultString

func (c *Config) GetDefaultString(path string, defaultVal string) string

func (*Config) GetDefaultUInt

func (c *Config) GetDefaultUInt(path string, defaultVal uint64) uint64

func (*Config) GetFloat

func (c *Config) GetFloat(path string) (val float64, err error)

func (*Config) GetInt

func (c *Config) GetInt(path string) (val int64, err error)

func (*Config) GetString

func (c *Config) GetString(path string) (val string, err error)

func (*Config) GetUInt

func (c *Config) GetUInt(path string) (val uint64, err error)

func (*Config) GetValue

func (c *Config) GetValue(path string) (conf *Config, err error)

func (*Config) String

func (c *Config) String() string

type FieldNode

type FieldNode struct {
	NodeType
	Pos

	Ident []string // The identifiers in lexical order.
	// contains filtered or unexported fields
}

FieldNode holds a field (identifier starting with '.'). The names may be chained ('.x.y'). The period is dropped from each ident.

func (*FieldNode) Copy

func (f *FieldNode) Copy() Node

func (*FieldNode) String

func (f *FieldNode) String() string

type ListNode

type ListNode struct {
	NodeType
	Pos

	Nodes []Node // The element nodes in lexical order.
	// contains filtered or unexported fields
}

ListNode holds a sequence of nodes.

func (*ListNode) Copy

func (l *ListNode) Copy() Node

func (*ListNode) CopyList

func (l *ListNode) CopyList() *ListNode

func (*ListNode) String

func (l *ListNode) String() string

type MapNode

type MapNode struct {
	NodeType
	Pos

	Nodes map[string]Node
	// contains filtered or unexported fields
}

MapNode holds a map of nodes.

func (*MapNode) Copy

func (m *MapNode) Copy() Node

func (*MapNode) CopyMap

func (m *MapNode) CopyMap() *MapNode

func (*MapNode) String

func (m *MapNode) String() string

type NilNode

type NilNode struct {
	NodeType
	Pos
	// contains filtered or unexported fields
}

NilNode holds the special identifier 'nil' representing an untyped nil constant.

func (*NilNode) Copy

func (n *NilNode) Copy() Node

func (*NilNode) String

func (n *NilNode) String() string

func (*NilNode) Type

func (n *NilNode) Type() NodeType

type Node

type Node interface {
	Type() NodeType
	String() string
	// Copy does a deep copy of the Node and all its components.
	// To avoid type assertions, some XxxNodes also have specialized
	// CopyXxx methods that return *XxxNode.
	Copy() Node
	Position() Pos // byte position of start of node in full original input string
	// contains filtered or unexported methods
}

A Node is an element in the parse tree. The interface is trivial. The interface contains an unexported method so that only types local to this package can satisfy it.

type NodeType

type NodeType int

NodeType identifies the type of a parse tree node.

const (
	NodeText   NodeType = iota // Plain text.
	NodeField                  // A field or method name.
	NodeList                   // A list of Nodes.
	NodeMap                    // A map of Nodes.
	NodeNil                    // An untyped nil constant.
	NodeBool                   // A boolean constant.
	NodeNumber                 // A numerical constant.
	NodeString                 // A string constant.
)

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 NumberNode

type NumberNode struct {
	NodeType
	Pos

	IsInt      bool       // Number has an integral value.
	IsUint     bool       // Number has an unsigned integral value.
	IsFloat    bool       // Number has a floating-point value.
	IsComplex  bool       // Number is complex.
	Int64      int64      // The signed integer value.
	Uint64     uint64     // The unsigned integer value.
	Float64    float64    // The floating-point value.
	Complex128 complex128 // The complex value.
	Text       string     // The original textual representation from the input.
	// contains filtered or unexported fields
}

NumberNode holds a number: signed or unsigned integer, float, or complex. The value is parsed and stored under all the types that can represent the value. This simulates in a small amount of code the behavior of Go's ideal constants.

func (*NumberNode) Copy

func (n *NumberNode) Copy() Node

func (*NumberNode) String

func (n *NumberNode) String() string

type Pos

type Pos int

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

func (Pos) Position

func (p Pos) Position() Pos

type StringNode

type StringNode struct {
	NodeType
	Pos

	Quoted string // The original text of the string, with quotes.
	Text   string // The string, after quote processing.
	// contains filtered or unexported fields
}

StringNode holds a string constant. The value has been "unquoted".

func (*StringNode) Copy

func (s *StringNode) Copy() Node

func (*StringNode) String

func (s *StringNode) String() string

type TextNode

type TextNode struct {
	NodeType
	Pos

	Text []byte // The text; may span newlines.
	// contains filtered or unexported fields
}

TextNode holds plain text.

func (*TextNode) Copy

func (t *TextNode) Copy() Node

func (*TextNode) String

func (t *TextNode) String() string

type Tree

type Tree struct {
	Name      string // name of the template represented by the tree.
	ParseName string // name of the top-level template during parsing, for error messages.
	Root      Node   // top-level root of the tree.
	// contains filtered or unexported fields
}

Tree is the representation of a single parsed template.

func New

func New(name string) *Tree

New allocates a new parse tree with the given name.

func Parse

func Parse(name, text string) (tree *Tree, err error)

Parse returns a map from template name to parse.Tree, created by parsing the templates described in the argument string. The top-level template will be given the specified name. If an error is encountered, parsing stops and an empty map is returned with the error.

func (*Tree) Copy

func (t *Tree) Copy() *Tree

Copy returns a copy of the Tree. Any parsing state is discarded.

func (*Tree) ErrorContext

func (t *Tree) ErrorContext(n Node) (location, context string)

ErrorContext returns a textual representation of the location of the node in the input text. The receiver is only used when the node does not have a pointer to the tree inside, which can occur in old code.

func (*Tree) GetConfig

func (t *Tree) GetConfig() *Config

func (*Tree) Parse

func (t *Tree) Parse(text string) (tree *Tree, err error)

Parse parses the template definition string to construct a representation of the template for execution. If either action delimiter string is empty, the default ("{{" or "}}") is used. Embedded template definitions are added to the treeSet map.

Jump to

Keyboard shortcuts

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