ast

package
v0.0.0-...-6c293db Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2021 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Print

func Print(v interface{}) error

func Sprint

func Sprint(v interface{}) (string, error)

Types

type Arguments

type Arguments struct {
	Opening Position
	List    []*Field
}

type ArrayDeclExpr

type ArrayDeclExpr struct {
	Pos  Position
	List []Expr
}

func (*ArrayDeclExpr) Position

func (i *ArrayDeclExpr) Position() Position

type AsignStmt

type AsignStmt struct {
	Left  Expr
	Value Expr
}

func (*AsignStmt) Position

func (i *AsignStmt) Position() Position

type BinaryExpr

type BinaryExpr struct {
	Operator Type
	Left     Expr
	Right    Expr
}

func (*BinaryExpr) Position

func (i *BinaryExpr) Position() Position

type BlockStmt

type BlockStmt struct {
	Lbrace Position // Position of "{"
	List   []Stmt
	Rbrace Position // Position of "}"
}

A BlockStmt node represents a braced statement list.

func (*BlockStmt) Position

func (i *BlockStmt) Position() Position

type BreakStmt

type BreakStmt struct {
	Pos   Position
	Label string
}

func (*BreakStmt) Position

func (i *BreakStmt) Position() Position

type BreakTarget

type BreakTarget interface {
	Label() string
	BreakPC() int
}

type CallExpr

type CallExpr struct {
	Ident    Expr
	Lparen   Position
	Args     []Expr
	Rparen   Position
	Spread   bool // if the last argument has a spread operator
	Optional bool // Optional chaining ?.
	First    bool // if it is the first part of the expression
}

func (*CallExpr) Position

func (i *CallExpr) Position() Position

type CallStmt

type CallStmt struct {
	*CallExpr
}

type CaseBlock

type CaseBlock struct {
	Pos        Position
	Expression Expr
	Stmts      []Stmt
}

func (*CaseBlock) Position

func (i *CaseBlock) Position() Position

type ClassDeclStmt

type ClassDeclStmt struct {
	Pos        Position
	Name       string
	Exported   bool
	Fields     []*VarDeclStmt
	Functions  []*FuncDeclStmt
	Getters    []*FuncDeclStmt
	Setters    []*FuncDeclStmt
	Attributes []string
}

func (*ClassDeclStmt) Position

func (c *ClassDeclStmt) Position() Position

type Comment

type Comment struct {
	MultiLine bool
	Str       string
	Pos       Position
}

func (*Comment) Position

func (i *Comment) Position() Position

type ConstantExpr

type ConstantExpr struct {
	Pos   Position
	Kind  Type
	Value string
}

func (*ConstantExpr) Position

func (i *ConstantExpr) Position() Position

type ContinueStmt

type ContinueStmt struct {
	Pos   Position
	Label string
}

func (*ContinueStmt) Position

func (i *ContinueStmt) Position() Position

type ContinueTarget

type ContinueTarget interface {
	Label() string
	ContinuePC() int
}

type Decl

type Decl interface {
	Node
	// contains filtered or unexported methods
}

type DeleteStmt

type DeleteStmt struct {
	Object string
	Field  string
	Pos    Position
}

func (*DeleteStmt) Position

func (i *DeleteStmt) Position() Position

type EnumDeclStmt

type EnumDeclStmt struct {
	Pos      Position
	Name     string
	Values   []EnumValue
	Exported bool
}

func (*EnumDeclStmt) Position

func (i *EnumDeclStmt) Position() Position

type EnumValue

type EnumValue struct {
	Pos   Position
	Name  string
	Kind  Type
	Value *ConstantExpr
}

type Expr

type Expr interface {
	Node
	// contains filtered or unexported methods
}

type Field

type Field struct {
	Pos      Position
	Name     string
	Optional bool
}

type File

type File struct {
	Path       string
	Stms       []Stmt
	Global     []Stmt
	Comments   []*Comment
	Imports    []*ImportStmt
	Attributes []string
}

func (*File) Import

func (f *File) Import(alias string) *ImportStmt

type ForStmt

type ForStmt struct {
	Pos          Position
	Declaration  []Stmt
	Expression   Expr
	Step         Stmt
	InExpression Expr
	OfExpression Expr
	Body         *BlockStmt
	// contains filtered or unexported fields
}

func (*ForStmt) BreakPC

func (i *ForStmt) BreakPC() int

func (*ForStmt) ContinuePC

func (i *ForStmt) ContinuePC() int

func (*ForStmt) Label

func (i *ForStmt) Label() string

func (*ForStmt) Position

func (i *ForStmt) Position() Position

func (*ForStmt) SetBreakPC

func (i *ForStmt) SetBreakPC(pc int)

func (*ForStmt) SetContinuePC

func (i *ForStmt) SetContinuePC(pc int)

func (*ForStmt) SetLabel

