sdk: github.com/bblfsh/sdk/uast/nodes Index | Files | Directories

package nodes

import "github.com/bblfsh/sdk/uast/nodes"

Index

Package Files

external.go hash.go iter.go node.go

Constants

const (
    IterAny = IterOrder(iota)
    PreOrder
    PostOrder
    LevelOrder
)
const (
    KindNil = Kind(1 << iota)
    KindObject
    KindArray
    KindString
    KindInt
    KindUint
    KindFloat
    KindBool
)
const (
    KindsValues    = KindString | KindInt | KindUint | KindFloat | KindBool
    KindsComposite = KindObject | KindArray
    KindsNotNil    = KindsComposite | KindsValues
    KindsAny       = KindNil | KindsNotNil
)
const HashSize = sha256.Size

HashSize is the size of hash used for nodes.

Variables

var DefaultHasher = NewHasher()

func ChildrenCount Uses

func ChildrenCount(n Node) int

ChildrenCount reports the number of immediate children of n. If n is an Array this is the length of the array. If n is an Object, each object in a field of n counts as one child and each array is counted as its length.

func Count Uses

func Count(root External, kinds Kind) int

Count returns a number of nodes with given kinds.

func Equal Uses

func Equal(n1, n2 External) bool

Equal compares two subtrees. Equality is checked by value (deep), not by reference.

func NodeEqual Uses

func NodeEqual(n1, n2 Node) bool

NodeEqual compares two subtrees. Equality is checked by value (deep), not by reference.

func Same Uses

func Same(n1, n2 External) bool

Same check if two nodes represent exactly the same node. This usually means compare nodes by pointers.

func ToString Uses

func ToString(v Value) string

ToString converts a value to a string.

func WalkPreOrder Uses

func WalkPreOrder(root Node, walk func(Node) bool)

WalkPreOrder visits all nodes of the tree in pre-order.

func WalkPreOrderExt Uses

func WalkPreOrderExt(root External, walk func(External) bool)

WalkPreOrderExt visits all nodes of the tree in pre-order.

type Array Uses

type Array []Node

Array is an ordered list of nodes.

func (Array) Clone Uses

func (m Array) Clone() Node

Clone returns a deep copy of an Array.

func (Array) CloneList Uses

func (m Array) CloneList() Array

CloneList creates a copy of an Array without copying it's elements.

func (Array) Equal Uses

func (m Array) Equal(n External) bool

func (Array) EqualArray Uses

func (m Array) EqualArray(m2 Array) bool

func (Array) Kind Uses

func (Array) Kind() Kind

func (Array) Native Uses

func (m Array) Native() interface{}

Native converts an array to a generic Go slice type ([]interface{}).

func (Array) SameAs Uses

func (m Array) SameAs(n External) bool

func (*Array) SetNode Uses

func (m *Array) SetNode(n Node) error

func (Array) Size Uses

func (m Array) Size() int

func (Array) Value Uses

func (Array) Value() Value

func (Array) ValueAt Uses

func (m Array) ValueAt(i int) External

type Bool Uses

type Bool bool

Bool is a boolean value used in tree fields.

func (Bool) Clone Uses

func (v Bool) Clone() Node

Clone returns a copy of the value.

func (Bool) Equal Uses

func (v Bool) Equal(n External) bool

func (Bool) Kind Uses

func (Bool) Kind() Kind

func (Bool) Native Uses

func (v Bool) Native() interface{}

Native converts the value to a bool.

func (Bool) SameAs Uses

func (v Bool) SameAs(n External) bool

func (*Bool) SetNode Uses

func (v *Bool) SetNode(n Node) error

func (Bool) Value Uses

func (v Bool) Value() Value

type Comparable Uses

type Comparable interface {
    // contains filtered or unexported methods
}

Comparable is an interface for comparable values that are guaranteed to be safely used as map keys.

func UniqueKey Uses

func UniqueKey(n Node) Comparable

UniqueKey returns a unique key of the node in the current tree. The key can be used in maps.

