golfcart

package
v0.0.0-...-6a8291c Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const VERSION = 0.1

Variables

This section is empty.

Functions

func GetGrammer

func GetGrammer() string

func InjectRuntime

func InjectRuntime(context *Context)

func REPL

func REPL()

func RunProgram

func RunProgram(source string, debug bool) (*string, error)

Types

type Addition

type Addition struct {
	Pos lexer.Position

	Multiplication *Multiplication `@@`
	Op             string          `( @( "-" | "+" )`
	Next           *Addition       `  @@ )?`
}

func (Addition) Equals

func (addition Addition) Equals(other Value) (bool, error)

func (Addition) Eval

func (addition Addition) Eval(frame *StackFrame) (Value, error)

func (Addition) String

func (addition Addition) String() string

type Assignment

type Assignment struct {
	Pos lexer.Position

	LogicAnd *LogicAnd `@@`
	Op       string    `( @"="`
	Next     *LogicAnd `  @@ )?`
}

func (Assignment) Equals

func (assignment Assignment) Equals(other Value) (bool, error)

func (Assignment) Eval

func (assignment Assignment) Eval(frame *StackFrame) (Value, error)

func (Assignment) String

func (assignment Assignment) String() string

type BoolValue

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

func (BoolValue) Equals

func (boolValue BoolValue) Equals(other Value) (bool, error)

func (BoolValue) String

func (boolValue BoolValue) String() string

type Break

type Break struct {
	Pos lexer.Position

	Break *string `"break"`
}

type BreakValue

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

func (BreakValue) Error

func (breakValue BreakValue) Error() string

type Call

type Call struct {
	Pos lexer.Position

	Ident         *string     `( @Ident`
	SubExpression *Expression `| "(" @@ ")" )`
	CallChain     *CallChain  `@@`
}

func (Call) Equals

func (call Call) Equals(other Value) (bool, error)

func (Call) Eval

func (call Call) Eval(frame *StackFrame) (Value, error)

func (Call) String

func (call Call) String() string

type CallChain

type CallChain struct {
	Parameters     *[]Expression `( "(" ( @@ ( "," @@ )* )? ")" `
	Access         *string       `    | "." @Ident`
	ComputedAccess *Expression   `    | "[" @@ "]" )`
	Next           *CallChain    `@@?`
}

type Comparison

type Comparison struct {
	Pos lexer.Position

	Addition *Addition   `@@`
	Op       string      `( @( ">" "=" | ">" | "<" "=" | "<" )`
	Next     *Comparison `  @@ )?`
}

func (Comparison) Equals

func (comparison Comparison) Equals(other Value) (bool, error)

func (Comparison) Eval

func (comparison Comparison) Eval(frame *StackFrame) (Value, error)

func (Comparison) String

func (comparison Comparison) String() string

type Context

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

func (*Context) Init

func (context *Context) Init()

type Continue

type Continue struct {
	Pos lexer.Position

	Continue *string `"continue"`
}

type ContinueValue

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

func (ContinueValue) Error

func (continueValue ContinueValue) Error() string

type DataLiteral

type DataLiteral struct {
	FunctionLiteral *FunctionLiteral `@@`
	ListLiteral     *ListLiteral     `| @@`
	DictLiteral     *DictLiteral     `| @@`
}

type DictEntry

type DictEntry struct {
	Pos lexer.Position

	Ident *string     `( @Ident`
	Key   *Expression `| @@ ) ":" `
	Value *Expression `@@`
}

type DictLiteral

type DictLiteral struct {
	Pos lexer.Position

	DictEntry *[]DictEntry `"{" ( @@ ("," @@)* ","? )? "}"`
}

func (DictLiteral) Equals

func (dictLiteral DictLiteral) Equals(other Value) (bool, error)

func (DictLiteral) Eval

func (dictLiteral DictLiteral) Eval(frame *StackFrame) (Value, error)

func (DictLiteral) String

func (dictLiteral DictLiteral) String() string

type DictValue

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

func (DictValue) Equals

func (dictValue DictValue) Equals(other Value) (bool, error)

func (*DictValue) Get

func (dictValue *DictValue) Get(key string) (*Value, error)

func (*DictValue) GetOrSet

func (dictValue *DictValue) GetOrSet(key string, newValue *Value) *Value

func (*DictValue) Set

func (dictValue *DictValue) Set(key string, value Value)

func (DictValue) String

func (dictValue DictValue) String() string

type ElseIf

type ElseIf struct {
	Condition *Expression   `"else" "if" @@`
	IfBody    []*Expression `"{" @@* "}"`
	Next      *ElseIf       `@@*`
}

type Equality

type Equality struct {
	Pos lexer.Position

	Comparison *Comparison `@@`
	Op         string      `( @( "!" "=" | "=" "=" )`
	Next       *Equality   `  @@ )?`
}

func (Equality) Equals

