ast

package
v0.0.0-...-4998ed7 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2021 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package ast provides types representing nodes of an abstract syntax tree. The abstract syntax tree can be evaluated (executed) using an evaluator.Evaluator.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	StartLine  int
	StartCol   int
	Statements []Statement
}

Block is a list of statements to execute.

func (*Block) Col

func (b *Block) Col() int

func (*Block) Line

func (b *Block) Line() int

type BoolLiteral

type BoolLiteral struct {
	StartLine int
	StartCol  int
	Value     bool
}

BoolLiteral represents a literal bool value.

func (*BoolLiteral) Col

func (b *BoolLiteral) Col() int

func (*BoolLiteral) Line

func (b *BoolLiteral) Line() int

type BreakStatement

type BreakStatement struct {
	StartLine int
	StartCol  int
}

BreakStatement breaks the execution of the loop it is used in.

func (*BreakStatement) Col

func (b *BreakStatement) Col() int

func (*BreakStatement) Line

func (b *BreakStatement) Line() int

type CallExpression

type CallExpression struct {
	StartLine int
	StartCol  int
	Callee    Expression
	Params    []Expression
}

CallExpression calls a method or function. The called method or function may return zero or more values. If no values are returned, the CallExpression returns nil, otherwise only the first value is returned. If the method or function returns an error as the last value, execution stops with that error.

Not all method or function arguments need to be supplied. Any remaining arguments not supplied can be supplied automatically by a evaluator.ResolveArgumentFunc.

func (*CallExpression) Col

func (c *CallExpression) Col() int

func (*CallExpression) Line

func (c *CallExpression) Line() int

type CaptureExpression

type CaptureExpression struct {
	StartLine int
	StartCol  int
	Block
}

CaptureExpression captures the return values of all statements in its block, returning them as elements of a slice. If there is only one value, it is returned directly rather than inside a slice.

func (*CaptureExpression) Col

func (c *CaptureExpression) Col() int

func (*CaptureExpression) Line

func (c *CaptureExpression) Line() int

type ConditionalBlock

type ConditionalBlock struct {
	StartLine int
	StartCol  int
	Condition Expression
	Block
}

ConditionalBlock contains a block of statements to be executed if the condition is met (if any.)

func (*ConditionalBlock) Col

func (c *ConditionalBlock) Col() int

func (*ConditionalBlock) Line

func (c *ConditionalBlock) Line() int

type ContinueStatement

type ContinueStatement struct {
	StartLine int
	StartCol  int
}

ContinueStatement starts the next iteration of the for loop it is used in.

func (*ContinueStatement) Col

func (c *ContinueStatement) Col() int

func (*ContinueStatement) Line

func (c *ContinueStatement) Line() int

type Expression

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

Expression represents any expression, such as "1 + 2" or "foo.bar()".

type ExpressionStatement

type ExpressionStatement struct {
	StartLine int
	StartCol  int
	Expression
}

func (*ExpressionStatement) Col

func (e *ExpressionStatement) Col() int

func (*ExpressionStatement) Line

func (e *ExpressionStatement) Line() int

type FieldExpression

type FieldExpression struct {
	StartLine int
	StartCol  int
	Callee    Expression
	Index     Expression
}

FieldExpression looks up a "field" in a callee, returning it. The "field" may be a struct member or a method. In the case of a method, a CallExpression can be used to call it.

func (*FieldExpression) Col

func (f *FieldExpression) Col() int

func (*FieldExpression) Line

func (f *FieldExpression) Line() int

type ForExpression

type ForExpression struct {
	StartLine int
	StartCol  int
	Ident
	StatusIdent *Ident
	RangeExpr   Expression
	Block
}

ForExpression ranges over a range of values, executing a block of statements for each iteration.

func (*ForExpression) Col

func (f *ForExpression) Col() int

func (*ForExpression) Line

func (f *ForExpression) Line() int

type HashExpression

type HashExpression struct {
	StartLine int
	StartCol  int
	Values    map[string]Expression
}

HashExpression creates a map of expressions indexed by strings.

func (*HashExpression) Col

func (h *HashExpression) Col() int

func (*HashExpression) Line

func (h *HashExpression) Line() int

type Ident

type Ident struct {
	StartLine int
	StartCol  int
	Name      string
}

Ident represents a literal identifier, usually looked up automatically in the current scope.

func (*Ident) Col

func (i *Ident) Col() int

func (*Ident) Line

func (i *Ident) Line() int

type IfExpression

type IfExpression struct {
	StartLine    int
	StartCol     int
	Conditionals []ConditionalBlock
}

IfExpression executes the statements in one of its conditional blocks if the condition of that block is met.

func (*IfExpression) Col

func (i *IfExpression) Col() int

func (*IfExpression) Line

func (i *IfExpression) Line() int

type InfixExpression

type InfixExpression struct {
	StartLine int
	StartCol  int
	Left      Expression
	Operator  string
	Right     Expression
}

InfixExpression is an expression with an operator in the middle, such as "1 + 2" or "x % 5".

func (*InfixExpression) Col

func (i *InfixExpression) Col() int

func (*InfixExpression) Line

func (i *InfixExpression) Line() int

type IntLiteral

type IntLiteral struct {
	StartLine int
	StartCol  int
	Value     int64
}

IntLiteral represents a literal signed integer value.

func (*IntLiteral) Col

func (i *IntLiteral) Col() int

func (*IntLiteral) Line

func (i *IntLiteral) Line() int

type LetStatement

type LetStatement struct {
	StartLine int
	StartCol  int
	Ident
	Expression
}

LetStatement assigns a value to an identifier, usually in the current scope.

func (*LetStatement) Col

func (l *LetStatement) Col() int

func (*LetStatement) Line

func (l *LetStatement) Line() int

type Literal

type Literal struct {
	StartLine int
	StartCol  int
	Text      string
}

Literal represents literal text outside of code blocks.

func (*Literal) Col

func (l *Literal) Col() int

func (*Literal) Line

func (l *Literal) Line() int

type NilLiteral

type NilLiteral struct {
	StartLine int
	StartCol  int
}

NilLiteral represents a literal nil value.

func (*NilLiteral) Col

func (n *NilLiteral) Col() int

func (*NilLiteral) Line

func (n *NilLiteral) Line() int

type Node

type Node interface {
	Line() int
	Col() int
}

Node represents a node in the abstract syntax tree.

type PrefixExpression

type PrefixExpression struct {
	StartLine int
	StartCol  int
	Operator  string
	Expression
}

PrefixExpression is an expression that starts with an operator, such as "-15" or "!x" (where x is a bool.)

func (*PrefixExpression) Col

func (p *PrefixExpression) Col() int

func (*PrefixExpression) Line

func (p *PrefixExpression) Line() int

type Program

type Program struct {
	StartLine  int
	StartCol   int
	Statements []Statement
}

Program contains a list of statements to be executed.

func (*Program) Col

func (p *Program) Col() int

func (*Program) Line

func (p *Program) Line() int

type Statement

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

Statement is a single statement to be executed, such as a "let" or "if" statement.

type StringLiteral

type StringLiteral struct {
	StartLine int
	StartCol  int
	Value     string
}

StringLiteral represents a literal string, such as "foo" (including quotes.)

func (*StringLiteral) Col

func (s *StringLiteral) Col() int

func (*StringLiteral) Line

func (s *StringLiteral) Line() int

Jump to

Keyboard shortcuts

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