parse

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2016 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NodeList     = "list"
	NodeDefer    = "defer"
	NodeError    = "error"
	NodeRecover  = "recover"
	NodeParallel = "parallel"
	NodeRun      = "run"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DeferNode

type DeferNode struct {
	NodeType `json:"type"`

	Body  Node `json:"body"`  // evaluate node
	Defer Node `json:"defer"` // defer evaluation of node.
}

DeferNode executes the child node, and then executes the deffered node. The deffered node is guaranteed to execute, even when the child node fails.

func NewDeferNode

func NewDeferNode() *DeferNode

NewDeferNode returns a new DeferNode.

func (*DeferNode) SetBody

func (n *DeferNode) SetBody(node Node) *DeferNode

func (*DeferNode) SetDefer

func (n *DeferNode) SetDefer(node Node) *DeferNode

func (*DeferNode) Validate

func (n *DeferNode) Validate() error

type ErrorNode

type ErrorNode struct {
	NodeType `json:"type"`

	Body  Node `json:"body"`  // evaluate node
	Defer Node `json:"defer"` // defer evaluation of node on error.
}

ErrorNode executes the body node, and then executes the error node if the body node errors. This is similar to defer but only executes on error.

func NewErrorNode

func NewErrorNode() *ErrorNode

NewErrorNode returns a new ErrorNode.

func (*ErrorNode) SetBody

func (n *ErrorNode) SetBody(node Node) *ErrorNode

func (*ErrorNode) SetDefer

func (n *ErrorNode) SetDefer(node Node) *ErrorNode

func (*ErrorNode) Validate

func (n *ErrorNode) Validate() error

type ListNode

type ListNode struct {
	NodeType `json:"type"`

	// Body is the list of child nodes
	Body []Node `json:"body"`
}

ListNode serially executes a list of child nodes.

func NewListNode

func NewListNode() *ListNode

NewListNode returns a new ListNode.

func (*ListNode) Append

func (n *ListNode) Append(node Node) *ListNode

Append appens a child node to the list.

func (*ListNode) Validate

func (n *ListNode) Validate() error

type Node

type Node interface {
	Type() NodeType
	Validate() error
}

A Node is an element in the parse tree.

type NodeType

type NodeType string

NodeType identifies the type of a parse tree node.

func (NodeType) String

func (t NodeType) String() string

String returns the string value of the Node type.

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 ParallelNode

type ParallelNode struct {
	NodeType `json:"type"`

	Body  []Node `json:"body"`  // nodes for parallel evaluation.
	Limit int    `json:"limit"` // limit for parallel evaluation.
}

ParallelNode executes a list of child nodes in parallel.

func NewParallelNode

func NewParallelNode() *ParallelNode

func (*ParallelNode) Append

func (n *ParallelNode) Append(node Node) *ParallelNode

func (*ParallelNode) SetLimit

func (n *ParallelNode) SetLimit(limit int) *ParallelNode

func (*ParallelNode) Validate

func (n *ParallelNode) Validate() error

type RecoverNode

type RecoverNode struct {
	NodeType `json:"type"`

	Body Node `json:"body"` // evaluate node and catch all errors.
}

func NewRecoverNode

func NewRecoverNode() *RecoverNode

func (*RecoverNode) SetBody

func (n *RecoverNode) SetBody(node Node) *RecoverNode

func (*RecoverNode) Validate

func (n *RecoverNode) Validate() error

type RunNode

type RunNode struct {
	NodeType `json:"type"`

	Name   string `json:"name"`
	Detach bool   `json:"detach,omitempty"`
	Silent bool   `json:"silent,omitempty"`
}

func NewRunNode

func NewRunNode() *RunNode

func (*RunNode) SetDetach

func (n *RunNode) SetDetach(detach bool) *RunNode

func (*RunNode) SetName

func (n *RunNode) SetName(name string) *RunNode

func (*RunNode) SetSilent

func (n *RunNode) SetSilent(silent bool) *RunNode

func (*RunNode) Validate

func (n *RunNode) Validate() error

type Tree

type Tree struct {
	*ListNode // top-level Tree node
}

Tree is the intermediate representation of a pipeline.

func NewTree

func NewTree() *Tree

New allocates a new Tree.

func Parse

func Parse(data []byte) (*Tree, error)

Parse parses a JSON encoded Tree.

func (*Tree) MarshalJSON

func (t *Tree) MarshalJSON() ([]byte, error)

MarshalJSON implements the Marshaler interface and returns a JSON encoded representation of the Tree.

func (*Tree) UnmarshalJSON

func (t *Tree) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the Unmarshaler interface and returns a Tree from a JSON representation.

Jump to

Keyboard shortcuts

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