node

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

node is an abstract syntax tree (AST) node

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aton

type Aton struct{ Value Type }

Aton converts a string to a number type

func (Aton) PrettyPrint

func (a Aton) PrettyPrint(d int)

func (Aton) Token

func (a Aton) Token() string

type BinOp

type BinOp struct {
	Op    string // Op is the operator string
	Left  Type   // Left operand
	Right Type   // Right operand
}

BinOp is a binary operator of any kind, anything from "=", etc.

func (BinOp) PrettyPrint

func (b BinOp) PrettyPrint(d int)

func (BinOp) Token

func (b BinOp) Token() string

type Block

type Block struct {
	Body []Type // Body is the block body
}

Block is a code block / sequence that was in '{', '}'

func (Block) PrettyPrint

func (b Block) PrettyPrint(d int)

func (Block) Token

func (b Block) Token() string

type Call

type Call struct {
	Name      string // Name of the function called
	Arguments List   // Arguments passed to the function
}

Call is function call

func (Call) PrettyPrint

func (c Call) PrettyPrint(d int)

func (Call) Token

func (c Call) Token() string

type Error

type Error struct{ Value Type }

Error converts a string to an error

func (Error) PrettyPrint

func (e Error) PrettyPrint(d int)

func (Error) Token

func (e Error) Token() string

type Float

type Float string

Float is float literal

func (Float) PrettyPrint

func (f Float) PrettyPrint(d int)

func (Float) Token

func (f Float) Token() string

type Function

type Function struct {
	Parameters List // Parameters of the function
	Body       Type // Body of the function
}

Function is a function definition

func (Function) PrettyPrint

func (f Function) PrettyPrint(d int)

func (Function) Token

func (f Function) Token() string

type If

type If struct {
	Condition Type // Condition is the condition for the if statement
	TrueCase  Type // TrueCase is executed if condition evaluates to true
}

If is a conditional construct without an else case

func (If) PrettyPrint

func (i If) PrettyPrint(d int)

func (If) Token

func (i If) Token() string

type IfElse

type IfElse struct {
	Condition Type // Condition is the condition for the if statement
	TrueCase  Type // TrueCase is executed if condition evaluates to true
	FalseCase Type // FalseCase is executed if condition evaluates to false
}

IfElse is a conditional construct

func (IfElse) PrettyPrint

func (ie IfElse) PrettyPrint(d int)

func (IfElse) Token

func (i IfElse) Token() string

type IndexAt

type IndexAt struct {
	Ary Type // Ary is the indexed node
	At  Type // At is the index
}

func (IndexAt) PrettyPrint

func (i IndexAt) PrettyPrint(d int)

func (IndexAt) Token

func (u IndexAt) Token() string

type IndexFromTo

type IndexFromTo struct {
	Ary  Type // Ary is the indexed node
	From Type // From is the start of the range
	To   Type // To is the end of the range
}

func (IndexFromTo) PrettyPrint

func (i IndexFromTo) PrettyPrint(d int)

func (IndexFromTo) Token

func (u IndexFromTo) Token() string

type Int

type Int string

Int is integer literal

func (Int) PrettyPrint

func (i Int) PrettyPrint(d int)

func (Int) Token

func (i Int) Token() string

type Invalid

type Invalid struct{}

Invalid is an invalid AST node

func (Invalid) Token

func (i Invalid) Token() string

type List

type List struct {
	Elems []Type // Elems are the parameters or arguments
}

List is a list of arguments or parameters depending on whether it's a function call or definition

func (List) PrettyPrint

func (l List) PrettyPrint(d int)

func (List) Token

func (l List) Token() string

type Name

type Name string

Variable name (also "true", "false" etc.)

func (Name) PrettyPrint

func (n Name) PrettyPrint(d int)

func (Name) Token

func (n Name) Token() string

type PrettyPrinter

type PrettyPrinter interface {
	PrettyPrint(indent int)
}

type Read

type Read struct{}

Read reads a string from stdin

func (Read) PrettyPrint

func (r Read) PrettyPrint(d int)

func (Read) Token

func (r Read) Token() string

type Repl

type Repl struct{}

Repl starts a calc repl session

func (Repl) PrettyPrint

func (r Repl) PrettyPrint(d int)

func (Repl) Token

func (r Repl) Token() string

type Return

type Return struct {
	Target Type // Target is the returned value
}

Return is a return statement

func (Return) PrettyPrint

func (r Return) PrettyPrint(d int)

func (Return) Token

func (r Return) Token() string

type String

type String string

String is string literal

func (String) PrettyPrint

func (s String) PrettyPrint(d int)

func (String) Token

func (s String) Token() string

type Type

type Type interface {
	PrettyPrinter
	Token() string
}

Type is AST node type

type UnOp

type UnOp struct {
	Op     string // Op is the operator string
	Target Type   // Target is the operand
}

UnOp is a unary operator of any kind, ie. '-'

func (UnOp) PrettyPrint

func (u UnOp) PrettyPrint(d int)

func (UnOp) Token

func (u UnOp) Token() string

type While

type While struct {
	Condition Type // Condition is the condition for the loop
	Body      Type // Body is the loop body
}

While is a loop construct

func (While) PrettyPrint

func (w While) PrettyPrint(d int)

func (While) Token

func (w While) Token() string

type Write

type Write struct{ Value Type }

Write writes a value to stdout

func (Write) PrettyPrint

func (w Write) PrettyPrint(d int)

func (Write) Token

func (w Write) Token() string

Jump to

Keyboard shortcuts

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