ast

package
v0.0.0-...-2577f20 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 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 []Expression
}

func (*ArrayLiteral) String

func (al *ArrayLiteral) String() string

func (*ArrayLiteral) TokenLiteral

func (al *ArrayLiteral) TokenLiteral() string

type AssignStatement

type AssignStatement struct {
	Token    token.Token // the token.ASSIGN token
	Name     *Identifier
	Names    []Expression
	Index    *IndexExpression    // support assignment to indexed expressions: a[0] = 1, h["a"] = 1
	Property *PropertyExpression // support assignment to hash properties: h.a = 1
	Value    Expression
}

Statements

func (*AssignStatement) String

func (as *AssignStatement) String() string

func (*AssignStatement) TokenLiteral

func (as *AssignStatement) TokenLiteral() string

type BlockStatement

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

func (*BlockStatement) String

func (bs *BlockStatement) String() string

func (*BlockStatement) TokenLiteral

func (bs *BlockStatement) TokenLiteral() string

type Boolean

type Boolean struct {
	Token token.Token
	Value bool
}

func (*Boolean) String

func (b *Boolean) String() string

func (*Boolean) TokenLiteral

func (b *Boolean) TokenLiteral() string

type BreakStatement

type BreakStatement struct {
	Token token.Token // the 'break' token
}

func (*BreakStatement) String

func (bs *BreakStatement) String() string

func (*BreakStatement) TokenLiteral

func (bs *BreakStatement) TokenLiteral() string

type CallExpression

type CallExpression struct {
	Token     token.Token // The '(' token
	Function  Expression  // Identifier or FunctionLiteral
	Arguments []Expression
	Deferred
}

func (*CallExpression) String

func (ce *CallExpression) String() string

func (*CallExpression) TokenLiteral

func (ce *CallExpression) TokenLiteral() string

type CommandExpression

type CommandExpression struct {
	Token token.Token // The command itself
	Value string
	Deferred
}

func (*CommandExpression) String

func (ce *CommandExpression) String() string

func (*CommandExpression) TokenLiteral

func (ce *CommandExpression) TokenLiteral() string

type CompoundAssignment

type CompoundAssignment struct {
	Token    token.Token // The operator token, e.g. +
	Left     Expression
	Operator string
	Right    Expression
}

func (*CompoundAssignment) String

func (ca *CompoundAssignment) String() string

func (*CompoundAssignment) TokenLiteral

func (ca *CompoundAssignment) TokenLiteral() string

type ContinueStatement

type ContinueStatement struct {
	Token token.Token // the 'continue' token
}

func (*ContinueStatement) String

func (cs *ContinueStatement) String() string

func (*ContinueStatement) TokenLiteral

func (cs *ContinueStatement) TokenLiteral() string

type CurrentArgsLiteral

type CurrentArgsLiteral struct {
	Token token.Token // ...
}

func (*CurrentArgsLiteral) String

func (cal *CurrentArgsLiteral) String() string

func (*CurrentArgsLiteral) TokenLiteral

func (cal *CurrentArgsLiteral) TokenLiteral() string

type Decorator

type Decorator struct {
	Token      token.Token // @
	Expression Expression
	Decorated  Expression
}

func (*Decorator) String

func (dc *Decorator) String() string

func (*Decorator) TokenLiteral

func (dc *Decorator) TokenLiteral() string

type Deferrable

type Deferrable interface {
	IsDeferred() bool
	SetDeferred(bool)
}

Deferrable is used to be able to check whether an expression needs to be executed now or at the end of the scope

type Deferred

type Deferred struct {
	// contains filtered or unexported fields
}

Deferred is a struct that can be embedded in order to define whether the current node needs to be executed right away or whether it should be deferred until the end of the current scope.

func (*Deferred) IsDeferred

func (d *Deferred) IsDeferred() bool

func (*Deferred) SetDeferred

func (d *Deferred) SetDeferred(deferred bool)

type Expression

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

All expression nodes implement this

type ExpressionStatement

type ExpressionStatement struct {
	Token      token.Token // the first token of the expression
	Expression Expression
}

func (*ExpressionStatement) String

func (es *ExpressionStatement) String() string

func (*ExpressionStatement) TokenLiteral

func (es *ExpressionStatement) TokenLiteral() string

type ForExpression

type ForExpression struct {
	Token      token.Token     // The 'for' token
	Identifier string          // "x"
	Starter    Statement       // x = 0
	Closer     Statement       // x++
	Condition  Expression      // x < 1
	Block      *BlockStatement // The block executed inside the for loop
}

func (*ForExpression) String

func (fe *ForExpression) String() string

func (*ForExpression) TokenLiteral

func (fe *ForExpression) TokenLiteral() string

type ForInExpression

type ForInExpression struct {
	Token       token.Token     // The 'for' token
	Block       *BlockStatement // The block executed inside the for loop
	Iterable    Expression      // An expression that should return an iterable ([1, 2, 3] or x in 1..10)
	Key         string
	Value       string
	Alternative *BlockStatement
}

func (*ForInExpression) String

func (fie *ForInExpression) String() string

func (*ForInExpression) TokenLiteral

