ast

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package ast declares the types used to represent syntax trees for Ghost source code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssignStatement added in v0.6.0

type AssignStatement struct {
	Token    token.Token
	Name     *IdentifierLiteral
	Index    *IndexExpression
	Property *PropertyExpression
	Value    Expression
}

AssignStatement defines a new statement type for defining assignments.

func (*AssignStatement) String added in v0.6.0

func (as *AssignStatement) String() string

func (*AssignStatement) TokenLiteral added in v0.6.0

func (as *AssignStatement) TokenLiteral() string

TokenLiteral and String implementations for statement nodes.

type BlockStatement

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

BlockStatement defines a new statement type for defining blocks.

func (*BlockStatement) String

func (bs *BlockStatement) String() string

func (*BlockStatement) TokenLiteral

func (bs *BlockStatement) TokenLiteral() string

type BooleanLiteral added in v0.2.0

type BooleanLiteral struct {
	Token token.Token
	Value bool
}

func (*BooleanLiteral) String added in v0.2.0

func (bl *BooleanLiteral) String() string

func (*BooleanLiteral) TokenLiteral added in v0.2.0

func (bl *BooleanLiteral) TokenLiteral() string

type CallExpression

type CallExpression struct {
	Token     token.Token
	Callable  Expression
	Arguments []Expression
}

CallExpression defines a new expression type for defining call expressions.

func (*CallExpression) String

func (ce *CallExpression) String() string

func (*CallExpression) TokenLiteral

func (ce *CallExpression) TokenLiteral() string

TokenLiteral and String implementations for expression/literal nodes.

type Expression

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

Expression interface is implemented by all expression nodes.

type ExpressionStatement

type ExpressionStatement struct {
	Token      token.Token
	Expression Expression
}

ExpressionStatement defines a new statement type for defining expressions.

func (*ExpressionStatement) String

func (es *ExpressionStatement) String() string

func (*ExpressionStatement) TokenLiteral

func (es *ExpressionStatement) TokenLiteral() string

type ForExpression added in v0.3.0

type ForExpression struct {
	Token       token.Token     // for
	Identifier  string          // x
	Initializer Statement       // x := 0
	Condition   Expression      // x <= 10
	Increment   Statement       // x += 1
	Block       *BlockStatement // { ... }
}

ForExpression defines a new expression type for defining for expressions. for (x := 0; x <= 10; x += 1) { ... }

func (*ForExpression) String added in v0.3.0

func (fe *ForExpression) String() string

func (*ForExpression) TokenLiteral added in v0.3.0

func (fe *ForExpression) TokenLiteral() string

type ForInExpression added in v0.4.0

type ForInExpression struct {
	Token    token.Token     // for
	Key      string          // key
	Value    string          // value
	Iterable Expression      // [1, 2, 3] | 1 .. 10
	Block    *BlockStatement // { ... }
}

ForInExpression defines a new expression type for defining for in expressions.

func (*ForInExpression) String added in v0.4.0

func (fie *ForInExpression) String() string

func (*ForInExpression) TokenLiteral added in v0.4.0

func (fie *ForInExpression) TokenLiteral() string

type FunctionLiteral

type FunctionLiteral struct {
	Token      token.Token
	Name       string
	Parameters []*IdentifierLiteral
	Defaults   map[string]Expression
	Body       *BlockStatement
}

func (*FunctionLiteral) String

func (fl *FunctionLiteral) String() string

func (*FunctionLiteral) TokenLiteral

func (fl *FunctionLiteral) TokenLiteral() string

type IdentifierLiteral added in v0.2.0

type IdentifierLiteral struct {
	Token token.Token
	Value string
}

func (*IdentifierLiteral) String added in v0.2.0

func (il *IdentifierLiteral) String() string

func (*IdentifierLiteral) TokenLiteral added in v0.2.0

func (il *IdentifierLiteral) TokenLiteral() string

type IfExpression

type IfExpression struct {
	Token       token.Token
	Condition   Expression
	Consequence *BlockStatement
	Alternative *BlockStatement
}

IfExpression defines a new expression type for defining if expressions.

func (*IfExpression) String

func (ie *IfExpression) String() string

func (*IfExpression) TokenLiteral

func (ie *IfExpression) TokenLiteral() string

type ImportExpression

type ImportExpression struct {
	Token token.Token
	Name  Expression
}

ImportExpression defines a new expression type for defining import expressions.

func (*ImportExpression) String

func (ie *ImportExpression) String() string

func (*ImportExpression) TokenLiteral

func (ie *ImportExpression) TokenLiteral() string

type IndexExpression

type IndexExpression struct {
	Token token.Token
	Left  Expression
	Index Expression
}

