parse

package
v0.0.0-...-f8c0f81 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2011 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package parse builds parse trees for templates. The grammar is defined in the documents for the template package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Set

func Set(text string, funcs ...map[string]interface{}) (tree map[string]*Tree, err os.Error)

Set returns a slice of Trees created by parsing the template set definition in the argument string. If an error is encountered, parsing stops and an empty slice is returned with the error.

Types

type ActionNode

type ActionNode struct {
	NodeType
	Line int       // The line number in the input.
	Pipe *PipeNode // The pipeline in the action.
}

ActionNode holds an action (something bounded by delimiters). Control actions have their own nodes; ActionNode represents simple ones such as field evaluations.

func (*ActionNode) String

func (a *ActionNode) String() string

type BoolNode

type BoolNode struct {
	NodeType
	True bool // The value of the boolean constant.
}

BoolNode holds a boolean constant.

func (*BoolNode) String

func (b *BoolNode) String() string

type BranchNode

type BranchNode struct {
	NodeType
	Line     int       // The line number in the input.
	Pipe     *PipeNode // The pipeline to be evaluated.
	List     *ListNode // What to execute if the value is non-empty.
	ElseList *ListNode // What to execute if the value is empty (nil if absent).
}

BranchNode is the common representation of if, range, and with.

func (*BranchNode) String

func (b *BranchNode) String() string

type CommandNode

type CommandNode struct {
	NodeType
	Args []Node // Arguments in lexical order: Identifier, field, or constant.
}

CommandNode holds a command (a pipeline inside an evaluating action).

func (*CommandNode) String

func (c *CommandNode) String() string

type DotNode

type DotNode bool

DotNode holds the special identifier '.'. It is represented by a nil pointer.

func (*DotNode) String

func (d *DotNode) String() string

func (*DotNode) Type

func (d *DotNode) Type() NodeType

type FieldNode

type FieldNode struct {
	NodeType
	Ident []string // The identifiers in lexical order.
}

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

func (*FieldNode) String

func (f *FieldNode) String() string

type IdentifierNode

type IdentifierNode struct {
	NodeType
	Ident string // The identifier's name.
}

IdentifierNode holds an identifier.

func NewIdentifier

func NewIdentifier(ident string) *IdentifierNode

NewIdentifier returns a new IdentifierNode with the given identifier name.

func (*IdentifierNode) String

func (i *IdentifierNode) String() string

type IfNode

type IfNode struct {
	BranchNode
}

IfNode represents an {{if}} action and its commands.

type ListNode

type ListNode struct {
	NodeType
	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
}

A node is an element in the parse tree. The interface is trivial.

type NodeType

type NodeType int

NodeType identifies the type of a parse tree node.

const (
	NodeText    NodeType = iota // Plain text.
	NodeAction                  // A simple action such as field evaluation.
	NodeBool                    // A boolean constant.
	NodeCommand                 // An element of a pipeline.
	NodeDot                     // The cursor, dot.

	NodeField      // A field or method name.
	NodeIdentifier // An identifier; always a function name.
	NodeIf         // An if action.
	NodeList       // A list of Nodes.
	NodeNumber     // A numerical constant.
	NodePipe       // A pipeline of commands.
	NodeRange      // A range action.
	NodeString     // A string constant.
	NodeTemplate   // A template invocation action.
	NodeVariable   // A $ variable.
	NodeWith       // A with action.
)

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
	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.
}

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) String

func (n *NumberNode) String() string

type PipeNode

type PipeNode struct {
	NodeType
	Line int             // The line number in the input.
	Decl []*VariableNode // Variable declarations in lexical order.
	Cmds []*CommandNode  // The commands in lexical order.
}

PipeNode holds a pipeline with optional declaration

func (*PipeNode) String

func (p *PipeNode) String() string

type RangeNode

type RangeNode struct {
	BranchNode
}

RangeNode represents a {{range}} action and its commands.

type StringNode

type StringNode struct {
	NodeType
	Quoted string // The original text of the string, with 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 TemplateNode

type TemplateNode struct {
	NodeType
	Line int       // The line number in the input.
	Name string    // The name of the template (unquoted).
	Pipe *PipeNode // The command to evaluate as dot for the template.
}

TemplateNode represents a {{template}} action.

func (*TemplateNode) String

func (t *TemplateNode) String() string

type TextNode

type TextNode struct {
	NodeType
	Text []byte // The text; may span newlines.
}

TextNode holds plain text.

func (*TextNode) String

func (t *TextNode) String() string

type Tree

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

Tree is the representation of a parsed template.

func New

func New(name string, funcs ...map[string]interface{}) *Tree

New allocates a new template with the given name.

func (*Tree) Parse

func (t *Tree) Parse(s string, funcs ...map[string]interface{}) (tree *Tree, err os.Error)

Parse parses the template definition string to construct an internal representation of the template for execution.

type VariableNode

type VariableNode struct {
	NodeType
	Ident []string // Variable names in lexical order.
}

VariableNode holds a list of variable names. The dollar sign is part of the name.

func (*VariableNode) String

func (v *VariableNode) String() string

type WithNode

type WithNode struct {
	BranchNode
}

WithNode represents a {{with}} action and its commands.

Jump to

Keyboard shortcuts

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