core

package
v0.0.0-...-d6d0e2a Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	INT_TYPE int = iota
	FLOAT_TYPE
	STRING_TYPE
	FUNC_TYPE
)
View Source
const (
	LOWEST int
	ASSIGN_P
	IF_P
	EQUALS      // ==
	LESSGREATER // > or <
	SUM         // +
	PRODUCT     // *
	PREFIX      // -X or !X

	ARRAY_P
	CALL_P // foo(X)
)
View Source
const CALL_STACK_SIZE = 10000
View Source
const SYNTAX_ERROR_MSG = "syntax error on line: %d"

Variables

View Source
var TokenTypeStr = map[TokenType]string{
	ERROR:       "ERROR",
	ILLEGAL:     "ILLEGAL",
	EOF:         "EOF",
	WS:          "WS",
	IDENT:       "IDENT",
	INT:         "INT",
	FLOAT:       "FLOAT",
	STRING:      "STRING",
	ARRAY:       "ARRAY",
	BOOL:        "BOOL",
	ADD:         "+",
	SUB:         "-",
	MUL:         "*",
	DIV:         "/",
	REM:         "%",
	EXP:         "^",
	ASSIGN:      "=",
	ASSIGN_INF:  ":=",
	LEFT_SHIFT:  "<<",
	RIGHT_SHIFT: ">>",
	ADD_ASSIGN:  "+=",
	SUB_ASSIGN:  "-=",
	INC:         "++",
	DEC:         "--",
	EQ:          "==",
	NOT_EQ:      "!=",
	GT:          ">",
	LT:          "<",
	GT_EQ:       ">=",
	LT_EQ:       "<=",
	LPAREN:      "(",
	RPAREN:      ")",
	LBRACKET:    "[",
	RBRACKET:    "]",
	LBRACE:      "{",
	RBRACE:      "}",
	COMMA:       ",",
	DOT:         ".",
	COLON:       ":",
	SEMICOLON:   ";",
	FUNC:        "FUNC",
	RETURN:      "RETURN",
	IF:          "IF",
	ELSE:        "ELSE",
	FOR:         "FOR",
	BREAK:       "BREAK",
	CONTINUE:    "CONTINUE",
	IMPORT:      "IMPORT",
	TRUE:        "TRUE",
	FALSE:       "FALSE",
	NEWLINE:     "NEWLINE",
	CALL:        "CALL",
}

Functions

func NewCallStack

func NewCallStack() *[]Frame

Types

type Array

type Array struct {
	Elements []Object
}

func (Array) Add

func (a Array) Add(other Object) (Object, error)

func (Array) Divide

func (a Array) Divide(other Object) (Object, error)

func (Array) Equal

func (a Array) Equal(other Object) (Object, error)

func (Array) GreaterThan

func (a Array) GreaterThan(other Object) (Object, error)

func (Array) GreaterThanOrEqual

func (a Array) GreaterThanOrEqual(other Object) (Object, error)

func (Array) LessThan

func (a Array) LessThan(other Object) (Object, error)

func (Array) LessThanOrEqual

func (a Array) LessThanOrEqual(other Object) (Object, error)

func (Array) Modulo

func (a Array) Modulo(other Object) (Object, error)

func (Array) Multiply

func (a Array) Multiply(other Object) (Object, error)

func (Array) NotEqual

func (a Array) NotEqual(other Object) (Object, error)

func (Array) String

func (a Array) String() (String, error)

func (Array) Sub

func (a Array) Sub(other Object) (Object, error)

func (Array) Type

func (a Array) Type() string

func (Array) Value

func (a Array) Value() interface{}

type ArrayLiteral

type ArrayLiteral struct {
	Line     int
	Column   int
	Elements []Node
}

func (*ArrayLiteral) GetColumn

func (al *ArrayLiteral) GetColumn() int

func (*ArrayLiteral) GetLine

func (al *ArrayLiteral) GetLine() int

func (*ArrayLiteral) String

func (al *ArrayLiteral) String() string

func (*ArrayLiteral) Value

func (al *ArrayLiteral) Value() interface{}

type BlockStatement

type BlockStatement struct {
	Statements []Node
	Line       int
	Column     int
}

func (*BlockStatement) GetColumn

