ast

package
v0.0.0-...-d03bbad Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2018 License: MIT Imports: 6 Imported by: 3

Documentation

Overview

Package ast implements the javascript Abstract Syntax Tree representation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsExpr

func IsExpr(node Node) bool

Types

type Bool

type Bool bool

func NewBool

func NewBool(a bool) Bool

func (Bool) Equal

func (a Bool) Equal(other Node) bool

func (Bool) String

func (a Bool) String() string

func (Bool) Type

func (Bool) Type() NodeType

func (Bool) Value

func (b Bool) Value() bool

type CallExpr

type CallExpr struct {
	Callee Node
	Args   []Node
}

func NewCallExpr

func NewCallExpr(callee Node, args []Node) *CallExpr

func (*CallExpr) Equal

func (c *CallExpr) Equal(other Node) bool

func (*CallExpr) String

func (c *CallExpr) String() string

func (*CallExpr) Type

func (c *CallExpr) Type() NodeType

type FunDecl

type FunDecl struct {
	Name Ident
	Args []Ident
	Body *Program
}

FunDecl is the syntatic function declaration

func NewFunDecl

func NewFunDecl(name Ident, args []Ident, body *Program) *FunDecl

NewFunDecl creates a new function declaration node.

func (*FunDecl) Equal

func (a *FunDecl) Equal(other Node) bool

func (*FunDecl) String

func (a *FunDecl) String() string

func (*FunDecl) Type

func (a *FunDecl) Type() NodeType

type Ident

type Ident utf16.Str

func NewIdent

func NewIdent(ident utf16.Str) Ident

func (Ident) Equal

func (an Ident) Equal(other Node) bool

func (Ident) String

func (an Ident) String() string

func (Ident) Type

func (_ Ident) Type() NodeType

type MemberExpr

type MemberExpr struct {
	Object   Node
	Property Ident
}

MemberExpr handles get of object's properties eg.: <object>.<property>

func NewMemberExpr

func NewMemberExpr(object Node, property Ident) *MemberExpr

func (*MemberExpr) Equal

func (m *MemberExpr) Equal(other Node) bool

func (*MemberExpr) String

func (m *MemberExpr) String() string

func (*MemberExpr) Type

func (m *MemberExpr) Type() NodeType

type Node

type Node interface {
	Type() NodeType
	String() string
	Equal(other Node) bool
}

All node types implement the Node interface

type NodeType

type NodeType int

Node type

const (
	NodeProgram NodeType = iota + 1
	NodeFunDecl
	NodeVarDecl
	NodeVarDecls

	NodeNumber
	NodeString
	NodeNull
	NodeUndefined
	NodeBool
	NodeUnaryExpr
	NodeMemberExpr
	NodeCallExpr
	NodeIdent
)

func (NodeType) String

func (t NodeType) String() string

type Null

type Null struct{}

func NewNull

func NewNull() Null

func (Null) Equal

func (Null) Equal(other Node) bool

func (Null) String

func (Null) String() string

func (Null) Type

func (Null) Type() NodeType

type Number

type Number float64

func NewIntNumber

func NewIntNumber(a int64) Number

func NewNumber

func NewNumber(a float64) Number

func (Number) Equal

func (a Number) Equal(other Node) bool

func (Number) String

func (a Number) String() string

TODO(i4k): Implements correct javascript number to string representation.

func (Number) Type

func (_ Number) Type() NodeType

func (Number) Value

func (a Number) Value() float64

type Program

type Program struct {
	Nodes []Node
}

Program Abstract Syntax Tree

func (*Program) Equal

func (p *Program) Equal(other Node) bool

func (*Program) String

func (p *Program) String() string

func (*Program) Type

func (_ *Program) Type() NodeType

type String

type String utf16.Str

func NewString

func NewString(a utf16.Str) String

func (String) Equal

func (s String) Equal(other Node) bool

func (String) String

func (s String) String() string

func (String) Type

func (String) Type() NodeType

type UnaryExpr

type UnaryExpr struct {
	Operator token.Type
	Operand  Node
}

UnaryExpr is a unary expression (-a, +a, ~a, and so on)

func NewUnaryExpr

func NewUnaryExpr(operator token.Type, operand Node) *UnaryExpr

func (*UnaryExpr) Equal

func (a *UnaryExpr) Equal(other Node) bool

func (*UnaryExpr) String

func (a *UnaryExpr) String() string

func (*UnaryExpr) Type

func (_ *UnaryExpr) Type() NodeType

type Undefined

type Undefined struct{}

func NewUndefined

func NewUndefined() Undefined

func (Undefined) Equal

func (Undefined) Equal(other Node) bool

func (Undefined) String

func (Undefined) String() string

func (Undefined) Type

func (Undefined) Type() NodeType

type VarDecl

type VarDecl struct {
	Name  Ident
	Value Node
}

func NewVarDecl

func NewVarDecl(name Ident, val Node) VarDecl

func (VarDecl) Equal

func (v VarDecl) Equal(other Node) bool

func (VarDecl) String

func (v VarDecl) String() string

func (VarDecl) Type

func (v VarDecl) Type() NodeType

type VarDecls

type VarDecls []VarDecl

func NewVarDecls

func NewVarDecls(vars ...VarDecl) VarDecls

func (VarDecls) Equal

func (v VarDecls) Equal(other Node) bool

func (VarDecls) String

func (v VarDecls) String() string

func (VarDecls) Type

func (v VarDecls) Type() NodeType

Jump to

Keyboard shortcuts

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