ast

package
v0.0.0-...-804c98d Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array struct {
	Token    lexer.Token
	Elements []Expression
}

Array represents an array literal

func (*Array) Context

func (a *Array) Context() lexer.Context

Context implements Node for Array

func (*Array) Literal

func (a *Array) Literal()

Literal implements Literal for Array

func (*Array) String

func (a *Array) String() string

String implements Node for Array

func (*Array) TokenLiteral

func (a *Array) TokenLiteral() string

TokenLiteral implements Node for Array

type BlockStatement

type BlockStatement struct {
	Token      lexer.Token
	Statements []Statement
}

BlockStatement represents a block of statements surrounded by braces

func (*BlockStatement) Context

func (bs *BlockStatement) Context() lexer.Context

Context implements Node for BlockStatement

func (*BlockStatement) String

func (bs *BlockStatement) String() string

String implements Node for BlockStatement

func (*BlockStatement) TokenLiteral

func (bs *BlockStatement) TokenLiteral() string

TokenLiteral implements Node for BlockStatement

type Bool

type Bool struct {
	Token lexer.Token
	Inner bool
}

Bool represents a boolean literal in the Monkey AST

func (*Bool) Context

func (b *Bool) Context() lexer.Context

Context implements Node for Bool

func (*Bool) Literal

func (b *Bool) Literal()

Literal implements Literal for Bool

func (*Bool) String

func (b *Bool) String() string

TokenLiteral implements Node for Bool

func (*Bool) TokenLiteral

func (b *Bool) TokenLiteral() string

TokenLiteral implements Node for Bool

type Declaration

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

Declaration defines a top level declaration (e.g. class, fn)

type DotExpression

type DotExpression struct {
	Token lexer.Token
	// Left can be any expression
	Left Expression
	// Right can only be a function call or a field
	Right Expression
}

DotExpression defines a dot expression [EXPR].[EXPR]

func (*DotExpression) Context

func (de *DotExpression) Context() lexer.Context

Context implements Node for DotExpression

func (*DotExpression) String

func (de *DotExpression) String() string

String implements Node for DotExpression

func (*DotExpression) TokenLiteral

func (de *DotExpression) TokenLiteral() string

TokenLiteral implements Node for DotExpression

type ExprStatement

type ExprStatement struct {
	Token      lexer.Token
	Expression Expression
}

ExprStatement - represents a bare expression in Monkey

func (*ExprStatement) Context

func (es *ExprStatement) Context() lexer.Context

Context implements Node for ExprStatement

func (*ExprStatement) String

func (es *ExprStatement) String() string

func (*ExprStatement) TokenLiteral

func (es *ExprStatement) TokenLiteral() string

TokenLiteral - Implements Node for ExpressionStatement

type Expression

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

Expression defines an expression in Monkey Syntax

type Flt

type Flt struct {
	Token lexer.Token
	Inner float64
}

Flt represents a float literal in the Monkey AST

func (*Flt) Context

func (f *Flt) Context() lexer.Context

Context implements Node for Flt

func (*Flt) Literal

func (f *Flt) Literal()

Literal implements Literal for Flt

func (*Flt) String

func (f *Flt) String() string

func (*Flt) TokenLiteral

func (f *Flt) TokenLiteral() string

TokenLiteral implements Node for Flt

type FnLiteral

type FnLiteral struct {
	Token  lexer.Token
	Params []*Identifier
	Body   *BlockStatement
}

FnLiteral represents a function declaration in Monkey

func (*FnLiteral) Context

func (fl *FnLiteral) Context() lexer.Context

Context implements Node for FnLiteral

func (*FnLiteral) String

func (fl *FnLiteral) String() string

String implements Node for FnLiteral

func (*FnLiteral) TokenLiteral

func (fl *FnLiteral) TokenLiteral() string

TokenLiteral implements Node for FnLiteral

type FunctionCall

type FunctionCall struct {
	Token  lexer.Token
	Ident  Expression
	Params []Expression
}

FunctionCall defines a function call in Monkey

func (*FunctionCall) Context

func (fc *FunctionCall) Context() lexer.Context

Context implements Node for FunctionCall

func (*FunctionCall) String

func (fc *FunctionCall) String() string

String implements Node for FunctionCall

func (*FunctionCall) TokenLiteral

func (fc *FunctionCall) TokenLiteral() string

TokenLiteral implements Node for FunctionCall

type FunctionDecl

type FunctionDecl struct {
	Token  lexer.Token
	Name   *Identifier
	Params []*Identifier
	Body   *BlockStatement
}

FunctionDecl represents a function declaration

func (*FunctionDecl) Context

func (fd *FunctionDecl) Context() lexer.Context

Context implements Node for FunctionDecl

func (*FunctionDecl) String

func (fd *FunctionDecl) String() string

String implements Node for FunctionDecl

func (*FunctionDecl) TokenLiteral

func (fd *FunctionDecl) TokenLiteral() string

TokenLiteral implements Node for FunctionDecl

type Identifier

type Identifier struct {
	Token lexer.Token
	Value string
}

Identifier - represents a name bound to a function or a variable

func (*Identifier) Context

func (i *Identifier) Context() lexer.Context

Context implements Node for Identifier

func (*Identifier) String

func (i *Identifier) String() string

String - implements Node for Identifier

func (*Identifier) TokenLiteral

func (i *Identifier) TokenLiteral() string

TokenLiteral - implements Node for Identifier

type IfExpression

type IfExpression struct {
	Token       lexer.Token
	Condition   Expression
	Result      *BlockStatement
	Alternative Node //! I don't like using a Node here, find a better alternative

}

IfExpression represents an if statement/expr in Monkey