func (bs *BlockStatement) GetColumn() int

func (*BlockStatement) GetLine

func (bs *BlockStatement) GetLine() int

func (*BlockStatement) String

func (bs *BlockStatement) String() string

func (*BlockStatement) Value

func (bs *BlockStatement) Value() interface{}

type Boolean

type Boolean struct {
	BoolValue bool
}

func (Boolean) Add

func (b Boolean) Add(other Object) (Object, error)

func (Boolean) Divide

func (b Boolean) Divide(other Object) (Object, error)

func (Boolean) Equal

func (b Boolean) Equal(other Object) (Object, error)

func (Boolean) GreaterThan

func (b Boolean) GreaterThan(other Object) (Object, error)

func (Boolean) GreaterThanOrEqual

func (b Boolean) GreaterThanOrEqual(other Object) (Object, error)

func (Boolean) LessThan

func (b Boolean) LessThan(other Object) (Object, error)

func (Boolean) LessThanOrEqual

func (b Boolean) LessThanOrEqual(other Object) (Object, error)

func (Boolean) Modulo

func (b Boolean) Modulo(other Object) (Object, error)

func (Boolean) Multiply

func (b Boolean) Multiply(other Object) (Object, error)

func (Boolean) NotEqual

func (b Boolean) NotEqual(other Object) (Object, error)

func (Boolean) String

func (b Boolean) String() (String, error)

func (Boolean) Sub

func (b Boolean) Sub(other Object) (Object, error)

func (Boolean) Type

func (b Boolean) Type() string

func (Boolean) Value

func (b Boolean) Value() interface{}

type BooleanLiteral

type BooleanLiteral struct {
	Line   int
	Column int
	// contains filtered or unexported fields
}

func NewBooleanLiteral

func NewBooleanLiteral(value bool, line, column int) *BooleanLiteral

func (*BooleanLiteral) GetColumn

func (bl *BooleanLiteral) GetColumn() int

func (*BooleanLiteral) GetLine

func (bl *BooleanLiteral) GetLine() int

func (*BooleanLiteral) String

func (bl *BooleanLiteral) String() string

func (*BooleanLiteral) Value

func (bl *BooleanLiteral) Value() interface{}

type Callable

type Callable interface {
	Object
	GetName() string
	Call(args []Object) (Object, error)
}

type DecrementNode

type DecrementNode struct {
	Line    int
	Column  int
	Operand *IdentifierLiteral
}

func (*DecrementNode) GetColumn

func (d *DecrementNode) GetColumn() int

func (*DecrementNode) GetLine

func (d *DecrementNode) GetLine() int

func (*DecrementNode) String

func (dn *DecrementNode) String() string

func (*DecrementNode) Value

func (d *DecrementNode) Value() interface{}

type DotNotationNode

type DotNotationNode struct {
	Line   int
	Column int
	Left   Node
	Right  Node
}

func (*DotNotationNode) GetColumn

func (dn *DotNotationNode) GetColumn() int

func (*DotNotationNode) GetLine

func (dn *DotNotationNode) GetLine() int

func (*DotNotationNode) String

func (dn *DotNotationNode) String() string

func (*DotNotationNode) Value

func (dn *DotNotationNode) Value() interface{}

type Error

type Error interface {
	Object
	Error() string
}

type Evaluator

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

func NewEvaluator

func NewEvaluator(debug bool) *Evaluator

func (*Evaluator) Evaluate

func (e *Evaluator) Evaluate(exp Node) (Object, error)

type Float

type Float struct {
	FloatValue float64
}

func (Float) Add

func (f Float) Add(other Object) (Object, error)

func (Float) Divide

func (f Float) Divide(other Object) (Object, error)

func (Float) Equal

func (f Float) Equal(other Object) (Object, error)

func (Float) GreaterThan

func (f Float) GreaterThan(other Object) (Object, error)

func (Float) GreaterThanOrEqual

func (f Float) GreaterThanOrEqual(other Object) (Object, error)

func (Float) LessThan

func (f Float) LessThan(other Object) (Object, error)

func (Float) LessThanOrEqual

func (f Float) LessThanOrEqual(other Object) (Object, error)

func (Float) Modulo

func (f Float) Modulo(other Object) (Object, error)

