Documentation
¶
Index ¶
- Constants
- Variables
- func DuplicateParam(params []FunctionParams, newParam string) bool
- func GetPackageNameByPath(path string) string
- func TokenPrecedence(tok lexer.Token) int
- type AST
- type AnonymousFunctionCallExpr
- type AnonymousFunctionExpr
- type ArrayLiteral
- type BinaryExpr
- type BlockScopeStmt
- type Decl
- type ElseStmt
- type Expr
- type File
- type ForStmt
- type FunctionCallExpr
- type FunctionDecl
- type FunctionParams
- type FunctionPrototype
- type IfStmt
- type ImportStmt
- type IndexableAccessExpr
- type Literal
- type MapLiteral
- type MurlocStmt
- type Node
- type ParenExpr
- type Parser
- func (p *Parser) Back()
- func (p *Parser) DisableEOLChecking()
- func (p *Parser) HandleError(message string)
- func (p *Parser) HandleFatal(message string)
- func (p *Parser) HandleWarning(message string)
- func (p *Parser) MultiBack(steps int)
- func (p *Parser) MultiStep(steps int)
- func (p *Parser) Parse() *File
- func (p *Parser) ParseAnonymousFunctionExpr() Expr
- func (p *Parser) ParseArrayLiteral() Expr
- func (p *Parser) ParseArrayType() string
- func (p *Parser) ParseBinaryExpr(Lhs Expr, precedence int) Expr
- func (p *Parser) ParseBlock() Node
- func (p *Parser) ParseBody() []Node
- func (p *Parser) ParseElseStmt() *ElseStmt
- func (p *Parser) ParseExpr() Expr
- func (p *Parser) ParseFile() *File
- func (p *Parser) ParseForStmt() Stmt
- func (p *Parser) ParseFunctionCallExpr() Expr
- func (p *Parser) ParseFunctionDecl() Node
- func (p *Parser) ParseFunctionType() string
- func (p *Parser) ParseIdent() Node
- func (p *Parser) ParseIfStmt() Stmt
- func (p *Parser) ParseImplicitVariableDecl() Decl
- func (p *Parser) ParseImportStmt() Stmt
- func (p *Parser) ParseIndexableAccessExpr() Expr
- func (p *Parser) ParseKeyword() Node
- func (p *Parser) ParseLiteral() Expr
- func (p *Parser) ParseMapLiteral() Expr
- func (p *Parser) ParseMapType() string
- func (p *Parser) ParseNode() Node
- func (p *Parser) ParseOperand() Expr
- func (p *Parser) ParseParenExpr() Expr
- func (p *Parser) ParsePrimaryExpr(exp Expr) Expr
- func (p *Parser) ParsePrototype() FunctionPrototype
- func (p *Parser) ParseReturnStmt() Node
- func (p *Parser) ParseSelector(x Expr) Expr
- func (p *Parser) ParseStructDecl() Node
- func (p *Parser) ParseStructField() StructField
- func (p *Parser) ParseStructInstantiation() StructInstantiationExpr
- func (p *Parser) ParseText() Node
- func (p *Parser) ParseType() (string, bool)
- func (p *Parser) ParseUnaryExpr() Expr
- func (p *Parser) ParseVariableAccess() Expr
- func (p *Parser) ParseVariableAssign(lhs Expr) Stmt
- func (p *Parser) ParseVariableAssignSide() []Expr
- func (p *Parser) ParseVariableDecl() Decl
- func (p *Parser) ParseWhileStmt() Stmt
- func (p *Parser) Peek(lookAhead int) lexer.Token
- func (p *Parser) PrintBacktrace()
- func (p *Parser) Step()
- type ReturnStmt
- type SelectorExpr
- type Stmt
- type StructDecl
- type StructField
- type StructInstantiationExpr
- type UnaryExpr
- type VariableAssignStmt
- type VariableDecl
- type WhileStmt
Constants ¶
const ( ASSIGN = "=" INCREMENT = "++" DECREMENT = "--" ADDASSIGN = "+=" SUBASSIGN = "-=" DIVASSIGN = "/=" MODASSIGN = "%=" QOTASSIGN = "//=" MULTASSIGN = "*=" )
const ( Int = "int" String = "string" Char = "char" Float = "float" Bool = "bool" Map = "map" Function = "function" ArrayStart = "[" Any = "any" // keywords Var = "var" Return = "return" Range = "range" Import = "import" For = "for" While = "while" If = "if" Else = "else" Null = "null" Struct = "struct" Murloc = "mgrlmgrl" // built-in functions TypeOf = "typeOf" Eval = "eval" Len = "len" SizeOf = "sizeOf" Append = "append" )
const ( LowestPrecedence = 0 HighestPrecedence = 7 )
Variables ¶
var ( Keywords = map[string]interface{}{ Var: nil, Function: nil, Return: nil, Range: nil, Import: nil, For: nil, While: nil, If: nil, Else: nil, Null: nil, Any: nil, Struct: nil, Murloc: nil, } BuiltInFunctions = map[string]interface{}{ TypeOf: nil, Eval: nil, Len: nil, SizeOf: nil, Append: nil, } VarTypes = map[string]interface{}{ Int: nil, Float: nil, String: nil, Char: nil, Bool: nil, Map: nil, Function: nil, ArrayStart: nil, Any: nil, } DefaultVarTypes = map[string]interface{}{ Int: nil, Float: nil, String: nil, Char: nil, Bool: nil, Map: nil, Function: nil, ArrayStart: nil, Any: nil, } )
Functions ¶
func DuplicateParam ¶
func DuplicateParam(params []FunctionParams, newParam string) bool
DuplicateParam checks if a parameter is already in the list of function parameters
func GetPackageNameByPath ¶
func TokenPrecedence ¶
Types ¶
type AST ¶
type AST struct {
Operations []Node
}
The AST struct contains all the information needed for the interpreter to run
type AnonymousFunctionCallExpr ¶
type AnonymousFunctionCallExpr struct { AnonymousFunction AnonymousFunctionExpr LeftParen lexer.Token RightParen lexer.Token Args []Expr }
func (AnonymousFunctionCallExpr) EndLine ¶
func (f AnonymousFunctionCallExpr) EndLine() int
func (AnonymousFunctionCallExpr) EndPos ¶
func (f AnonymousFunctionCallExpr) EndPos() int
func (AnonymousFunctionCallExpr) StartLine ¶
func (f AnonymousFunctionCallExpr) StartLine() int
func (AnonymousFunctionCallExpr) StartPos ¶
func (f AnonymousFunctionCallExpr) StartPos() int
type AnonymousFunctionExpr ¶
type AnonymousFunctionExpr struct { FunctionToken lexer.Token Prototype FunctionPrototype Body []Node }
func (AnonymousFunctionExpr) EndLine ¶
func (f AnonymousFunctionExpr) EndLine() int
func (AnonymousFunctionExpr) EndPos ¶
func (f AnonymousFunctionExpr) EndPos() int
func (AnonymousFunctionExpr) StartLine ¶
func (f AnonymousFunctionExpr) StartLine() int
func (AnonymousFunctionExpr) StartPos ¶
func (f AnonymousFunctionExpr) StartPos() int
type ArrayLiteral ¶
func (ArrayLiteral) EndLine ¶
func (p ArrayLiteral) EndLine() int
func (ArrayLiteral) EndPos ¶
func (p ArrayLiteral) EndPos() int
func (ArrayLiteral) StartLine ¶
func (p ArrayLiteral) StartLine() int
func (ArrayLiteral) StartPos ¶
func (p ArrayLiteral) StartPos() int
type BinaryExpr ¶
BinaryExpr is a struct that defines a binary operation between two expressions
func (BinaryExpr) EndLine ¶
func (b BinaryExpr) EndLine() int
func (BinaryExpr) EndPos ¶
func (b BinaryExpr) EndPos() int
func (BinaryExpr) StartLine ¶
func (b BinaryExpr) StartLine() int
func (BinaryExpr) StartPos ¶
func (b BinaryExpr) StartPos() int
type BlockScopeStmt ¶
func (BlockScopeStmt) EndLine ¶
func (b BlockScopeStmt) EndLine() int
func (BlockScopeStmt) EndPos ¶
func (b BlockScopeStmt) EndPos() int
func (BlockScopeStmt) StartLine ¶
func (b BlockScopeStmt) StartLine() int
func (BlockScopeStmt) StartPos ¶
func (b BlockScopeStmt) StartPos() int
type Decl ¶
type Decl interface { Node // contains filtered or unexported methods }
Decl is a declaration
type ElseStmt ¶
type Expr ¶
type Expr interface { Node // contains filtered or unexported methods }
Expr is an expression
type File ¶
type File struct { ParseTree *AST Imports []string // TODO: use a map instead of a slice for better performance Dependencies []string VariableDecl []string StructInstances []string FunctionDecl []string ConsumedComments []string Trace string }
func (*File) AddDependency ¶
AddDependency adds a new dependency to the file that is currently being parsed
func (*File) ConsumeComments ¶
ConsumeComments examines all the tokens, consumes them and deletes them from the token slice
func (*File) DepChecker ¶
DepChecker checks if all dependencies in the current file are resolved by the specified imports
func (*File) IsImported ¶
func (*File) RemoveDependency ¶
type ForStmt ¶
type FunctionCallExpr ¶
type FunctionCallExpr struct { FunctionCallToken lexer.Token Name string LeftParen lexer.Token RightParen lexer.Token Args []Expr }
func (FunctionCallExpr) EndLine ¶
func (f FunctionCallExpr) EndLine() int
func (FunctionCallExpr) EndPos ¶
func (f FunctionCallExpr) EndPos() int
func (FunctionCallExpr) StartLine ¶
func (f FunctionCallExpr) StartLine() int
func (FunctionCallExpr) StartPos ¶
func (f FunctionCallExpr) StartPos() int
type FunctionDecl ¶
type FunctionDecl struct { FunctionToken lexer.Token Name string Prototype FunctionPrototype Body []Node }
func (FunctionDecl) EndLine ¶
func (f FunctionDecl) EndLine() int
func (FunctionDecl) EndPos ¶
func (f FunctionDecl) EndPos() int
func (FunctionDecl) StartLine ¶
func (f FunctionDecl) StartLine() int
func (FunctionDecl) StartPos ¶
func (f FunctionDecl) StartPos() int
type FunctionParams ¶
type FunctionPrototype ¶
type IfStmt ¶
type ImportStmt ¶
func (ImportStmt) EndLine ¶
func (i ImportStmt) EndLine() int
func (ImportStmt) EndPos ¶
func (i ImportStmt) EndPos() int
func (ImportStmt) StartLine ¶
func (i ImportStmt) StartLine() int
func (ImportStmt) StartPos ¶
func (i ImportStmt) StartPos() int
type IndexableAccessExpr ¶
type IndexableAccessExpr struct { VariableToken lexer.Token VariableName string Indexes []Expr LastBracket lexer.Token }
func (IndexableAccessExpr) EndLine ¶
func (a IndexableAccessExpr) EndLine() int
func (IndexableAccessExpr) EndPos ¶
func (a IndexableAccessExpr) EndPos() int
func (IndexableAccessExpr) StartLine ¶
func (a IndexableAccessExpr) StartLine() int
func (IndexableAccessExpr) StartPos ¶
func (a IndexableAccessExpr) StartPos() int
type MapLiteral ¶
func (MapLiteral) EndLine ¶
func (m MapLiteral) EndLine() int
func (MapLiteral) EndPos ¶
func (m MapLiteral) EndPos() int
func (MapLiteral) StartLine ¶
func (m MapLiteral) StartLine() int
func (MapLiteral) StartPos ¶
func (m MapLiteral) StartPos() int
type MurlocStmt ¶
func (MurlocStmt) EndLine ¶
func (m MurlocStmt) EndLine() int
func (MurlocStmt) EndPos ¶
func (m MurlocStmt) EndPos() int
func (MurlocStmt) StartLine ¶
func (m MurlocStmt) StartLine() int
func (MurlocStmt) StartPos ¶
func (m MurlocStmt) StartPos() int
type Parser ¶
type Parser struct { ErrorHandler *errorHandler.ErrorHandler Tokens []lexer.Token TokenIndex int CurrentToken lexer.Token CurrentFile *File IsEndOfBrace bool VarTypes map[string]interface{} }
func (*Parser) DisableEOLChecking ¶
func (p *Parser) DisableEOLChecking()
DisableEOLChecking disables the EOL checking for the parser to allow for semicolon-less syntax on conditionals statements and loops
func (*Parser) HandleError ¶
HandleError handles an error level error
func (*Parser) HandleFatal ¶
HandleFatal handles a fatal level error
func (*Parser) HandleWarning ¶
HandleWarning handles a warning level error
func (*Parser) Parse ¶
Parse is the main function of the parser. It parses the tokens within itself and returns a File struct containing the AST and the parsed declarations of variables and functions It also runs the dependency checker to find any missing dependencies and notifies the user
func (*Parser) ParseAnonymousFunctionExpr ¶
func (*Parser) ParseArrayLiteral ¶
ParseArrayLiteral parses an array literal
func (*Parser) ParseArrayType ¶
ParseArrayType parses an array type
func (*Parser) ParseBinaryExpr ¶
ParseBinaryExpr parses a binary expression with the given precedence
func (*Parser) ParseElseStmt ¶
ParseElseStmt parses an else statement
func (*Parser) ParseFile ¶
ParseFile parses the tokens and returns a File struct containing the AST and the parsed declarations of variables and functions
func (*Parser) ParseForStmt ¶
ParseForStmt parses a for statement
func (*Parser) ParseFunctionCallExpr ¶
ParseFunctionCallExpr parse a function call expression
func (*Parser) ParseFunctionDecl ¶
ParseFunctionDecl parses a function declaration
func (*Parser) ParseFunctionType ¶
func (*Parser) ParseIdent ¶
ParseIdent parses an identifier and checking if it is function or method call,a variable declaration or an indexable variable access
func (*Parser) ParseImplicitVariableDecl ¶
func (*Parser) ParseImportStmt ¶
ParseImportStmt parses an import statement
func (*Parser) ParseIndexableAccessExpr ¶
ParseIndexableAccessExpr parses an indexable variable access expression
func (*Parser) ParseKeyword ¶
ParseKeyword parses a keyword and calls the appropriate parsing function
func (*Parser) ParseMapLiteral ¶
ParseMapLiteral parses a map literal
func (*Parser) ParseNode ¶
ParseNode parses a node from the current token deciding checking if the token is text or other
func (*Parser) ParseParenExpr ¶
ParseParenExpr parses a parenthesized expression
func (*Parser) ParsePrimaryExpr ¶
ParsePrimaryExpr parses a primary expression
func (*Parser) ParsePrototype ¶
func (p *Parser) ParsePrototype() FunctionPrototype
func (*Parser) ParseReturnStmt ¶
ParseReturnStmt parses a return statement
func (*Parser) ParseSelector ¶
func (*Parser) ParseStructDecl ¶
ParseStructDecl parses a struct declaration
func (*Parser) ParseStructField ¶
func (p *Parser) ParseStructField() StructField
ParseStructField parses a struct field
func (*Parser) ParseStructInstantiation ¶
func (p *Parser) ParseStructInstantiation() StructInstantiationExpr
func (*Parser) ParseText ¶
ParseText parses a text node and checking if it is a keyword from Keywords
func (*Parser) ParseUnaryExpr ¶
ParseUnaryExpr parses a unary expression
func (*Parser) ParseVariableAccess ¶
ParseVariableAccess parses a variable access
func (*Parser) ParseVariableAssign ¶
ParseVariableAssign parses a variable assignment
func (*Parser) ParseVariableAssignSide ¶
ParseVariableAssignSide parses the right hand side or the left hand side of a variable assignment
func (*Parser) ParseVariableDecl ¶
ParseVariableDecl parses a variable declaration
func (*Parser) ParseWhileStmt ¶
ParseWhileStmt parses a while statement
func (*Parser) Peek ¶
Peek returns the token n steps ahead of the current token without moving the parser
func (*Parser) PrintBacktrace ¶
func (p *Parser) PrintBacktrace()
PrintBacktrace prints the last 10 tokens for debugging purposes
type ReturnStmt ¶
func (ReturnStmt) EndLine ¶
func (r ReturnStmt) EndLine() int
func (ReturnStmt) EndPos ¶
func (r ReturnStmt) EndPos() int
func (ReturnStmt) StartLine ¶
func (r ReturnStmt) StartLine() int
func (ReturnStmt) StartPos ¶
func (r ReturnStmt) StartPos() int
type SelectorExpr ¶
func (SelectorExpr) EndLine ¶
func (s SelectorExpr) EndLine() int
func (SelectorExpr) EndPos ¶
func (s SelectorExpr) EndPos() int
func (SelectorExpr) StartLine ¶
func (s SelectorExpr) StartLine() int
func (SelectorExpr) StartPos ¶
func (s SelectorExpr) StartPos() int
type Stmt ¶
type Stmt interface { Node // contains filtered or unexported methods }
Stmt is a statement
type StructDecl ¶
type StructDecl struct { StructToken lexer.Token Name string LeftBrace lexer.Token Fields []StructField RightBrace lexer.Token }
func (StructDecl) EndLine ¶
func (s StructDecl) EndLine() int
func (StructDecl) EndPos ¶
func (s StructDecl) EndPos() int
func (StructDecl) StartLine ¶
func (s StructDecl) StartLine() int
func (StructDecl) StartPos ¶
func (s StructDecl) StartPos() int
type StructField ¶
type StructInstantiationExpr ¶
type StructInstantiationExpr struct { StructNameToken lexer.Token Name string LeftBrace lexer.Token RightBrace lexer.Token Args []Expr }
func (StructInstantiationExpr) EndLine ¶
func (s StructInstantiationExpr) EndLine() int
func (StructInstantiationExpr) EndPos ¶
func (s StructInstantiationExpr) EndPos() int
func (StructInstantiationExpr) StartLine ¶
func (s StructInstantiationExpr) StartLine() int
func (StructInstantiationExpr) StartPos ¶
func (s StructInstantiationExpr) StartPos() int
type VariableAssignStmt ¶
func (VariableAssignStmt) EndLine ¶
func (v VariableAssignStmt) EndLine() int
func (VariableAssignStmt) EndPos ¶
func (v VariableAssignStmt) EndPos() int
func (VariableAssignStmt) StartLine ¶
func (v VariableAssignStmt) StartLine() int
func (VariableAssignStmt) StartPos ¶
func (v VariableAssignStmt) StartPos() int
type VariableDecl ¶
func (VariableDecl) EndLine ¶
func (v VariableDecl) EndLine() int
func (VariableDecl) EndPos ¶
func (v VariableDecl) EndPos() int
func (VariableDecl) StartLine ¶
func (v VariableDecl) StartLine() int
func (VariableDecl) StartPos ¶
func (v VariableDecl) StartPos() int