ast

package
v0.0.0-...-59cec5b Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2022 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 {
	List    []*Field
	Opening Position
}

type ArrayDeclExpr

type ArrayDeclExpr struct {
	List []Expr
	Pos  Position
}

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 {
	Left     Expr
	Right    Expr
	Operator Type
}

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 {
	Label string
	Pos   Position
}

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 {
	Expression Expr
	Stmts      []Stmt
	Pos        Position
}

func (*CaseBlock) Position

func (i *CaseBlock) Position() Position

type ClassDeclStmt

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

func (*ClassDeclStmt) Position

func (c *ClassDeclStmt) Position() Position

type Comment

type Comment struct {
	Str       string
	Pos       Position
	MultiLine bool
}

func (*Comment) Position

func (i *Comment) Position() Position

type ConstantExpr

type ConstantExpr struct {
	Value string
	Pos   Position
	Kind  Type
}

func (*ConstantExpr) Position

func (i *ConstantExpr) Position() Position

type ContinueStmt

type ContinueStmt struct {
	Label string
	Pos   Position
}

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 {
	Name     string
	Values   []EnumValue
	Pos      Position
	Exported bool
}

func (*EnumDeclStmt) Position

func (i *EnumDeclStmt) Position() Position

type EnumValue

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

type Expr

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

type Field

type Field struct {
	Name     string
	Pos      Position
	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 {
	Expression   Expr
	Step         Stmt
	InExpression Expr
	OfExpression Expr
	Body         *BlockStmt

	Declaration []Stmt
	Pos         Position
	// 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 {
	Args     *Arguments
	Body     *BlockStmt
	Pos      Position
	Variadic bool
}

FuncDeclExpr is a function as a value expression

func (*FuncDeclExpr) Position

func (i *FuncDeclExpr) Position() Position

type FuncDeclStmt

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

func (*FuncDeclStmt) Position

func (i *FuncDeclStmt) Position() Position

type IdentExpr

type IdentExpr struct {
	Name string
	Pos  Position
}

func (*IdentExpr) Position

func (i *IdentExpr) Position() Position

type IfBlock

type IfBlock struct {
	Condition Expr
	Body      *BlockStmt
}

type IfStmt

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

func (*IfStmt) Position

func (i *IfStmt) Position() Position

type ImportStmt

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

func (*ImportStmt) Position

func (i *ImportStmt) Position() Position

type IncStmt

type IncStmt struct {
	Left     Expr
	Operator Type
}

func (*IncStmt) Position

func (i *IncStmt) Position() Position

type IndexAsignStmt

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

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 {
	Value   Expr
	Key     string
	KeyType Type
}

type Lexer

type Lexer struct {
	Tokens []*Token
	Pos    Position
	// 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 {
	List []KeyValue
	Pos  Position
}

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 {
	Value Expr
	Pos   Position
}

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 {
	Expression Expr
	Default    *CaseBlock

	Blocks []*CaseBlock
	Pos    Position
	// 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 {
	Value Expr
	Pos   Position
}

func (*ThrowStmt) Position

func (i *ThrowStmt) Position() Position

type Token

type Token struct {
	Str  string
	Pos  Position
	Type Type
}

func (Token) String

func (t Token) String() string

type TryStmt

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

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     // :

	LAMBDA // =>

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

	LET
	VAR
	CONST
	FUNCTION
	ENUM
	NULL
	UNDEFINED
	INTERFACE
	EXPORT
	DECLARE

	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 {
	Operand  Expr
	Pos      Position
	Operator Type
}

func (*UnaryExpr) Position

func (i *UnaryExpr) Position() Position

type VarDeclStmt

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

func (*VarDeclStmt) Position

func (i *VarDeclStmt) Position() Position

type WhileStmt

type WhileStmt struct {
	Expression Expr
	Body       *BlockStmt

	Pos Position
	// 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