func (Float) Multiply

func (f Float) Multiply(other Object) (Object, error)

func (Float) NotEqual

func (f Float) NotEqual(other Object) (Object, error)

func (Float) String

func (f Float) String() (String, error)

func (Float) Sub

func (f Float) Sub(other Object) (Object, error)

func (Float) Type

func (f Float) Type() string

func (Float) Value

func (f Float) Value() interface{}

type FloatLiteral

type FloatLiteral struct {
	Line   int
	Column int
	// contains filtered or unexported fields
}

func NewFloatLiteral

func NewFloatLiteral(value float64, line, column int) *FloatLiteral

func (*FloatLiteral) GetColumn

func (fl *FloatLiteral) GetColumn() int

func (*FloatLiteral) GetLine

func (fl *FloatLiteral) GetLine() int

func (*FloatLiteral) String

func (fl *FloatLiteral) String() string

func (*FloatLiteral) Value

func (fl *FloatLiteral) Value() interface{}

type ForNode

type ForNode struct {
	Initialisation Node
	Condition      Node
	Updater        Node
	Body           []Node
	Line           int
	Column         int
}

func (*ForNode) GetColumn

func (fe *ForNode) GetColumn() int

func (*ForNode) GetLine

func (fe *ForNode) GetLine() int

func (*ForNode) String

func (fe *ForNode) String() string

func (*ForNode) Value

func (fe *ForNode) Value() interface{}

type Frame

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

func NewFrame

func NewFrame() *Frame

type Function

type Function struct {
	Name       string
	Parameters []string
	Body       *BlockStatement
}

func (*Function) Add

func (f *Function) Add(other Object) (Object, error)

func (*Function) Call

func (f *Function) Call(args []Object) (Object, error)

func (*Function) Divide

func (f *Function) Divide(other Object) (Object, error)

func (*Function) Equal

func (f *Function) Equal(other Object) (Object, error)

func (*Function) GetName

func (f *Function) GetName() string

func (*Function) GreaterThan

func (f *Function) GreaterThan(other Object) (Object, error)

func (*Function) GreaterThanOrEqual

func (f *Function) GreaterThanOrEqual(other Object) (Object, error)

func (*Function) LessThan

func (f *Function) LessThan(other Object) (Object, error)

func (*Function) LessThanOrEqual

func (f *Function) LessThanOrEqual(other Object) (Object, error)

func (*Function) Modulo

func (f *Function) Modulo(other Object) (Object, error)

func (*Function) Multiply

func (f *Function) Multiply(other Object) (Object, error)

func (*Function) NotEqual

func (f *Function) NotEqual(other Object) (Object, error)

func (*Function) String

func (f *Function) String() (String, error)

func (*Function) Sub

func (f *Function) Sub(other Object) (Object, error)

func (*Function) Type

func (f *Function) Type() string

func (*Function) Value

func (f *Function) Value() interface{}

type FunctionCall

type FunctionCall struct {
	Name      string
	Function  Node
	Arguments []Node
	Line      int
	Column    int
}

func NewFunctionCall

func NewFunctionCall(function Node, arguments []Node, line, column int) *FunctionCall

func (*FunctionCall) GetColumn

func (fc *FunctionCall) GetColumn() int

func (*FunctionCall) GetLine

func (fc *FunctionCall) GetLine() int

func (*FunctionCall) String

func (fc *FunctionCall) String() string

func (*FunctionCall) Value

func (fc *FunctionCall) Value() interface{}

type FunctionLiteral

type FunctionLiteral struct {
	Name       string
	Parameters []*VariableDeclaration
	Body       *BlockStatement
	Line       int
	Column     int
}

func NewFunctionLiteral

func NewFunctionLiteral(name string, parameters []*VariableDeclaration, body *BlockStatement, line, column int) *FunctionLiteral

func (*FunctionLiteral) GetColumn

func (fl *FunctionLiteral) GetColumn() int

func (*FunctionLiteral) GetLine

func (fl *FunctionLiteral) GetLine() int

func (*FunctionLiteral) String

func (fl *FunctionLiteral) String() string

func (*FunctionLiteral) Value

func (fl *FunctionLiteral) Value() interface{}

type GoFunction