func (equality Equality) Equals(other Value) (bool, error)

func (Equality) Eval

func (equality Equality) Eval(frame *StackFrame) (Value, error)

func (Equality) String

func (equality Equality) String() string

type Expression

type Expression struct {
	Pos lexer.Position

	Assignment          *Assignment `@@`
	NativeFunctionValue *NativeFunctionValue
}

func (Expression) Equals

func (expr Expression) Equals(other Value) (bool, error)

func (Expression) Eval

func (expr Expression) Eval(frame *StackFrame) (Value, error)

func (Expression) String

func (expr Expression) String() string

type ExpressionList

type ExpressionList struct {
	Pos lexer.Position

	Expressions []*Expression `@@*`
}

func GenerateAST

func GenerateAST(source string) (*ExpressionList, error)

func (ExpressionList) Equals

func (exprList ExpressionList) Equals(other Value) (bool, error)

func (ExpressionList) Eval

func (exprList ExpressionList) Eval(context *Context) (Value, error)

func (ExpressionList) String

func (exprList ExpressionList) String() string

type For

type For struct {
	Pos lexer.Position

	Init      []*Assignment `"for" ( @@ ";"`
	Condition *Expression   `@@ ";"`
	Post      *Expression   `@@`
	Body      []*Expression `"{" @@* "}" )`
}

func (For) Eval

func (forExpression For) Eval(frame *StackFrame) (Value, error)

type ForKeyValue

type ForKeyValue struct {
	Pos lexer.Position

	Key                  *string       `( "for" @Ident ","`
	Value                *string       `@Ident "in"`
	Collection           *string       `( @Ident`
	CollectionExpression *Expression   `| @@) `
	Body                 []*Expression `"{" @@* "}" )`
}

type ForValue

type ForValue struct {
	Pos lexer.Position

	Value                *string       `( "for" @Ident "in"`
	Collection           *string       `( @Ident`
	CollectionExpression *Expression   `| @@) `
	Body                 []*Expression `"{" @@* "}" )`
}

type ForWhile

type ForWhile struct {
	Pos lexer.Position

	Init      []*Assignment `"for" (`
	Condition *Expression   `@@?`
	Post      *Expression   ``
	Body      []*Expression `"{" @@* "}" )`
}

type FunctionLiteral

type FunctionLiteral struct {
	Pos lexer.Position

	Parameters []string      `( "(" ( @Ident ( "," @Ident )* )? ")" | @Ident )`
	Body       []*Expression `"=" ">" ( "{" @@* "}" | @@ )`
}

func (FunctionLiteral) Equals

func (functionLiteral FunctionLiteral) Equals(other Value) (bool, error)

func (FunctionLiteral) Eval

func (functionLiteral FunctionLiteral) Eval(frame *StackFrame) (Value, error)

func (FunctionLiteral) String

func (functionLiteral FunctionLiteral) String() string

type FunctionValue

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

func (FunctionValue) Equals

func (functionValue FunctionValue) Equals(other Value) (bool, error)

func (FunctionValue) Exec

func (functionValue FunctionValue) Exec(args []Value) (Value, error)

func (FunctionValue) String

func (functionValue FunctionValue) String() string

type IdentifierValue

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

func (IdentifierValue) Equals

func (identifierValue IdentifierValue) Equals(other Value) (bool, error)

func (IdentifierValue) Eval

func (idValue IdentifierValue) Eval(frame *StackFrame) (Value, error)

func (IdentifierValue) String

func (identifierValue IdentifierValue) String() string

type If

type If struct {
	Pos lexer.Position

	Condition *Expression   `"if" @@`
	IfBody    []*Expression `"{" @@* "}"`
	ElseIf    *ElseIf       `@@*`
	ElseBody  []*Expression `( "else" "{" @@* "}" )?`
}

func (If) Equals

func (ifExpression If) Equals(other Value) (bool, error)

func (If) Eval

func (ifExpression If) Eval(frame *StackFrame) (Value, error)

func (If) String

func (ifExpression If) String() string

type ListLiteral

type ListLiteral struct {
	Pos lexer.Position

	Expressions *[]Expression `"[" ( @@ ( "," @@ )* )? "]"`
}

func (ListLiteral) Equals

func (listLiteral ListLiteral) Equals(other Value) (bool, error)

func (ListLiteral) Eval

func (listLiteral ListLiteral) Eval(frame *StackFrame) (Value, error)

func (ListLiteral) String

func (listLiteral ListLiteral) String() string

type ListValue

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

func (ListValue) Append

func (listValue ListValue) Append(other Value)

func (ListValue) Equals

func (listValue ListValue) Equals(other Value) (bool, error)

func (ListValue) Pop

func (listValue ListValue) Pop() Value

func (ListValue) PopLeft

func (listValue ListValue) PopLeft() Value

func (ListValue) Prepend