func (i *ForStmt) SetLabel(s string)

type FuncDeclExpr

type FuncDeclExpr struct {
	Pos      Position
	Args     *Arguments
	Variadic bool
	Body     *BlockStmt
}

FuncDeclExpr is a function as a value expression

func (*FuncDeclExpr) Position

func (i *FuncDeclExpr) Position() Position

type FuncDeclStmt

type FuncDeclStmt struct {
	Pos        Position
	Args       *Arguments
	Variadic   bool
	Body       *BlockStmt
	Name       string
	Exported   bool
	Lambda     bool
	Attributes []string
	Comment    *Comment

	// a Object value means that it is a method of that object
	ReceiverType string
}

func (*FuncDeclStmt) Position

func (i *FuncDeclStmt) Position() Position

type IdentExpr

type IdentExpr struct {
	Pos  Position
	Name string
}

func (*IdentExpr) Position

func (i *IdentExpr) Position() Position

type IfBlock

type IfBlock struct {
	Condition Expr
	Body      *BlockStmt
}

type IfStmt

type IfStmt struct {
	Pos      Position
	IfBlocks []*IfBlock
	Else     *BlockStmt
}

func (*IfStmt) Position

func (i *IfStmt) Position() Position

type ImportStmt

type ImportStmt struct {
	Pos     Position
	Alias   string
	Path    string
	AbsPath string
}

func (*ImportStmt) Position

func (i *ImportStmt) Position() Position

type IncStmt

type IncStmt struct {
	Operator Type
	Left     Expr
}

func (*IncStmt) Position

func (i *IncStmt) Position() Position

type IndexAsignStmt

type IndexAsignStmt struct {
	Pos       Position
	Name      string
	IndexExpr Expr
	Value     Expr
}

func (*IndexAsignStmt) Position

func (i *IndexAsignStmt) Position() Position

type IndexExpr

type IndexExpr struct {
	Left     Expr
	Lbrack   Position
	Index    Expr
	Rbrack   Position
	Optional bool // Optional chaining ?.
	First    bool // if it is the first part of the expression
}

func (*IndexExpr) Position

func (i *IndexExpr) Position() Position

type KeyValue

type KeyValue struct {
	Key     string
	KeyType Type
	Value   Expr
}

type Lexer

type Lexer struct {
	Pos Position

	Tokens []*Token
	// contains filtered or unexported fields
}

func New

func New(reader io.Reader, fileName string) *Lexer

func (*Lexer) Run

func (l *Lexer) Run() error

type MapDeclExpr

type MapDeclExpr struct {
	Pos  Position
	List []KeyValue
}

func (*MapDeclExpr) Position

func (i *MapDeclExpr) Position() Position

type NewInstanceExpr

type NewInstanceExpr struct {
	Name   Expr
	Lparen Position
	Args   []Expr
	Rparen Position
	Spread bool // if the last argument has a spread operator
}

func (*NewInstanceExpr) Position

func (i *NewInstanceExpr) Position() Position

type Node

type Node interface {
	Position() Position
}

type NodeError

type NodeError interface {
	ErrorMessage() string
	Position() Position
	Error() string
}

type Position

type Position struct {
	FileName string
	Line     int
	Column   int
}

func (Position) String

func (p Position) String() string

type Printer

type Printer struct {
	Positions bool
}

A helper to inspect the Module

func (*Printer) Print

func (p *Printer) Print(v interface{}) error

func (*Printer) Printf

func (p *Printer) Printf(w io.Writer, v interface{}) error

type Program

type Program struct {
	File     *File
	Modules  map[string]*File
	BasePath string
}

type RegisterExpr

type RegisterExpr struct {
	Pos Position
	Reg int
}

RegisterExpr is just the index of a local register. Is for internal use only, when you need to pass directly the result of a compiled expression of any kind.

func (*RegisterExpr) Position

func (i *RegisterExpr) Position() Position

type ReturnStmt

type ReturnStmt struct {
	Pos   Position
	Value Expr
}

func (*ReturnStmt) Position

func (i *ReturnStmt) Position() Position

type SelectorExpr

type SelectorExpr struct {
	X        Expr       // expression
	Sel      *IdentExpr // field selector
	Optional bool       // Optional chaining ?.
	First    bool       // if it is the first part of the expression
}

func (*SelectorExpr) Position

func (i *SelectorExpr) Position() Position

type Stmt

type Stmt interface {
	Node
	// contains filtered or unexported methods
}

type SwitchStmt

type SwitchStmt struct {
	Pos        Position
	Expression Expr
	Blocks     []*CaseBlock
	Default    *CaseBlock
	// contains filtered or unexported fields
}

func (*SwitchStmt) BreakPC

func (i *SwitchStmt) BreakPC() int

func (*SwitchStmt) Label

func (i *SwitchStmt) Label() string

func (*SwitchStmt) Position

