Documentation ¶
Index ¶
- type ArrayLiteral
- type BlockStatement
- type Boolean
- type CallExpression
- type Expression
- type ExpressionStatement
- type FunctionLiteral
- type HashLiteral
- type Identifier
- type IfExpression
- type IndexExpression
- type InfixExpression
- type IntegerLiteral
- type LetStatement
- type Node
- type PrefixExpression
- type Program
- type ReturnStatement
- type Statement
- type StringLiteral
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArrayLiteral ¶ added in v0.0.5
type ArrayLiteral struct { // Token represents the [ token Token token.Token // Elements represents the items of the array Elements []Expression }
ArrayLiteral returns an array literal representation which can support any value including functions It fulfils the Expression interface by implementing expressionNode() method It by extension fulfills the Node interface which is part of the Expression interface by implementing TokenLiteral() and String() methods from the Node interface
func (*ArrayLiteral) String ¶ added in v0.0.5
func (a *ArrayLiteral) String() string
String returns a string representation of an ArrayLiteral node
func (*ArrayLiteral) TokenLiteral ¶ added in v0.0.5
func (a *ArrayLiteral) TokenLiteral() string
TokenLiteral returns the actual value of the array literal
type BlockStatement ¶
type BlockStatement struct { // Token represents { which indicated the start of a block statement i.e token.RBRACE { Token token.Token // Statements represents the list of statements in the block Statements []Statement }
BlockStatement represents a list of statements that can be structured in a block like manner It fulfils the Statement interface by implementing statementNode() method It by extension fulfills the Node interface which is part of the Statement interface by implementing TokenLiteral() and String() methods from the Node interface
func (*BlockStatement) String ¶
func (b *BlockStatement) String() string
String returns a string representation of a BlockStatement node
func (*BlockStatement) TokenLiteral ¶
func (b *BlockStatement) TokenLiteral() string
TokenLiteral returns the actual value of the block statement
type Boolean ¶
type Boolean struct { // Token represents either token.True or token.False Token token.Token // Value is true or false Value bool }
Boolean represents whose value is true or false It fulfils the Expression interface by implementing expressionNode() method It by extension fulfills the Node interface which is part of the Expression interface by implementing TokenLiteral() and String() methods from the Node interface
func (Boolean) TokenLiteral ¶
TokenLiteral returns the string value of the boolean e.g. "true" or "false"
type CallExpression ¶
type CallExpression struct { // Token represents the ( token which is after the function name Token token.Token // Function represents an identifier or function literal Function Expression // Arguments represents the parameters of the function Arguments []Expression }
CallExpression represents a structure to support function calls that also may include parameters It fulfils the Expression interface by implementing expressionNode() method It by extension fulfills the Node interface which is part of the Expression interface by implementing TokenLiteral() and String() methods from the Node interface
func (*CallExpression) String ¶
func (c *CallExpression) String() string
String returns a string representation of a CallExpression node
func (*CallExpression) TokenLiteral ¶
func (c *CallExpression) TokenLiteral() string
TokenLiteral returns the actual value of the call expression
type Expression ¶
type Expression interface { // Node ensures each statement returns a token literal and a debug string Node // contains filtered or unexported methods }
Expression is a structure that abstracts a list of tokens that represent an expression The implementor fulfills the Expression Interface by implementing the expressionNode() method and by extension, the Node interface by implementing TokenLiteral() and String() methods
type ExpressionStatement ¶
type ExpressionStatement struct { // Token represents any token representation being parsed as an expression Token token.Token // Value is any value representation being parsed as an expression Value Expression }
ExpressionStatement is an expression wrapper that groups expressions It fulfils the Statement interface by implementing statementNode() method It by extension fulfills the Node interface which is part of the Statement interface by implementing TokenLiteral() and String() methods from the Node interface
func (*ExpressionStatement) String ¶
func (e *ExpressionStatement) String() string
String returns a string representation of an ExpressionStatement node
func (*ExpressionStatement) TokenLiteral ¶
func (e *ExpressionStatement) TokenLiteral() string
TokenLiteral returns the actual value of the expression e.g. add(5,5), --4, z == a
type FunctionLiteral ¶
type FunctionLiteral struct { // Token represents the fn token Token token.Token // Parameters represents the parameters of the function Parameters []*Identifier // Body represents the body of the function Body *BlockStatement }
FunctionLiteral defines the structure of a function which includes the fn token, parameters and the body It fulfils the Expression interface by implementing expressionNode() method It by extension fulfills the Node interface which is part of the Expression interface by implementing TokenLiteral() and String() methods from the Node interface
func (*FunctionLiteral) String ¶
func (f *FunctionLiteral) String() string
String returns a string representation of a FunctionLiteral node
func (*FunctionLiteral) TokenLiteral ¶
func (f *FunctionLiteral) TokenLiteral() string
TokenLiteral returns the actual value of the function literal
type HashLiteral ¶ added in v0.0.7
type HashLiteral struct { // Token represents the { token Token token.Token // Pairs represents the pairs of the hash literal which are both expressions Pairs map[Expression]Expression }
HashLiteral returns a map representation which can support any value including functions as keys and values It fulfils the Expression interface by implementing expressionNode() method It by extension fulfills the Node interface which is part of the Expression interface by implementing TokenLiteral() and String() methods from the Node interface
func (*HashLiteral) String ¶ added in v0.0.7
func (h *HashLiteral) String() string
String returns a string representation of a HashLiteral node
func (*HashLiteral) TokenLiteral ¶ added in v0.0.7
func (h *HashLiteral) TokenLiteral() string
TokenLiteral returns the actual value of the hash literal
type Identifier ¶
type Identifier struct { // Token represents the "identifier" token Token token.Token // Value is the actual value the identifier represents e.g. "foo" Value string }
Identifier represents the 2 parts of an identifier, IDENTIFIER and Value e.g. IDENTIFIER("foo") It fulfils the Expression interface by implementing expressionNode() method It by extension fulfills the Node interface which is part of the Expression interface by implementing TokenLiteral() and String() methods from the Node interface
func (*Identifier) String ¶
func (i *Identifier) String() string
String returns a string representation of an Identifier value
func (*Identifier) TokenLiteral ¶
func (i *Identifier) TokenLiteral() string
TokenLiteral returns the actual value of the identifier e.g. returns "foo" in IDENTIFIER("foo")
type IfExpression ¶
type IfExpression struct { // Token represents the if token Token token.Token // Condition represents the expression the if expression is checking Condition Expression // Consequence represents the block statement to be executed when the condition is met Consequence *BlockStatement // Alternative represents the block statement to be executed when the condition is not met (ELSE) Alternative *BlockStatement }
IfExpression represents the composition of an if expression that represents an if-else-condition It fulfils the Expression interface by implementing expressionNode() method It by extension fulfills the Node interface which is part of the Expression interface by implementing TokenLiteral() and String() methods from the Node interface
func (*IfExpression) String ¶
func (i *IfExpression) String() string
String returns a string representation of an IfExpression node
func (*IfExpression) TokenLiteral ¶
func (i *IfExpression) TokenLiteral() string
TokenLiteral returns the actual value of the if expression e.g. 5 < 7
type IndexExpression ¶ added in v0.0.5
type IndexExpression struct { // Token represents the [ token Token token.Token // Left represents the expression being accessed Left Expression // Index represents the accessor of the left expression Index Expression }
IndexExpression defines the structure that allows accessing of values by index. It fulfils the Expression interface by implementing expressionNode() method It by extension fulfills the Node interface which is part of the Expression interface by implementing TokenLiteral() and String() methods from the Node interface
func (*IndexExpression) String ¶ added in v0.0.5
func (i *IndexExpression) String() string
String returns a string representation of an IndexExpression node
func (*IndexExpression) TokenLiteral ¶ added in v0.0.5
func (i *IndexExpression) TokenLiteral() string
TokenLiteral returns the actual value of the index expression
type InfixExpression ¶
type InfixExpression struct { // Token represent the infix operator token e.g. + Token token.Token // Left represents the expression on the left hand side of the operator e.g. 5 in 5 + 7 Left Expression // Operator is a type of operator that appears on the left side of the expression e.g. + in 5 + 7 Operator string // Right represents the expression on the right hand side of the operator e.g. 7 in 5 + 7 Right Expression }
InfixExpression represents the 3 parts of an infix expression, left operand, operator, right operand. e.g. 5 + 7 It fulfils the Expression interface by implementing expressionNode() method It by extension fulfills the Node interface which is part of the Expression interface by implementing TokenLiteral() and String() methods from the Node interface
func (*InfixExpression) String ¶
func (i *InfixExpression) String() string
String returns a string representation of an InfixExpression node
func (*InfixExpression) TokenLiteral ¶
func (i *InfixExpression) TokenLiteral() string
TokenLiteral returns the actual value of the infix expression e.g. 5 + 7
type IntegerLiteral ¶
type IntegerLiteral struct { // Token represent the integer token e.g. "5" Token token.Token // Value asserts the integer value. e.g. "5" will be returned as 5 of type int64 Value int64 }
IntegerLiteral represents an integer literal in int64 format It fulfils the Expression interface by implementing expressionNode() method It by extension fulfills the Node interface which is part of the Expression interface by implementing TokenLiteral() and String() methods from the Node interface
func (*IntegerLiteral) String ¶
func (n *IntegerLiteral) String() string
String returns a string representation of an integer literal node
func (*IntegerLiteral) TokenLiteral ¶
func (n *IntegerLiteral) TokenLiteral() string
TokenLiteral returns the actual value of the literal in string format e.g. "5"
type LetStatement ¶
type LetStatement struct { // Token represents the "let" token Token token.Token // The Name is the identifier for binding the expression/statement e.g. {token: IDENTIFIER, value: "foo"} Name *Identifier // Value represent both the expression ("add(2,2)") and a statement ("let x = 5"). statement is already represented by the expression Value Expression }
LetStatement defines the 3 parts of a let let statement: "let", "identifier", "expression" It fulfils the Statement interface by implementing statementNode() method It by extension fulfills the Node interface which is part of the Statement interface by implementing TokenLiteral() and String() methods from the Node interface
func (*LetStatement) String ¶
func (l *LetStatement) String() string
String returns a string representation of a LetStatement node
func (*LetStatement) TokenLiteral ¶
func (l *LetStatement) TokenLiteral() string
TokenLiteral returns the a "let" expression in the AST
type Node ¶
type Node interface { // TokenLiteral returns the actual value of the token TokenLiteral() string // String returns a string representation of an AST node String() string }
Node represents a single branch in the abstract syntax tree The implementor fulfills the Node interface by implementing TokenLiteral() and String() methods
type PrefixExpression ¶
type PrefixExpression struct { // Token represent the prefix operator token e.g. ! Token token.Token // Operator is a type of prefix that appears on the left side of the expression e.g. ! in !5 Operator string // Right represents the expression on the right hand side of the operator e.g. 5 in !5 Right Expression }
PrefixExpression represents an expression that is placed on the left side of other expressions e.g ! in !5 It fulfils the Expression interface by implementing expressionNode() method It by extension fulfills the Node interface which is part of the Expression interface by implementing TokenLiteral() and String() methods from the Node interface
func (*PrefixExpression) String ¶
func (p *PrefixExpression) String() string
String returns a string representation of a PrefixExpression node
func (*PrefixExpression) TokenLiteral ¶
func (p *PrefixExpression) TokenLiteral() string
TokenLiteral returns the actual value of the prefix expression e.g.!5
type Program ¶
type Program struct { // Statements contains a list of nodes (branches) which are building blocks of the AST Statements []Statement }
Program represents entry point where the root of the AST is initialized and other child nodes are built into the AST It by extension fulfills the Node interface which is part of the Statement interface by implementing TokenLiteral() and String() methods from the Node interface
func (*Program) TokenLiteral ¶
TokenLiteral method returns the token literal of the first statement in the program.(Root node of the AST) This method is used by the parser to determine the first token to be executed when a program is run.
type ReturnStatement ¶
type ReturnStatement struct { // Token represent the return token Token token.Token // Value is the actual expression being returned e.g. add(5,5), 5, foo, nil. note, we can return both statements and expressions Value Expression }
ReturnStatement contains the 2 parts of the return statement, RETURN(expression) e.g. "return add(5,5)" It fulfils the Statement interface by implementing statementNode() method It by extension fulfills the Node interface which is part of the Statement interface by implementing TokenLiteral() and String() methods from the Node interface
func (*ReturnStatement) String ¶
func (r *ReturnStatement) String() string
String returns a string representation of a ReturnStatement node
func (*ReturnStatement) TokenLiteral ¶
func (r *ReturnStatement) TokenLiteral() string
TokenLiteral returns an actual value in a return statement e.g. add(5,5), 5, foo, nil
type Statement ¶
type Statement interface { // Node ensures each statement returns a token literal and a debug string Node // contains filtered or unexported methods }
Statement is structure that abstracts a list of tokens that resemble a single statement The implementor fulfills the Statement Interface by implementing the statementNode() method and by extension, the Node interface by implementing TokenLiteral() and String() methods
type StringLiteral ¶
type StringLiteral struct { // Token represents the string token Token token.Token // Value represents the actual value of the string Value string }
StringLiteral returns a string representation of a STRING data type as a node It fulfils the Expression interface by implementing expressionNode() method It by extension fulfills the Node interface which is part of the Expression interface by implementing TokenLiteral() and String() methods from the Node interface
func (*StringLiteral) String ¶
func (s *StringLiteral) String() string
String returns a string representation of a StringLiteral node
func (*StringLiteral) TokenLiteral ¶
func (s *StringLiteral) TokenLiteral() string
TokenLiteral returns the actual value of the string literal