parse

package
v0.0.0-...-f7a0673 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2015 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package parse builds parse trees for configurations as defined by conf. Clients should use that package to construct configurations rather than this one, which provides shared internal data structures not intended for general use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ListNode

type ListNode struct {
	NodeType
	Pos
	Nodes []Node // The element nodes in lexical order.
}

ListNode holds a sequence of nodes.

func (*ListNode) String

func (l *ListNode) String() string

type Node

type Node interface {
	Type() NodeType
	String() string
	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 (
	NodePair    NodeType = iota // key=value expression.
	NodeList                    // A list of nodes.
	NodeString                  // A string constant.
	NodeSection                 // [section] definition.
)

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 PairNode

type PairNode struct {
	NodeType
	Pos
	Key, Val *StringNode
}

PairNode holds a key=value pair.

func (*PairNode) String

func (p *PairNode) 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 SectionNode

type SectionNode struct {
	NodeType
	Pos
	RawText     string
	SectionType *StringNode
	Name        *StringNode
	Nodes       *ListNode
}

SectionNode holds a section name and children

func (*SectionNode) String

func (s *SectionNode) String() string

type StringNode

type StringNode struct {
	NodeType
	Pos
	Quoted string // The original text of the string, with possible quotes.
	Text   string // The string, after quote processing.
}

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

func (*StringNode) String

func (s *StringNode) String() string

type Tree

type Tree struct {
	Name string    // name of the template represented by the tree.
	Root *ListNode // top-level root of the tree.
	// contains filtered or unexported fields
}

Tree is the representation of a single parsed configuration.

func New

func New(name string) *Tree

New allocates a new parse tree with the given name.

func Parse

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

Parse returns a Tree, created by parsing the configuration described in the argument string. If an error is encountered, parsing stops and an empty Tree is returned with the error.

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.

func (*Tree) Parse

func (t *Tree) Parse(text string) (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