IndexExpression defines a new expression type for defining index expressions.

func (*IndexExpression) String

func (ie *IndexExpression) String() string

func (*IndexExpression) TokenLiteral

func (ie *IndexExpression) TokenLiteral() string

type InfixExpression

type InfixExpression struct {
	Token    token.Token
	Left     Expression
	Operator string
	Right    Expression
}

InfixExpression defines a new expression type for defining infix expressions.

func (*InfixExpression) String

func (ie *InfixExpression) String() string

func (*InfixExpression) TokenLiteral

func (ie *InfixExpression) TokenLiteral() string

type ListLiteral

type ListLiteral struct {
	Token    token.Token
	Elements []Expression
}

func (*ListLiteral) String

func (ll *ListLiteral) String() string

func (*ListLiteral) TokenLiteral

func (ll *ListLiteral) TokenLiteral() string

type MapLiteral

type MapLiteral struct {
	Token token.Token
	Pairs map[Expression]Expression
}

func (*MapLiteral) String

func (ml *MapLiteral) String() string

func (*MapLiteral) TokenLiteral

func (ml *MapLiteral) TokenLiteral() string

type MethodExpression added in v0.6.0

type MethodExpression struct {
	Token     token.Token
	Object    Expression
	Method    Expression
	Arguments []Expression
}

MethodExpression defines a new expression type for defining method expressions.

func (*MethodExpression) String added in v0.6.0

func (me *MethodExpression) String() string

func (*MethodExpression) TokenLiteral added in v0.6.0

func (me *MethodExpression) TokenLiteral() string

type Node

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

Node interface is implemented by all node types.

type NullLiteral added in v0.16.0

type NullLiteral struct {
	Token token.Token
}

func (*NullLiteral) String added in v0.16.0

func (nl *NullLiteral) String() string

func (*NullLiteral) TokenLiteral added in v0.16.0

func (nl *NullLiteral) TokenLiteral() string

type NumberLiteral

type NumberLiteral struct {
	Token token.Token
	Value decimal.Decimal
}

func (*NumberLiteral) String

func (nl *NumberLiteral) String() string

func (*NumberLiteral) TokenLiteral

func (nl *NumberLiteral) TokenLiteral() string

type PostfixExpression

type PostfixExpression struct {
	Token    token.Token
	Operator string
}

PostfixExpression defines a new expression type for defining postfix expressions.

func (*PostfixExpression) String

func (pe *PostfixExpression) String() string

func (*PostfixExpression) TokenLiteral

func (pe *PostfixExpression) TokenLiteral() string

type PrefixExpression

type PrefixExpression struct {
	Token    token.Token
	Operator string
	Right    Expression
}

PrefixExpression defines a new expression type for defining prefix expressions.

func (*PrefixExpression) String

func (pe *PrefixExpression) String() string

func (*PrefixExpression) TokenLiteral

func (pe *PrefixExpression) TokenLiteral() string

type Program

type Program struct {
	Statements []Statement
}

Program is the root node. All programs consist of a slice of Statement(s).

func (*Program) String

func (p *Program) String() string

String returns a stringified version of the AST for debugging purposes.

func (*Program) TokenLiteral

func (p *Program) TokenLiteral() string

TokenLiteral prints the literal value of the token associated with this node.

type PropertyExpression added in v0.6.0

type PropertyExpression struct {
	Token    token.Token
	Object   Expression
	Property Expression
}

PropertyExpression defines a new expression type for defining property expressions.

func (*PropertyExpression) String added in v0.6.0

func (pe *PropertyExpression) String() string

func (*PropertyExpression) TokenLiteral added in v0.6.0

func (pe *PropertyExpression) TokenLiteral() string

type ReturnStatement

type ReturnStatement struct {
	Token       token.Token
	ReturnValue Expression
}

ReturnStatement defines a new statement type for defining returns.

func (*ReturnStatement) String

func (rs *ReturnStatement) String() string

func (*ReturnStatement) TokenLiteral

func (rs *ReturnStatement) TokenLiteral() string

type Statement

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

Statement interface is implemented by all statement nodes.

type StringLiteral

type StringLiteral struct {
	Token token.Token
	Value string
}

func (*StringLiteral) String

func (sl *StringLiteral) String() string

func (*StringLiteral) TokenLiteral

func (sl *StringLiteral) TokenLiteral() string

type WhileExpression

type WhileExpression struct {
	Token       token.Token
	Condition   Expression
	Consequence *BlockStatement
}

WhileExpression defines a new expression type for defining while expressions.

func (*WhileExpression) String

func (we *WhileExpression) String() string

func (*WhileExpression) TokenLiteral

func (we *WhileExpression) TokenLiteral() string

Jump to

Keyboard shortcuts

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