func (i *SwitchStmt) Position() Position

func (*SwitchStmt) SetBreakPC

func (i *SwitchStmt) SetBreakPC(pc int)

func (*SwitchStmt) SetContinuePC

func (i *SwitchStmt) SetContinuePC(pc int)

func (*SwitchStmt) SetLabel

func (i *SwitchStmt) SetLabel(s string)

type TailCallStmt

type TailCallStmt struct {
	*CallExpr
}

type Target

type Target interface {
	Label() string
}

type TernaryExpr

type TernaryExpr struct {
	Condition Expr
	Left      Expr
	Right     Expr
}

func (*TernaryExpr) Position

func (i *TernaryExpr) Position() Position

type ThrowStmt

type ThrowStmt struct {
	Pos   Position
	Value Expr
}

func (*ThrowStmt) Position

func (i *ThrowStmt) Position() Position

type Token

type Token struct {
	Type Type
	Str  string
	Pos  Position
}

func (Token) String

func (t Token) String() string

type TryStmt

type TryStmt struct {
	Pos        Position
	Body       *BlockStmt
	CatchIdent *VarDeclStmt
	Catch      *BlockStmt
	Finally    *BlockStmt
}

func (*TryStmt) Position

func (i *TryStmt) Position() Position

type Type

type Type byte
const (
	ERROR Type = iota
	EOF
	COMMENT
	MULTILINE_COMMENT
	ATTRIBUTE

	// Identifiers and basic type literals
	// (these tokens stand for classes of literals)
	IDENT  // main
	INT    // 12345
	HEX    // 0xFF
	FLOAT  // 123.45
	RUNE   // 'a'
	STRING // "abc"

	// Operators and delimiters
	ADD // +
	SUB // -
	MUL // *
	DIV // /
	MOD // %

	AND // &
	BOR // | binary or
	XOR // ^
	LSH // << left shift
	RSH // >> right shift
	BNT // ~ bitwise not

	QUESTION // ?

	ADD_ASSIGN // +=
	SUB_ASSIGN // -=
	MUL_ASSIGN // *=
	DIV_ASSIGN // /=
	XOR_ASSIGN // ^=
	BOR_ASSIGN // |=
	MOD_ASSIGN // %=

	LAND // &&
	LOR  // ||
	NOR  // ??
	INC  // ++
	DEC  // --
	EXP  // **

	EQL    // ==
	SEQ    // ===
	NEQ    // !=
	SNE    // !==
	LSS    // <
	GTR    // >
	ASSIGN // =
	NOT    // !

	LEQ // <=
	GEQ // >=

	LPAREN // (
	LBRACK // [
	LBRACE // {
	COMMA  // ,
	PERIOD // .

	RPAREN    // )
	RBRACK    // ]
	RBRACE    // }
	SEMICOLON // ;
	COLON     // :

	DECL   // :=
	LAMBDA // =>

	// Keywords
	BREAK
	CONTINUE
	IF
	ELSE
	FOR
	WHILE
	RETURN
	IMPORT
	SWITCH
	CASE
	DEFAULT

	LET
	VAR
	CONST
	FUNCTION
	ENUM
	NULL
	UNDEFINED
	INTERFACE
	EXPORT

	NEW
	CLASS

	TRUE
	FALSE

	TRY
	CATCH
	FINALLY
	THROW

	TYPEOF
	DELETE
)

func (Type) String

func (i Type) String() string

type TypeofExpr

type TypeofExpr struct {
	Expr Expr
}

func (*TypeofExpr) Position

func (i *TypeofExpr) Position() Position

type UnaryExpr

type UnaryExpr struct {
	Pos      Position
	Operator Type
	Operand  Expr
}

func (*UnaryExpr) Position

func (i *UnaryExpr) Position() Position

type VarDeclStmt

type VarDeclStmt struct {
	Pos      Position
	Name     string
	Value    Expr
	Exported bool
	Const    bool
}

func (*VarDeclStmt) Position

func (i *VarDeclStmt) Position() Position

type WhileStmt

type WhileStmt struct {
	Pos        Position
	Expression Expr
	Body       *BlockStmt
	// contains filtered or unexported fields
}

func (*WhileStmt) BreakPC

func (i *WhileStmt) BreakPC() int

func (*WhileStmt) ContinuePC

func (i *WhileStmt) ContinuePC() int

func (*WhileStmt) Label

func (i *WhileStmt) Label() string

func (*WhileStmt) Position

func (i *WhileStmt) Position() Position

func (*WhileStmt) SetBreakPC

func (i *WhileStmt) SetBreakPC(pc int)

func (*WhileStmt) SetContinuePC

func (i *WhileStmt) SetContinuePC(pc int)

func (*WhileStmt) SetLabel

func (i *WhileStmt) SetLabel(s string)

Jump to

Keyboard shortcuts

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