type GoFunction struct {
	Name string
	Func func([]Object) (Object, error) // The actual Go function
}

func (*GoFunction) Add

func (f *GoFunction) Add(other Object) (Object, error)

func (*GoFunction) Call

func (f *GoFunction) Call(args []Object) (Object, error)

func (*GoFunction) Divide

func (f *GoFunction) Divide(other Object) (Object, error)

func (*GoFunction) Equal

func (f *GoFunction) Equal(other Object) (Object, error)

func (*GoFunction) GetName

func (f *GoFunction) GetName() string

func (*GoFunction) GreaterThan

func (f *GoFunction) GreaterThan(other Object) (Object, error)

func (*GoFunction) GreaterThanOrEqual

func (f *GoFunction) GreaterThanOrEqual(other Object) (Object, error)

func (*GoFunction) LessThan

func (f *GoFunction) LessThan(other Object) (Object, error)

func (*GoFunction) LessThanOrEqual

func (f *GoFunction) LessThanOrEqual(other Object) (Object, error)

func (*GoFunction) Modulo

func (f *GoFunction) Modulo(other Object) (Object, error)

func (*GoFunction) Multiply

func (f *GoFunction) Multiply(other Object) (Object, error)

func (*GoFunction) NotEqual

func (f *GoFunction) NotEqual(other Object) (Object, error)

func (*GoFunction) String

func (f *GoFunction) String() (String, error)

func (*GoFunction) Sub

func (f *GoFunction) Sub(other Object) (Object, error)

func (*GoFunction) Type

func (f *GoFunction) Type() string

func (*GoFunction) Value

func (f *GoFunction) Value() interface{}

type HashLiteral

type HashLiteral struct {
	Line   int
	Column int
	Pairs  map[Node]Node
}

func (*HashLiteral) GetColumn

func (hl *HashLiteral) GetColumn() int

func (*HashLiteral) GetLine

func (hl *HashLiteral) GetLine() int

func (*HashLiteral) String

func (hl *HashLiteral) String() string

func (*HashLiteral) Value

func (hl *HashLiteral) Value() interface{}

type IdentifierLiteral

type IdentifierLiteral struct {
	Type   int
	Line   int
	Column int
	// contains filtered or unexported fields
}

func NewIdentifierLiteral

func NewIdentifierLiteral(value string, line, column int) *IdentifierLiteral

func (*IdentifierLiteral) GetColumn

func (il *IdentifierLiteral) GetColumn() int

func (*IdentifierLiteral) GetLine

func (il *IdentifierLiteral) GetLine() int

func (*IdentifierLiteral) String

func (il *IdentifierLiteral) String() string

func (*IdentifierLiteral) Value

func (il *IdentifierLiteral) Value() interface{}

type IfNode

type IfNode struct {
	Condition   Node
	Consequence Node
	Alternative Node
	Line        int
	Column      int
}

func NewIfNode

func NewIfNode(condition Node, consequence Node, alternative Node, line, column int) *IfNode

func (*IfNode) GetColumn

func (ie *IfNode) GetColumn() int

func (*IfNode) GetLine

func (ie *IfNode) GetLine() int

func (*IfNode) String

func (ie *IfNode) String() string

func (*IfNode) Value

func (ie *IfNode) Value() interface{}

type IncrementNode

type IncrementNode struct {
	Line    int
	Column  int
	Operand *IdentifierLiteral
}

func (*IncrementNode) GetColumn

func (i *IncrementNode) GetColumn() int

func (*IncrementNode) GetLine

func (i *IncrementNode) GetLine() int

func (*IncrementNode) String

func (in *IncrementNode) String() string

func (*IncrementNode) Value

func (i *IncrementNode) Value() interface{}

type InfixNode

type InfixNode struct {
	Left     Node
	Operator string
	Right    Node
	Line     int
	Column   int
}

func NewInfixNode

func NewInfixNode(left Node, operator string, right Node, line, column int) *InfixNode

func (*InfixNode) GetColumn

func (ie *InfixNode) GetColumn() int

func (*InfixNode) GetLine

func (ie *InfixNode) GetLine() int

func (*InfixNode) String

func (ie *InfixNode) String() string

func (*InfixNode) Value

func (ie *InfixNode) Value() interface{}

type Integer

