uast

package
v2.0.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2018 License: GPL-3.0 Imports: 6 Imported by: 1

Documentation

Overview

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

Index

Constants

View Source
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

View Source
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

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

Functions

func LookupType

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

func NewObjectByType

func NewObjectByType(typ string) nodes.Object

func NewObjectByTypeOpt

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

func NewValue

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

func NodeAs

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

func RegisterPackage

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

func RoleList

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

RoleList converts a set of roles into a list node.

func RolesOf

func RolesOf(m nodes.Object) role.Roles

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

func ToNode

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

func TokenOf(m nodes.Object) string

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

func Tokens

func Tokens(n nodes.Node) []string

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

func TypeOf

func TypeOf(o interface{}) string

Types

type Alias added in v1.0.0

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

type Any

type Any interface{}

Any is an alias type for any UAST node.

type Argument added in v1.0.0

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

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

type Comment

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 added in v1.0.0

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

type FunctionGroup

type FunctionGroup Group

type FunctionType

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

type GenNode

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

type Group

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

type Identifier added in v1.0.0

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

type Import added in v1.0.0

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

type Position

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

func AsPosition(m nodes.Object) *Position

AsPosition transforms a generic AST node to a Position object.

func (Position) ToObject

func (p Position) ToObject() nodes.Object

ToObject converts Position to a generic AST node.

type Positions

type Positions map[string]Position

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

func PositionsOf

func PositionsOf(m nodes.Object) Positions

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

func (Positions) End

func (p Positions) End() *Position

func (Positions) Start

func (p Positions) Start() *Position

func (Positions) ToObject

func (p Positions) ToObject() nodes.Object

type QualifiedIdentifier

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

type RuntimeImport

type RuntimeImport Import

type RuntimeReImport

type RuntimeReImport RuntimeImport

type Scope added in v1.0.0

type Scope = Any

Scope is a temporary definition of a scope semantic type.

type String added in v1.0.0

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

Directories

Path Synopsis
nodesproto
Package nodesproto is a generated protocol buffer package.
Package nodesproto is a generated protocol buffer package.
Package role is a generated protocol buffer package.
Package role is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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