type Empty Uses

type Empty struct{}

func (Empty) Next Uses

func (Empty) Next() bool

func (Empty) Node Uses

func (Empty) Node() External

type External Uses

type External interface {
    // Kind returns a node kind.
    Kind() Kind
    // Value returns a primitive value of the node or nil if node is not a value.
    Value() Value
    // SameAs check if the node is exactly the same node as n2. This usually means checking node pointers.
    SameAs(n2 External) bool
}

External is a node interface that can be implemented by other packages.

type ExternalArray Uses

type ExternalArray interface {
    External
    // Size returns the number of child nodes.
    Size() int
    // ValueAt returns a array value by an index.
    ValueAt(i int) External
}

ExternalArray is an analog of Array type.

type ExternalObject Uses

type ExternalObject interface {
    External
    // Size returns the number of fields in an object.
    Size() int
    // Keys returns a sorted list of keys (object field names).
    Keys() []string
    // ValueAt returns an object field by key. It returns false if key does not exist.
    ValueAt(key string) (External, bool)
}

ExternalObject is an analog of Object type.

type Float Uses

type Float float64

Float is a floating point value used in tree fields.

func (Float) Clone Uses

func (v Float) Clone() Node

Clone returns a copy of the value.

func (Float) Equal Uses

func (v Float) Equal(n External) bool

func (Float) Kind Uses

func (Float) Kind() Kind

func (Float) Native Uses

func (v Float) Native() interface{}

Native converts the value to a float64.

func (Float) SameAs Uses

func (v Float) SameAs(n External) bool

func (*Float) SetNode Uses

func (v *Float) SetNode(n Node) error

func (Float) Value Uses

func (v Float) Value() Value

type Hash Uses

type Hash [HashSize]byte

func HashOf Uses

func HashOf(n External) Hash

HashOf computes a hash of a node with all it's children. Shorthand for DefaultHasher.HashOf with default settings.

type Hasher Uses

type Hasher struct {
    // KeyFilter allows to skip field in objects by returning false from the function.
    // Hash will still reflect the presence or absence of these key, but it won't hash a value of that field.
    KeyFilter func(key string) bool
}

Hasher allows to configure node hashing.

func NewHasher Uses

func NewHasher() *Hasher

NewHasher creates a new hashing config with default options.

func (*Hasher) HashOf Uses

func (h *Hasher) HashOf(n External) Hash

HashOf computes a hash of a node with all it's children. Caller should not rely on a specific hash value, since the hash size and the algorithm might change.

func (*Hasher) HashTo Uses

func (h *Hasher) HashTo(hash hash.Hash, n External) error

HashTo hashes the node with a custom hash function. See HashOf for details.

type Int Uses

type Int int64

Int is a integer value used in tree fields.

func (Int) Clone Uses

func (v Int) Clone() Node

Clone returns a copy of the value.

func (Int) Equal Uses

func (v Int) Equal(n External) bool

func (Int) Kind Uses

func (Int) Kind() Kind

func (Int) Native Uses

func (v Int) Native() interface{}

Native converts the value to an int64.

func (Int) SameAs Uses

func (v Int) SameAs(n External) bool

func (*Int) SetNode Uses

func (v *Int) SetNode(n Node) error

func (Int) Value Uses

func (v Int) Value() Value

type IterOrder Uses

type IterOrder int

type Iterator Uses

type Iterator interface {
    // Next advances an iterator.
    Next() bool
    // Node returns a current node.
    Node() External
}

func NewIterator Uses

func NewIterator(root External, order IterOrder) Iterator

type Kind Uses

type Kind int

Kind is a node kind.

func KindOf Uses

func KindOf(n External) Kind

KindOf returns a kind of the node.

func (Kind) In Uses

func (k Kind) In(k2 Kind) bool

func (Kind) Split Uses

func (k Kind) Split() []Kind

func (Kind) String Uses

func (k Kind) String() string

type Node Uses