type Integer struct {
	IntValue int
}

func (Integer) Add

func (i Integer) Add(other Object) (Object, error)

func (Integer) Divide

func (i Integer) Divide(other Object) (Object, error)

func (Integer) Equal

func (i Integer) Equal(other Object) (Object, error)

func (Integer) GreaterThan

func (i Integer) GreaterThan(other Object) (Object, error)

func (Integer) GreaterThanOrEqual

func (i Integer) GreaterThanOrEqual(other Object) (Object, error)

func (Integer) LessThan

func (i Integer) LessThan(other Object) (Object, error)

func (Integer) LessThanOrEqual

func (i Integer) LessThanOrEqual(other Object) (Object, error)

func (Integer) Modulo

func (i Integer) Modulo(other Object) (Object, error)

func (Integer) Multiply

func (i Integer) Multiply(other Object) (Object, error)

func (Integer) NotEqual

func (i Integer) NotEqual(other Object) (Object, error)

func (Integer) String

func (i Integer) String() (String, error)

func (Integer) Sub

func (i Integer) Sub(other Object) (Object, error)

func (Integer) Type

func (i Integer) Type() string

func (Integer) Value

func (i Integer) Value() interface{}

type IntegerLiteral

type IntegerLiteral struct {
	Line   int
	Column int
	// contains filtered or unexported fields
}

func NewIntegerLiteral

func NewIntegerLiteral(value int, line, column int) *IntegerLiteral

func (*IntegerLiteral) GetColumn

func (il *IntegerLiteral) GetColumn() int

func (*IntegerLiteral) GetLine

func (il *IntegerLiteral) GetLine() int

func (*IntegerLiteral) String

func (il *IntegerLiteral) String() string

func (*IntegerLiteral) Value

func (il *IntegerLiteral) Value() interface{}

type Lexer

type Lexer interface {
	NextToken() Token
}

func NewV1Lexer

func NewV1Lexer(input string) Lexer

type Map

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

func (Map) String

func (m Map) String() Object

func (Map) Type

func (m Map) Type() string

func (Map) Value

func (m Map) Value() interface{}

type Module

type Module struct {
	Name  string
	Scope map[string]Object
}

func (*Module) Add

func (m *Module) Add(other Object) (Object, error)

func (*Module) Divide

func (m *Module) Divide(other Object) (Object, error)

func (*Module) Equal

func (m *Module) Equal(other Object) (Object, error)

func (*Module) GreaterThan

func (m *Module) GreaterThan(other Object) (Object, error)

func (*Module) GreaterThanOrEqual

func (m *Module) GreaterThanOrEqual(other Object) (Object, error)

func (*Module) LessThan

func (m *Module) LessThan(other Object) (Object, error)

func (*Module) LessThanOrEqual

func (m *Module) LessThanOrEqual(other Object) (Object, error)

func (*Module) Modulo

func (m *Module) Modulo(other Object) (Object, error)

func (*Module) Multiply

func (m *Module) Multiply(other Object) (Object, error)

func (*Module) NotEqual

func (m *Module) NotEqual(other Object) (Object, error)

func (*Module) String

func (m *Module) String() (String, error)

func (*Module) Sub

func (m *Module) Sub(other Object) (Object, error)

func (*Module) Type

func (m *Module) Type() string

func (*Module) Value

func (m *Module) Value() interface{}

type ModuleListNode

type ModuleListNode struct {
	Modules []Node
	Line    int
	Column  int
}

func NewModuleListNode

func NewModuleListNode(modules []Node, line, column int) *ModuleListNode

func (*ModuleListNode) GetColumn

func (mle *ModuleListNode) GetColumn() int

func (*ModuleListNode) GetLine

func (mle *ModuleListNode) GetLine() int

func (*ModuleListNode) String

func (mle *ModuleListNode) String() string

func (*ModuleListNode) Value

func (mle *ModuleListNode) Value() interface{}

type ModuleLiteral

type ModuleLiteral struct {
	Name   string
	Nodes  []Node
	Line   int
	Column int
}

func NewModuleLiteral

func NewModuleLiteral(name string, Nodes []Node, line, column int) *ModuleLiteral

func (*ModuleLiteral) GetColumn

func (m *ModuleLiteral) GetColumn() int