func (fie *ForInExpression) TokenLiteral() string

type FunctionLiteral

type FunctionLiteral struct {
	Token      token.Token // The 'fn' token
	Name       string      // identifier for this function
	Parameters []*Parameter
	Body       *BlockStatement
}

func (*FunctionLiteral) String

func (fl *FunctionLiteral) String() string

func (*FunctionLiteral) TokenLiteral

func (fl *FunctionLiteral) TokenLiteral() string

type HashLiteral

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

func (*HashLiteral) String

func (hl *HashLiteral) String() string

func (*HashLiteral) TokenLiteral

func (hl *HashLiteral) TokenLiteral() string

type Identifier

type Identifier struct {
	Token token.Token // the token.IDENT token
	Value string
}

Expressions

func (*Identifier) String

func (i *Identifier) String() string

func (*Identifier) TokenLiteral

func (i *Identifier) TokenLiteral() string

type IfExpression

type IfExpression struct {
	Token     token.Token // The 'if' token
	Scenarios []*Scenario
}

func (*IfExpression) String

func (ie *IfExpression) String() string

func (*IfExpression) TokenLiteral

func (ie *IfExpression) TokenLiteral() string

type IndexExpression

type IndexExpression struct {
	Token   token.Token // The [ token
	Left    Expression  // the argument on which the index is access eg array of array[1]
	Index   Expression  // the left-most index eg. 1 in array[1] or array[1:10]
	IsRange bool        // whether the expression is a range (1:10)
	End     Expression  // the end of the range, if the expression is a range
}

IndexExpression allows accessing a single index, or a range, over a string or an array.

array[1:10] -> left[index:end] array[1] -> left[index] string[1] -> left[index]

func (*IndexExpression) String

func (ie *IndexExpression) String() string

func (*IndexExpression) TokenLiteral

func (ie *IndexExpression) TokenLiteral() string

type InfixExpression

type InfixExpression struct {
	Token    token.Token // The operator token, e.g. +
	Left     Expression
	Operator string
	Right    Expression
}

func (*InfixExpression) String

func (ie *InfixExpression) String() string

func (*InfixExpression) TokenLiteral

func (ie *InfixExpression) TokenLiteral() string

type MethodExpression

type MethodExpression struct {
	Token     token.Token // The operator token, e.g. .
	Object    Expression
	Method    Expression
	Arguments []Expression
	Optional  bool
	Deferred
}

func (*MethodExpression) String

func (me *MethodExpression) String() string

func (*MethodExpression) TokenLiteral

func (me *MethodExpression) TokenLiteral() string

type Node

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

The base Node interface

type NullLiteral

type NullLiteral struct {
	Token token.Token
}

func (*NullLiteral) String

func (nl *NullLiteral) String() string

func (*NullLiteral) TokenLiteral

func (nl *NullLiteral) TokenLiteral() string

type NumberLiteral

type NumberLiteral struct {
	Token token.Token
	Value float64
}

func (*NumberLiteral) String

func (nl *NumberLiteral) String() string

func (*NumberLiteral) TokenLiteral

func (nl *NumberLiteral) TokenLiteral() string

type Parameter

type Parameter struct {
	*Identifier
	Default Expression
}

Parameter is a function parameter fn(x, y = 2)

func (*Parameter) String

func (p *Parameter) String() string

func (*Parameter) TokenLiteral

func (p *Parameter) TokenLiteral() string

type PrefixExpression

type PrefixExpression struct {
	Token    token.Token // The prefix token, e.g. !
	Operator string
	Right    Expression
}

func (*PrefixExpression) String

func (pe *PrefixExpression) String() string

func (*PrefixExpression) TokenLiteral

func (pe *PrefixExpression) TokenLiteral() string

type Program

type Program struct {
	Statements []Statement
}

Represents the whole program as a bunch of statements

func (*Program) String

func (p *Program) String() string

func (*Program) TokenLiteral

func (p *Program) TokenLiteral() string

type PropertyExpression

type PropertyExpression struct {
	Token    token.Token // The . token
	Object   Expression
	Property Expression
	Optional bool
}

func (*PropertyExpression) String

func (pe *PropertyExpression) String() string

func (*PropertyExpression) TokenLiteral

func (pe *PropertyExpression) TokenLiteral() string

type ReturnStatement

type ReturnStatement struct {
	Token       token.Token // the 'return' token
	ReturnValue Expression
}

func (*ReturnStatement) String

func (rs *ReturnStatement) String() string

func (*ReturnStatement) TokenLiteral

func (rs *ReturnStatement) TokenLiteral() string

type Scenario

type Scenario struct {
	Condition   Expression
	Consequence *BlockStatement
}

A scenario is used to represent a path within an IF block (if x = 2 { return x}). It has a condition (x = 2) and a consenquence (return x).

type Statement

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

All statement nodes implement this

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 // The 'while' token
	Condition   Expression
	Consequence *BlockStatement
}

func (*WhileExpression) String

func (ie *WhileExpression) String() string

func (*WhileExpression) TokenLiteral

func (ie *WhileExpression) TokenLiteral() string

Jump to

Keyboard shortcuts

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