sdk.v2: gopkg.in/bblfsh/sdk.v2/uast Index | Files | Directories

package uast

import "gopkg.in/bblfsh/sdk.v2/uast"

Package uast defines a UAST (Universal Abstract Syntax Tree) representation and operations to manipulate them.

Index

Package Files

iter.go types.go uast.go

Constants

const (
    KeyType  = "@type"  // InternalType
    KeyToken = "@token" // Token
    KeyRoles = "@role"  // Roles, for representations see RoleList
    KeyPos   = "@pos"   // All positional information is stored in this field
)

Special field keys for nodes.Object

const (
    // NS is a namespace for the UAST types.
    NS  = "uast"

    // TypePosition is a node type for positional information in AST. See AsPosition.
    TypePosition = NS + ":Position"
    // TypePositions is a node type for a root node of positional information in AST. See AsPositions.
    TypePositions = NS + ":Positions"
    // TypeOperator is a node type for an operator AST node. See Operator.
    TypeOperator = NS + ":Operator"
    // KeyPosOff is a name for a Position object field that stores a bytes offset.
    KeyPosOff = "offset"
    // KeyPosLine is a name for a Position object field that stores a source line.
    KeyPosLine = "line"
    // KeyPosCol is a name for a Position object field that stores a source column.
    KeyPosCol = "col"

    KeyStart = "start" // StartPosition
    KeyEnd   = "end"   // EndPosition
)

Variables

var (
    ErrIncorrectType     = errors.NewKind("incorrect object type: %q, expected: %q")
    ErrTypeNotRegistered = errors.NewKind("type is not registered: %q")
)

func HashNoPos Uses

func HashNoPos(n nodes.External) nodes.Hash

HashNoPos hashes the node, but skips positional information.

func LookupType Uses

func LookupType(typ string) (reflect.Type, bool)

func NewObjectByType Uses

func NewObjectByType(typ string) nodes.Object

func NewObjectByTypeOpt Uses

func NewObjectByTypeOpt(typ string) (obj, opt nodes.Object)

func NewPositionalIterator Uses

func NewPositionalIterator(root nodes.External) nodes.Iterator

NewPositionalIterator creates a new iterator that enumerates all object nodes, sorting them by positions in the source file. Nodes with no positions will be enumerated last.

func NewValue Uses

func NewValue(typ string) (reflect.Value, error)

func NodeAs Uses

func NodeAs(n nodes.External, dst interface{}) error

func RegisterPackage Uses

func RegisterPackage(ns string, types ...interface{})

func RoleList Uses

func RoleList(roles ...role.Role) nodes.Array

RoleList converts a set of roles into a list node.

func RolesOf Uses

func RolesOf(m nodes.Object) role.Roles

RolesOf is a helper for getting node UAST roles (see KeyRoles).

func ToNode Uses

func ToNode(o interface{}) (nodes.Node, error)

ToNode converts objects returned by schema-less encodings such as JSON to Node objects. It also supports types from packages registered via RegisterPackage.

func TokenOf Uses

func TokenOf(m nodes.Object) string

TokenOf is a helper for getting node token (see KeyToken).

func Tokens Uses

func Tokens(n nodes.Node) []string

Tokens collects all tokens of the tree recursively (pre-order).

func TypeOf Uses

func TypeOf(o interface{}) string

type Alias Uses

type Alias struct {
    GenNode
    Name Identifier `json:"Name"`
    Node Any        `json:"Node"`
}

type Any Uses

type Any interface{}

Any is an alias type for any UAST node.

type Argument Uses

type Argument struct {
    GenNode
    Name        *Identifier `json:"Name"`
    Type        Any         `json:"Type"`
    Init        Any         `json:"Init"`
    Variadic    bool        `json:"Variadic"`
    MapVariadic bool        `json:"MapVariadic"`
    Receiver    bool        `json:"Receiver"`
}

type Block Uses

type Block struct {
    GenNode
    Statements []Any `json:"Statements"`
}

type Comment Uses

type Comment struct {
    GenNode
    Text   string `json:"Text"`
    Prefix string `json:"Prefix"`
    Suffix string `json:"Suffix"`
    Tab    string `json:"Tab"`
    Block  bool   `json:"Block"`
}

type Function Uses

type Function struct {
    GenNode
    Type FunctionType `json:"Type"`
    Body *Block       `json:"Body"`
}

type FunctionGroup Uses

type FunctionGroup Group

type FunctionType Uses

type FunctionType struct {
    GenNode
    Arguments []Argument `json:"Arguments"`
    Returns   []Argument `json:"Returns"`
}

type GenNode Uses

type GenNode struct {
    Positions Positions `json:"@pos,omitempty"`
}

type Group Uses

type Group struct {
    GenNode
    Nodes []Any `json:"Nodes"`
}

type Identifier Uses

type Identifier struct {
    GenNode
    Name string `json:"Name"`
}

type Import Uses

type Import struct {
    GenNode
    Path   Any   `json:"Path"`
    All    bool  `json:"All"`
    Names  []Any `json:"Names"`
    Target Scope `json:"Target"`
}

type InlineImport Uses

type InlineImport Import

type Position Uses

type Position struct {
    // Offset is the position as an absolute byte offset. It is a 0-based index.
    Offset uint32 `json:"offset"`
    // Line is the line number. It is a 1-based index.
    Line uint32 `json:"line"`
    // Col is the column number (the byte offset of the position relative to
    // a line. It is a 1-based index.
    Col uint32 `json:"col"`
}

Position represents a position in a source code file.

func AsPosition Uses

func AsPosition(m nodes.Object) *Position

AsPosition transforms a generic AST node to a Position object.

func (Position) HasLineCol Uses

func (p Position) HasLineCol() bool

func (Position) HasOffset Uses

func (p Position) HasOffset() bool

func (Position) Less Uses

func (p Position) Less(p2 Position) bool

func (Position) ToObject Uses

func (p Position) ToObject() nodes.Object

ToObject converts Position to a generic AST node.

func (Position) Valid Uses

func (p Position) Valid() bool

type Positions Uses

type Positions map[string]Position

Positions is a container object that stores all positional information for a node.

func PositionsOf Uses

func PositionsOf(m nodes.Object) Positions

PositionsOf returns an object with all positional information for a node.

func (Positions) End Uses

func (p Positions) End() *Position

End returns an end position of the node.

func (Positions) Keys Uses

func (p Positions) Keys() []string

Keys returns a sorted slice of position names.

func (Positions) Start Uses

func (p Positions) Start() *Position

Start returns a start position of the node.

func (Positions) ToObject Uses

func (p Positions) ToObject() nodes.Object

ToObject converts positions to a generic object.

type QualifiedIdentifier Uses

type QualifiedIdentifier struct {
    GenNode
    Names []Identifier `json:"Names"`
}

type RuntimeImport Uses

type RuntimeImport Import

type RuntimeReImport Uses

type RuntimeReImport RuntimeImport

type Scope Uses

type Scope = Any

Scope is a temporary definition of a scope semantic type.

type String Uses

type String struct {
    GenNode
    Value  string `json:"Value"`
    Format string `json:"Format"` // TODO: make an enum later
}

Directories

PathSynopsis
nodes
nodes/nodesprotoPackage nodesproto is a generated protocol buffer package.
nodes/nodesproto/pio
query
query/xpath
rolePackage role is a generated protocol buffer package.
transformer
transformer/positioner
viewer
yaml

Package uast imports 7 packages (graph) and is imported by 15 packages. Updated 2018-12-04. Refresh now. Tools for package owners.