func (listValue ListValue) Prepend(other Value)

func (ListValue) String

func (listValue ListValue) String() string

type LogicAnd

type LogicAnd struct {
	Pos lexer.Position

	LogicOr *LogicOr  `@@`
	Op      string    `( @( "and" )`
	Next    *LogicAnd `  @@ )?`
}

func (LogicAnd) Equals

func (logicAnd LogicAnd) Equals(other Value) (bool, error)

func (LogicAnd) Eval

func (logicAnd LogicAnd) Eval(frame *StackFrame) (Value, error)

func (LogicAnd) String

func (logicAnd LogicAnd) String() string

type LogicOr

type LogicOr struct {
	Pos lexer.Position

	Equality *Equality `@@`
	Op       string    `( @( "or" )`
	Next     *LogicOr  `  @@ )?`
}

func (LogicOr) Equals

func (logicOr LogicOr) Equals(other Value) (bool, error)

func (LogicOr) Eval

func (logicOr LogicOr) Eval(frame *StackFrame) (Value, error)

func (LogicOr) String

func (logicOr LogicOr) String() string

type Multiplication

type Multiplication struct {
	Pos lexer.Position

	Unary *Unary          `@@`
	Op    string          `( @( "/" | "*" | "%")`
	Next  *Multiplication `  @@ )?`
}

func (Multiplication) Equals

func (multiplication Multiplication) Equals(other Value) (bool, error)

func (Multiplication) Eval

func (multiplication Multiplication) Eval(frame *StackFrame) (Value, error)

func (Multiplication) String

func (multiplication Multiplication) String() string

type NativeFunctionValue

type NativeFunctionValue struct {
	Pos lexer.Position

	Exec func([]Value) (Value, error)
	// contains filtered or unexported fields
}

func (NativeFunctionValue) Equals

func (nativeFunctionValue NativeFunctionValue) Equals(other Value) (bool, error)

func (NativeFunctionValue) String

func (nativeFunctionValue NativeFunctionValue) String() string

type NilValue

type NilValue struct{}

func (NilValue) Equals

func (numberValue NilValue) Equals(other Value) (bool, error)

func (NilValue) String

func (numberValue NilValue) String() string

type NumberValue

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

func (NumberValue) Equals

func (numberValue NumberValue) Equals(other Value) (bool, error)

func (NumberValue) String

func (numberValue NumberValue) String() string

type Primary

type Primary struct {
	Pos lexer.Position

	If            *If          `@@`
	DataLiteral   *DataLiteral `| @@`
	SubExpression *Expression  `| "(" @@ ")"`
	Call          *Call        `| @@`
	// TODO: `for {}` is a parser error
	ForKeyValue *ForKeyValue `| @@`
	ForValue    *ForValue    `| @@`
	For         *For         `| @@`
	ForWhile    *ForWhile    `| @@`
	Return      *Return      `| @@`
	Break       *Break       `| @@`
	Continue    *Continue    `| @@`
	Number      *float64     `| @Float | @Int`
	Str         *string      `| @String`
	True        *bool        `| @"true"`
	False       *bool        `| @"false"`
	Nil         *bool        `| @"nil"`
	Ident       *string      `| @Ident`
}

func (Primary) Eval

func (primary Primary) Eval(frame *StackFrame) (Value, error)

func (Primary) String

func (primary Primary) String() string

type ReferenceValue

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

func (ReferenceValue) Equals

func (_ ReferenceValue) Equals(other Value) (bool, error)

func (ReferenceValue) String

func (_ ReferenceValue) String() string

type Return

type Return struct {
	Pos lexer.Position

	Return     *string     `( "return" `
	Expression *Expression `@@ )`
}

type ReturnValue

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

func (ReturnValue) Error

func (returnValue ReturnValue) Error() string

type StackFrame

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

func (*StackFrame) Get

func (frame *StackFrame) Get(key string) (Value, error)

func (*StackFrame) GetChild

func (frame *StackFrame) GetChild() *StackFrame

func (*StackFrame) Set

func (frame *StackFrame) Set(key string, value Value)

func (*StackFrame) String

func (frame *StackFrame) String() string

type StringValue

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

func (StringValue) Equals

func (stringValue StringValue) Equals(other Value) (bool, error)

func (StringValue) String

func (stringValue StringValue) String() string

type Unary

type Unary struct {
	Pos lexer.Position

	Op      string   `( @( "!" | "-" )`
	Unary   *Unary   `  @@ )`
	Primary *Primary `| @@`
}

func (Unary) Equals

func (unary Unary) Equals(other Value) (bool, error)

func (Unary) Eval

func (unary Unary) Eval(frame *StackFrame) (Value, error)

func (Unary) String

func (unary Unary) String() string

type Value

type Value interface {
	String() string
	Equals(Value) (bool, error)
}

Jump to

Keyboard shortcuts

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