ctree

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTreeTokenSource

func NewTreeTokenSource(tree Tree, tttype TreeTokenTypes) antlr.TokenStream

func NewTreeTokenSourceFromStart

func NewTreeTokenSourceFromStart(tree Tree, tttype TreeTokenTypes, start INode) antlr.TokenStream

func NewTree_MutableINodes

func NewTree_MutableINodes(name string, root INode) (Tree, INode)

Creates a tree that allow non pointer Inode. Client beware, do not mutate object or pass non keyable objects

Types

type Builder

type Builder interface {
	Add(n INode) Builder
	Down() Builder
	Up() Builder
	Build() Tree
	Current() INode
}

Fluent API for building a tree

func BuildTree

func BuildTree(name string, root INode) Builder

func BuildTree_MutableNodes

func BuildTree_MutableNodes(name string, root INode) Builder

type CallbackFunc

type CallbackFunc func(depth int, node INode) (more bool)

type Down

type Down struct{}

func (*Down) String

func (*Down) String() string

type Eof

type Eof struct{}

func (*Eof) String

func (*Eof) String() string

type INode

type INode interface {
}

INode, an interface{} type store in the tree. Tider then writing interface{} everywhere

type INodeIterator

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

func (*INodeIterator) HasNext

func (iter *INodeIterator) HasNext() bool

func (*INodeIterator) Next

func (iter *INodeIterator) Next() INode

func (*INodeIterator) String

func (iter *INodeIterator) String() string

type Iterator

type Iterator interface {
	HasNext() bool
	Next() INode
}

type PreOrderTreeIterator

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

func NewPreOrderTreeIterator

func NewPreOrderTreeIterator(tree Tree, node INode) *PreOrderTreeIterator

Constructs a preorder enumeration with the tree to traverse, and the starting node */

func (*PreOrderTreeIterator) HasNext

func (iter *PreOrderTreeIterator) HasNext() bool

INMIND It would be handy to get traversal information UP DOWN etc

func (*PreOrderTreeIterator) Next

func (iter *PreOrderTreeIterator) Next() INode

type Tree

type Tree interface {
	Name() string
	// Returns the root Inode of the tree
	Root() INode
	// Adds a child to the provided parent.
	// Returns true, nil if added successfully,
	// false, current parent if
	// the Inode already exists in the tree
	Add(parent INode, child INode) (success bool, otherParent INode)
	// Get the parent of the provided Inode
	Parent(child INode) (parent INode)
	// Depth first walk of the tree calling the provided function for each Inode visited
	Walk(CallbackFunc)

	// Children of parent
	Children(parent INode) []INode

	Size() int
	PathAsPosition(node INode) []int
	CommonAncestor(a, b INode) INode

	// Contains
	Contains(INode) bool

	TreeString() string
	DebugTreeString() string
	SExpr(start INode) string
}

func NewTree

func NewTree(name string, root INode) Tree

Create a new tree with a hidden root and return the root and the tree

type TreeNode

type TreeNode interface {
	StartToken() antlr.Token
	StopToken() antlr.Token
	GetTokenType() int
	String() string
	GetStop() int
	Val() interface{}
}

type TreeToken

type TreeToken struct {
	TType      int
	Start      int // optional return -1 if not implemented.
	Stop       int // optional return -1 if not implemented.
	TokenIndex int
}

func (*TreeToken) GetChannel

func (tt *TreeToken) GetChannel() int

func (*TreeToken) GetColumn

func (tt *TreeToken) GetColumn() int

func (*TreeToken) GetInputStream

func (tt *TreeToken) GetInputStream() antlr.CharStream

func (*TreeToken) GetLine

func (tt *TreeToken) GetLine() int

func (*TreeToken) GetSource

func (tt *TreeToken) GetSource() *antlr.TokenSourceCharStreamPair

func (*TreeToken) GetStart

func (tt *TreeToken) GetStart() int

func (*TreeToken) GetStop

func (tt *TreeToken) GetStop() int

func (*TreeToken) GetText

func (tt *TreeToken) GetText() string

func (*TreeToken) GetTokenIndex

func (tt *TreeToken) GetTokenIndex() int

func (*TreeToken) GetTokenSource

func (tt *TreeToken) GetTokenSource() antlr.TokenSource

func (*TreeToken) GetTokenType

func (t *TreeToken) GetTokenType() int

func (*TreeToken) SetText

func (tt *TreeToken) SetText(s string)

func (*TreeToken) SetTokenIndex

func (tt *TreeToken) SetTokenIndex(v int)

type TreeTokenSource

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

func (*TreeTokenSource) Consume

func (tts *TreeTokenSource) Consume()

func (*TreeTokenSource) Get

func (tts *TreeTokenSource) Get(index int) antlr.Token

func (*TreeTokenSource) GetAllText

func (tts *TreeTokenSource) GetAllText() string

func (*TreeTokenSource) GetSourceName

func (tts *TreeTokenSource) GetSourceName() string

func (*TreeTokenSource) GetTextFromInterval

func (tts *TreeTokenSource) GetTextFromInterval(*antlr.Interval) string

func (*TreeTokenSource) GetTextFromRuleContext

func (tts *TreeTokenSource) GetTextFromRuleContext(antlr.RuleContext) string

func (*TreeTokenSource) GetTextFromTokens

func (tts *TreeTokenSource) GetTextFromTokens(antlr.Token, antlr.Token) string

func (*TreeTokenSource) GetTokenSource

func (tts *TreeTokenSource) GetTokenSource() antlr.TokenSource

func (*TreeTokenSource) Index

func (tts *TreeTokenSource) Index() int

func (*TreeTokenSource) LA

func (tts *TreeTokenSource) LA(i int) int

func (*TreeTokenSource) LT

func (tts *TreeTokenSource) LT(k int) (ret antlr.Token)

func (*TreeTokenSource) Mark

func (tts *TreeTokenSource) Mark() int

same a common token

func (*TreeTokenSource) Release

func (tts *TreeTokenSource) Release(marker int)

func (*TreeTokenSource) Seek

func (tts *TreeTokenSource) Seek(index int)

func (*TreeTokenSource) SetTokenSource

func (tts *TreeTokenSource) SetTokenSource(antlr.TokenSource)

func (*TreeTokenSource) Size

func (tts *TreeTokenSource) Size() int

type TreeTokenTypes

type TreeTokenTypes interface {
	Eof() int
	Down() int
	Up() int
}

type Up

type Up struct{}

func (*Up) String

func (*Up) String() string

type WalkableBuilder

type WalkableBuilder interface {
	Add(n antlr.Token) WalkableBuilder
	AddNode(n antlr.Token, stop antlr.Token, ttype int, val interface{}) WalkableBuilder
	Down() WalkableBuilder
	Up() WalkableBuilder
	Build() Tree
	Current() antlr.Token
}

func NewBuild

func NewBuild(tree_name string, n antlr.Token, stop antlr.Token, ttype int, val interface{}) WalkableBuilder

func NewWalkableBuild

func NewWalkableBuild(name string, root antlr.Token) WalkableBuilder

Jump to

Keyboard shortcuts

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