func (*ModuleLiteral) GetLine

func (m *ModuleLiteral) GetLine() int

func (*ModuleLiteral) String

func (m *ModuleLiteral) String() string

func (*ModuleLiteral) Value

func (m *ModuleLiteral) Value() interface{}

type Nil

type Nil struct {
}

func (Nil) Add

func (n Nil) Add(other Object) (Object, error)

func (Nil) Divide

func (n Nil) Divide(other Object) (Object, error)

func (Nil) Equal

func (n Nil) Equal(other Object) (Object, error)

func (Nil) GreaterThan

func (n Nil) GreaterThan(other Object) (Object, error)

func (Nil) GreaterThanOrEqual

func (n Nil) GreaterThanOrEqual(other Object) (Object, error)

func (*Nil) Inspect

func (n *Nil) Inspect() string

func (Nil) LessThan

func (n Nil) LessThan(other Object) (Object, error)

func (Nil) LessThanOrEqual

func (n Nil) LessThanOrEqual(other Object) (Object, error)

func (Nil) Modulo

func (n Nil) Modulo(other Object) (Object, error)

func (Nil) Multiply

func (n Nil) Multiply(other Object) (Object, error)

func (Nil) NotEqual

func (n Nil) NotEqual(other Object) (Object, error)

func (Nil) String

func (n Nil) String() (String, error)

func (Nil) Sub

func (n Nil) Sub(other Object) (Object, error)

func (Nil) Type

func (n Nil) Type() string

func (Nil) Value

func (n Nil) Value() interface{}

type Node

type Node interface {
	String() string
	Value() interface{}
	GetLine() int
	GetColumn() int
}

type Object

type Object interface {
	Type() string
	Value() interface{}
	String() (String, error)
	Add(other Object) (Object, error)
	Sub(other Object) (Object, error)
	Multiply(other Object) (Object, error)
	Divide(other Object) (Object, error)
	Modulo(other Object) (Object, error)
	Equal(other Object) (Object, error)
	NotEqual(other Object) (Object, error)
	GreaterThan(other Object) (Object, error)
	LessThan(other Object) (Object, error)
	GreaterThanOrEqual(other Object) (Object, error)
	LessThanOrEqual(other Object) (Object, error)
}

type Parser

type Parser interface {
	ParseProgram() (Node, error)
	ParseNode(int) (Node, error)
}

func NewV1Parser

func NewV1Parser(l Lexer, debug bool) Parser

type PrefixNode

type PrefixNode struct {
	Operator string
	Right    Node
	Line     int
	Column   int
}

func NewPrefixNode

func NewPrefixNode(operator string, right Node, line, column int) *PrefixNode

func (*PrefixNode) GetColumn

func (pe *PrefixNode) GetColumn() int

func (*PrefixNode) GetLine

func (pe *PrefixNode) GetLine() int

func (*PrefixNode) String

func (pe *PrefixNode) String() string

func (*PrefixNode) Value

func (pe *PrefixNode) Value() interface{}

type ReturnStatement

type ReturnStatement struct {
	ReturnValue Node
	Line        int
	Column      int
}

func NewReturnStatement

func NewReturnStatement(returnValue Node, line, column int) *ReturnStatement

func (*ReturnStatement) GetColumn

func (rs *ReturnStatement) GetColumn() int

func (*ReturnStatement) GetLine

func (rs *ReturnStatement) GetLine() int

func (*ReturnStatement) String

func (rs *ReturnStatement) String() string

func (*ReturnStatement) Value

func (rs *ReturnStatement) Value() interface{}

type String

type String struct {
	StringValue string
}

func (String) Add

func (s String) Add(other Object) (Object, error)

func (String) Divide

func (s String) Divide(other Object) (Object, error)

func (String) Equal

func (s String) Equal(other Object) (Object, error)

func (String) GreaterThan

func (s String) GreaterThan(other Object) (Object, error)

func (String) GreaterThanOrEqual

func (s String) GreaterThanOrEqual(other Object) (Object, error)

func (String) LessThan

func (s String) LessThan(other Object) (Object, error)

func (String) LessThanOrEqual

func (s String) LessThanOrEqual(other Object) (Object, error)

func (String) Modulo