type Node interface {
    External
    // Clone creates a deep copy of the node.
    Clone() Node
    // Native returns a native Go type for this node.
    Native() interface{}
    // Equal checks if the node is equal to another node.
    // Equality is checked by value (deep), not by reference.
    Equal(n2 External) bool
    // contains filtered or unexported methods
}

Node is a generic interface for a tree structure.

Can be one of:

* Object
* Array
* Value

func Apply Uses

func Apply(root Node, apply func(n Node) (Node, bool)) (Node, bool)

Apply takes a root node and applies callback to each node of the tree recursively. Apply returns an old or a new node and a flag that indicates if node was changed or not. If callback returns true and a new node, Apply will make a copy of parent node and will replace an old value with a new one. It will make a copy of all parent nodes recursively in this case.

func ToNode Uses

func ToNode(o interface{}, fallback ToNodeFunc) (Node, error)

ToNode converts objects returned by schema-less encodings such as JSON to Node objects.

type NodePtr Uses

type NodePtr interface {
    Value
    SetNode(v Node) error
}

NodePtr is an assignable node pointer.

type Object Uses

type Object map[string]Node

Object is a representation of generic node with fields.

func (Object) Clone Uses

func (m Object) Clone() Node

Clone returns a deep copy of an Object.

func (Object) CloneObject Uses

func (m Object) CloneObject() Object

CloneObject clones this node only, without deep copy of field values.

func (Object) Equal Uses

func (m Object) Equal(n External) bool

func (Object) EqualObject Uses

func (m Object) EqualObject(m2 Object) bool

func (Object) Keys Uses

func (m Object) Keys() []string

Keys returns a sorted list of node keys.

func (Object) Kind Uses

func (Object) Kind() Kind

func (Object) Native Uses

func (m Object) Native() interface{}

Native converts an object to a generic Go map type (map[string]interface{}).

func (Object) SameAs Uses

func (m Object) SameAs(n External) bool

func (Object) Set Uses

func (m Object) Set(k string, v Node) Object

Set is a helper for setting node properties.

func (*Object) SetNode Uses

func (m *Object) SetNode(n Node) error

func (Object) Size Uses

func (m Object) Size() int

func (Object) Value Uses

func (Object) Value() Value

func (Object) ValueAt Uses

func (m Object) ValueAt(k string) (External, bool)

type String Uses

type String string

String is a string value used in tree fields.

func (String) Clone Uses

func (v String) Clone() Node

Clone returns a copy of the value.

func (String) Equal Uses

func (v String) Equal(n External) bool

func (String) Kind Uses

func (String) Kind() Kind

func (String) Native Uses

func (v String) Native() interface{}

Native converts the value to a string.

func (String) SameAs Uses

func (v String) SameAs(n External) bool

func (*String) SetNode Uses

func (v *String) SetNode(n Node) error

func (String) Value Uses

func (v String) Value() Value

type ToNodeFunc Uses

type ToNodeFunc func(interface{}) (Node, error)

type Uint Uses

type Uint uint64

Uint is a unsigned integer value used in tree fields.

func (Uint) Clone Uses

func (v Uint) Clone() Node

Clone returns a copy of the value.

func (Uint) Equal Uses

func (v Uint) Equal(n External) bool

func (Uint) Kind Uses

func (Uint) Kind() Kind

func (Uint) Native Uses

func (v Uint) Native() interface{}

Native converts the value to an int64.

func (Uint) SameAs Uses

func (v Uint) SameAs(n External) bool

func (*Uint) SetNode Uses

func (v *Uint) SetNode(n Node) error

func (Uint) Value Uses

func (v Uint) Value() Value

type Value Uses

type Value interface {
    Node
    Comparable
    // contains filtered or unexported methods
}

Value is a generic interface for primitive values.

Can be one of:

* String
* Int
* Uint
* Float
* Bool

Directories

PathSynopsis
nodesprotoPackage nodesproto is a generated protocol buffer package.
nodesproto/pio

Package nodes imports 10 packages (graph). Updated 2019-04-14. Refresh now. Tools for package owners.