syntaxtree

package
v0.0.0-...-5abede8 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArrayLiteral

type ArrayLiteral struct {
	Token    token.Token // the '[' token
	Elements []Expr
}

func (*ArrayLiteral) GetTokenLiteral

func (al *ArrayLiteral) GetTokenLiteral() string

func (*ArrayLiteral) String

func (al *ArrayLiteral) String() string

type BlockStmt

type BlockStmt struct {
	Token      token.Token // the { token
	Statements []Stmt
}

BlockStmt defines a block statement. Used in conditional expressions - if, and function definitions

func (*BlockStmt) GetTokenLiteral

func (bs *BlockStmt) GetTokenLiteral() string

func (*BlockStmt) String

func (bs *BlockStmt) String() string

type BooleanLiteral

type BooleanLiteral struct {
	Token token.Token
	Value bool
}

func (*BooleanLiteral) GetTokenLiteral

func (b *BooleanLiteral) GetTokenLiteral() string

func (*BooleanLiteral) String

func (b *BooleanLiteral) String() string

type CallExpr

type CallExpr struct {
	Token     token.Token // '(' left parenthesis
	Function  Expr        // either an identifier or a function literal
	Arguments []Expr
}

CallExpr identifies a callable expression. call expressions are of this structure: <expression>(<comma separated expressions>) sum(1, 2) sum(1 + 2, 3 + 4) fn(x, y) { x + y; }(1, 2)

func (*CallExpr) GetTokenLiteral

func (c *CallExpr) GetTokenLiteral() string

func (*CallExpr) String

func (c *CallExpr) String() string

type Expr

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

Expression is a type of node which provides expression functionality Expressions produce values. E.g: 6; sum(6,6)

type ExpressionStmt

type ExpressionStmt struct {
	Token      token.Token
	Expression Expr
}

ExpressionStmt defines an expression statement. The previous 2 types were either only expr or stmt, but now we have both. Most scripting languages support this type of statements, so will gohil. E.g: let x = 6; // we said that this was a let statement x + 6; // this is an expression statement This type implements the Stmt interface, therefore we can use it in the Program type, which holds a slice of statements, which in turn means that gohil now supports expression statements

func (*ExpressionStmt) GetTokenLiteral

func (e *ExpressionStmt) GetTokenLiteral() string

func (*ExpressionStmt) String

func (e *ExpressionStmt) String() string

type FunctionLiteral

type FunctionLiteral struct {
	Token      token.Token
	Parameters []*Identifier
	Body       *BlockStmt // reminder: 1 block statement has many statements
}

func (*FunctionLiteral) GetTokenLiteral

func (f *FunctionLiteral) GetTokenLiteral() string

func (*FunctionLiteral) String

func (f *FunctionLiteral) String() string

type HashLiteral

type HashLiteral struct {
	Token token.Token // the '{' token
	Pairs map[Expr]Expr
}

func (*HashLiteral) GetTokenLiteral

func (hl *HashLiteral) GetTokenLiteral() string

func (*HashLiteral) String

func (hl *HashLiteral) String() string

type Identifier

type Identifier struct {
	Token token.Token
	Value string
}

Identifier represents identifiers that are used in statements and expressions. x is an identifier and to represent it we need a token - token.Identifier and a value in our case, the value is "x"

func (*Identifier) GetTokenLiteral

func (i *Identifier) GetTokenLiteral() string

func (*Identifier) String

func (i *Identifier) String() string

type IfExpr

type IfExpr struct {
	Token       token.Token // if
	Condition   Expr
	Consequence *BlockStmt
	Alternative *BlockStmt
}

func (*IfExpr) GetTokenLiteral

func (ie *IfExpr) GetTokenLiteral() string

func (*IfExpr) String

func (ie *IfExpr) String() string

type IndexExpression

type IndexExpression struct {
	Token token.Token // The [ token
	Left  Expr        // the left side of an index expression is an expr: arr[4]
	Index Expr        // the index is also an expression arr[3+4] is valid syntax in gohil
}

func (*IndexExpression) GetTokenLiteral

func (ie *IndexExpression) GetTokenLiteral() string

func (*IndexExpression) String

func (ie *IndexExpression) String() string

type InfixExpr

type InfixExpr struct {
	Token token.Token

	Left     Expr
	Operator string
	Right    Expr
}

InfixExpr describes infix expressions. There are many infix expressions supported by gohil. All of the arithmetic operations are considered infix expressions. E.g: 6 + 8 Should result in: Token: + Left: IntegerLiteral(6) Operator: + Right: IntegerLiteral(8)

func (*InfixExpr) GetTokenLiteral

func (i *InfixExpr) GetTokenLiteral() string

func (*InfixExpr) String

func (i *InfixExpr) String() string

type IntegerLiteral

type IntegerLiteral struct {
	Token token.Token
	Value int
}

func (*IntegerLiteral) GetTokenLiteral

func (il *IntegerLiteral) GetTokenLiteral() string

func (*IntegerLiteral) String

func (il *IntegerLiteral) String() string

type LetStmt

type LetStmt struct {
	Token token.Token
	Name  *Identifier
	Value Expr
}

LetStmt defines a let statement. E.g: let x = 6 This means that we need a token that identifies this statement - token.Let. We need an identifier - x. We also need a value - 6.

func (*LetStmt) GetTokenLiteral

func (l *LetStmt) GetTokenLiteral() string

func (*LetStmt) String

func (l *LetStmt) String() string

type Node

type Node interface {
	fmt.Stringer

	GetTokenLiteral() string
}

Node is an interface that must be implemented by every node in the tree

type PrefixExpr

type PrefixExpr struct {
	Token    token.Token // The prefix token, e.g. ! or -
	Operator string
	Right    Expr
}

PrefixExpr describes prefix expressions in gohil. There are 2 types of prefix expressions in the language: ! and - E.g: -66 Token: - Operation: - Right: 66

func (*PrefixExpr) GetTokenLiteral

func (p *PrefixExpr) GetTokenLiteral() string

func (*PrefixExpr) String

func (p *PrefixExpr) String() string

type Program

type Program struct {
	Statements []Stmt
}

func (*Program) GetTokenLiteral

func (p *Program) GetTokenLiteral() string

func (*Program) String

func (p *Program) String() string

type ReturnStmt

type ReturnStmt struct {
	Token       token.Token
	ReturnValue Expr // return expression
}

ReturnStmt defines a return statement. E.g: return 6; return keyword and expression. This means that we need a token that identifies this statement - token.Return. We also need a return value - 6, which is an expression.

func (*ReturnStmt) GetTokenLiteral

func (r *ReturnStmt) GetTokenLiteral() string

func (*ReturnStmt) String

func (r *ReturnStmt) String() string

type Stmt

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

Statement is a type of node which provides statement functionality. Statements do not produce values. E.g: bind a value to a name: let x = 6;

type StringLiteral

type StringLiteral struct {
	Token token.Token
	Value string
}

func (*StringLiteral) GetTokenLiteral

func (sl *StringLiteral) GetTokenLiteral() string

func (*StringLiteral) String

func (sl *StringLiteral) String() string

Jump to

Keyboard shortcuts

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