func (*IfExpression) Context

func (ie *IfExpression) Context() lexer.Context

Context implements Node for IfExpression

func (*IfExpression) String

func (ie *IfExpression) String() string

String implements Node for IfExpression

func (*IfExpression) TokenLiteral

func (ie *IfExpression) TokenLiteral() string

TokenLiteral implements Node for IfExpression

type IndexExpr

type IndexExpr struct {
	Token lexer.Token
	Left  Expression
	Index Expression
}

IndexExpr represents an index into an array or a map

func (*IndexExpr) Context

func (ie *IndexExpr) Context() lexer.Context

Context implements Node for IndexExpr

func (*IndexExpr) String

func (ie *IndexExpr) String() string

String implements Node for IndexExpr

func (*IndexExpr) TokenLiteral

func (ie *IndexExpr) TokenLiteral() string

TokenLiteral implements Node for IndexExpr

type InfixExpr

type InfixExpr struct {
	Token    lexer.Token
	Left     Expression
	Operator string
	Right    Expression
}

InfixExpr represents an expression with an infixed operator

func (*InfixExpr) Context

func (ie *InfixExpr) Context() lexer.Context

Context implements Node for InfixExpr

func (*InfixExpr) String

func (ie *InfixExpr) String() string

String implements Node InfixExpr

func (*InfixExpr) TokenLiteral

func (ie *InfixExpr) TokenLiteral() string

TokenLiteral implements Node for InfixExpr

type Int

type Int struct {
	Token lexer.Token
	Inner int64
}

Int represents an integer literal in the Monkey AST

func (*Int) Context

func (i *Int) Context() lexer.Context

Context implements Node for Int

func (*Int) Literal

func (i *Int) Literal()

Literal implements Literal for Int

func (*Int) String

func (i *Int) String() string

func (*Int) TokenLiteral

func (i *Int) TokenLiteral() string

TokenLiteral implements Node for Int

type LetStatement

type LetStatement struct {
	Token lexer.Token
	Name  *Identifier
	Value Expression
}

LetStatement - represents a let statement in the AST

func (*LetStatement) Context

func (ls *LetStatement) Context() lexer.Context

Context implements Node for LetStatement

func (*LetStatement) String

func (ls *LetStatement) String() string

func (*LetStatement) TokenLiteral

func (ls *LetStatement) TokenLiteral() string

TokenLiteral - Implements Node for LetStatement

type Literal

type Literal interface {
	Node
	Literal()
	String() string
}

Literal defines a literal in Monkey: string, int or float

type Map

type Map struct {
	Token    lexer.Token
	Elements map[Expression]Expression
}

Map represents a map literal

func (*Map) Context

func (m *Map) Context() lexer.Context

Context implements Node for Map

func (*Map) Literal

func (m *Map) Literal()

Literal implements Literal for Map

func (*Map) String

func (m *Map) String() string

String implements Node for Map

func (*Map) TokenLiteral

func (m *Map) TokenLiteral() string

TokenLiteral implements Node for Map

type Node

type Node interface {
	TokenLiteral() string
	Context() lexer.Context
	String() string
}

Node defines the general behaviour for a node in the AST

type PrefixExpr

type PrefixExpr struct {
	Token    lexer.Token
	Operator string
	Right    Expression
}

PrefixExpr represents a prefixed expression, such as ! or -

func (*PrefixExpr) Context

func (pe *PrefixExpr) Context() lexer.Context

Context implements Node for PrefixExpr

func (*PrefixExpr) String

func (pe *PrefixExpr) String() string

String implements Node for PrefixExpr

func (*PrefixExpr) TokenLiteral

func (pe *PrefixExpr) TokenLiteral() string

TokenLiteral implements Node for PrefixExpr

type Program

type Program struct {
	Statements []Statement
	Functions  []*FunctionDecl
}

Program represents the entire parsed program

func (*Program) Context

func (p *Program) Context() lexer.Context

Context implements Node for Program

func (*Program) String

func (p *Program) String() string

func (*Program) TokenLiteral

func (p *Program) TokenLiteral() string

TokenLiteral implements Node for string

type ReturnStatement

type ReturnStatement struct {
	Token lexer.Token
	Value Expression
}

ReturnStatement - represents a return statement in the AST

func (*ReturnStatement) Context

func (rs *ReturnStatement) Context() lexer.Context

Context implements Node for ReturnStatement

func (*ReturnStatement) String

func (rs *ReturnStatement) String() string

func (*ReturnStatement) TokenLiteral

func (rs *ReturnStatement) TokenLiteral() string

TokenLiteral - Implements Node for ReturnStatement

type Statement

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

Statement defines a statement in Monkey syntax

type Str

type Str struct {
	Token lexer.Token
	Inner string
}

Str represents a string literal in the Monkey AST

func (*Str) Context

func (s *Str) Context() lexer.Context

Context implements Node for Str

func (*Str) Literal

func (s *Str) Literal()

Literal implements Literal for Str

func (*Str) String

func (s *Str) String() string

func (*Str) TokenLiteral

func (s *Str) TokenLiteral() string

TokenLiteral implements Node for Str

type WhileStatement

type WhileStatement struct {
	Token     lexer.Token
	Condition Expression
	Body      *BlockStatement
}

WhileStatement represents a while loop

func (*WhileStatement) Context

func (ws *WhileStatement) Context() lexer.Context

Context implements Node for WhileStatement

func (*WhileStatement) String

func (ws *WhileStatement) String() string

String implements Node for WhileStatement

func (*WhileStatement) TokenLiteral

func (ws *WhileStatement) TokenLiteral() string

TokenLiteral implements Node for WhileStatement

Jump to

Keyboard shortcuts

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