func (s String) Modulo(other Object) (Object, error)

func (String) Multiply

func (s String) Multiply(other Object) (Object, error)

func (String) NotEqual

func (s String) NotEqual(other Object) (Object, error)

func (String) String

func (s String) String() (String, error)

func (String) Sub

func (s String) Sub(other Object) (Object, error)

func (String) Type

func (s String) Type() string

func (String) Value

func (s String) Value() interface{}

type StringLiteral

type StringLiteral struct {
	Line   int
	Column int
	// contains filtered or unexported fields
}

func NewStringLiteral

func NewStringLiteral(value string, line, column int) *StringLiteral

func (*StringLiteral) GetColumn

func (sl *StringLiteral) GetColumn() int

func (*StringLiteral) GetLine

func (sl *StringLiteral) GetLine() int

func (*StringLiteral) String

func (sl *StringLiteral) String() string

func (*StringLiteral) Value

func (sl *StringLiteral) Value() interface{}

type StructLiteral

type StructLiteral struct {
	Fields map[string]Node
	Line   int
	Column int
}

func NewStructLiteral

func NewStructLiteral(fields map[string]Node, line, column int) *StructLiteral

func (*StructLiteral) GetColumn

func (sl *StructLiteral) GetColumn() int

func (*StructLiteral) GetLine

func (sl *StructLiteral) GetLine() int

func (*StructLiteral) String

func (sl *StructLiteral) String() string

func (*StructLiteral) Value

func (sl *StructLiteral) Value() interface{}

type Token

type Token struct {
	Type   TokenType
	Value  string
	Line   int
	Column int
	Error  string
}

type TokenType

type TokenType int
const (
	// Special tokens
	ERROR TokenType = iota
	ILLEGAL
	EOF
	WS
	NEWLINE

	// Literals
	IDENT  // main, foo, bar, x, y, etc.
	INT    // int
	FLOAT  // 123.456
	STRING // "abc", 'abc'
	BOOL   // true
	ARRAY  // [1, 2]
	STRUCT // { a int }

	// Operators
	ADD         // +
	SUB         // -
	MUL         // *
	DIV         // /
	REM         // %
	EXP         // **
	ASSIGN      // =
	ASSIGN_INF  // :=
	LEFT_SHIFT  // <<
	RIGHT_SHIFT // >>
	XOR         //^
	ADD_ASSIGN  // +=
	SUB_ASSIGN  // -=
	INC         // ++
	DEC         // --

	// Comparators
	EQ     // ==
	NOT_EQ // !=
	GT     // >
	LT     // <
	GT_EQ  // >=
	LT_EQ  // <=
	OR

	// Delimiters
	LPAREN    // (
	RPAREN    // )
	LBRACKET  // [
	RBRACKET  // ]
	LBRACE    // {
	RBRACE    // }
	COMMA     // ,
	DOT       // .
	COLON     // :
	SEMICOLON // ;

	// Keywords
	FUNC
	VAR
	CLASS
	RETURN
	IF
	ELIF
	ELSE
	FOR
	FOREVER
	BREAK
	CONTINUE
	IMPORT
	TRUE
	FALSE
	CALL
	ASYNC
	AWAIT
)

type V1Lexer

type V1Lexer struct {
	Debug bool
	// contains filtered or unexported fields
}

func (*V1Lexer) NextToken

func (l *V1Lexer) NextToken() Token

type V1Parser

type V1Parser struct {
	Debug bool
	// contains filtered or unexported fields
}

func (*V1Parser) ParseNode

func (p *V1Parser) ParseNode(precedence int) (Node, error)

func (*V1Parser) ParseProgram

func (p *V1Parser) ParseProgram() (Node, error)

type VariableDeclaration

type VariableDeclaration struct {
	Identifier *IdentifierLiteral
	Type       Token
	Line       int
	Column     int
}

func (*VariableDeclaration) GetColumn

func (vd *VariableDeclaration) GetColumn() int

func (*VariableDeclaration) GetLine

func (vd *VariableDeclaration) GetLine() int

func (*VariableDeclaration) String

func (vd *VariableDeclaration) String() string

func (*VariableDeclaration) Value

func (vd *VariableDeclaration) Value() interface{}

Jump to

Keyboard shortcuts

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