parse

package
v0.0.0-...-f21147f Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2019 License: MIT Imports: 8 Imported by: 5

Documentation

Index

Constants

View Source
const (
	UNA_SEGMENT_NAME         = "UNA"
	UNA_COMPONENT_DELIMITER  = ':'
	UNA_DATA_DELIMITER       = '+'
	UNA_DECIMAL              = '.'
	UNA_RELEASE_INDICATOR    = '?'
	UNA_REPETITION_DELIMITER = ' ' // This is really "reserved" in the spec.
	UNA_SEGMENT_TERMINATOR   = '\''
)

default values for the UNA segment. if no una segment is specified, then these are used

View Source
const (
	COMPONENT_DELIMITER_POS = iota
	DATA_DELIMITER_POS
	DECIMAL_POS
	RELEASE_INDICATOR_POS
	REPETITION_DELIMITER_POS
	SEGMENT_TERMINATOR_POS
)

Variables

View Source
var (
	// our reduce table
	REDUCETABLE = map[NodeType]map[token.TokenType]reduceFunc{
		NodeText: map[token.TokenType]reduceFunc{
			token.COMPONENT_DELIMITER:  reduceTextComponent,
			token.REPETITION_DELIMITER: reduceTextRepetition,
			token.DATA_DELIMITER:       reduceTextData,
		},

		NodeComponent: map[token.TokenType]reduceFunc{
			token.TEXT:                 reduceComponentText,
			token.DATA_DELIMITER:       reduceComponentData,
			token.REPETITION_DELIMITER: reduceComponentRepetition,
		},

		NodeRepetition: map[token.TokenType]reduceFunc{
			token.TEXT:                 reduceRepetitionText,
			token.DATA_DELIMITER:       reduceRepetitionData,
			token.COMPONENT_DELIMITER:  reduceRepetitionComponent,
			token.REPETITION_DELIMITER: reduceRepetitionRepetition,
		},
	}
)

Functions

This section is empty.

Types

type ComponentNode

type ComponentNode struct {
	NodeType
	List *ListNode
}

ComponentNode holds a list of nodes that are components of one another. Like a person's first and last name can be components.

func (*ComponentNode) String

func (c *ComponentNode) String() string

type DataNode

type DataNode struct {
	NodeType
	Node Node
}

DataNode holds a single node. It's basically an encapsulation to follow the spec.

func (*DataNode) String

func (c *DataNode) String() string

type HeaderNode

type HeaderNode struct {
	NodeType
	SegmentName Node
	Text        Node
}

A header node holds the UNA header and the configuration text.

func (*HeaderNode) String

func (h *HeaderNode) String() string

type ListNode

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

ListNode holds a sequence of nodes.

func Parse

func Parse(text string) (listnode *ListNode, err error)

Parses the text and returns a parse tree.

func (*ListNode) String

func (l *ListNode) String() string

Returns a flat string of the ListNode.

func (*ListNode) StringDelim

func (l *ListNode) StringDelim(delim string) string

Prints out the nodes with a delimiter.

type Node

type Node interface {
	Type() NodeType
	String() string
}

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 NodeStack

type NodeStack []Node

type NodeType

type NodeType int

NodeType identifies the type of a parse tree node.

const (
	NodeList       NodeType = iota // A list of Nodes.
	NodeHeader                     // The UNA header node.
	NodeSegment                    // A segment node.
	NodeData                       // A data node.
	NodeText                       // Plain text.
	NodeComponent                  // A component node.
	NodeRepetition                 // A repetition node.
)

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 RepetitionNode

type RepetitionNode struct {
	NodeType
	List *ListNode
}

RepetitionNode holds a list of nodes that are repetitions. For example, a start and end date could be repetitions.

func (*RepetitionNode) String

func (r *RepetitionNode) String() string

type SegmentNode

type SegmentNode struct {
	NodeType
	List *ListNode
}

SegmentNode holds a list of nodes (only DataNodes) that signify an entire segment. The segment name is specified in the first DataNode of the list.

func (*SegmentNode) String

func (s *SegmentNode) 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 {
	Root *ListNode // top-level root of the tree.
	// contains filtered or unexported fields
}

Tree is the representation of a single parsed template.

Jump to

Keyboard shortcuts

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