Documentation
¶
Index ¶
- type Error
- type Errors
- type Parser
- func (p *Parser) Advance() *ast.Token
- func (p *Parser) Error(msg string, start ast.Position, end ast.Position)
- func (p *Parser) ErrorCurrent(msg string)
- func (p *Parser) Expect(tokenType string, tokenValue string) ast.Position
- func (p *Parser) HasNext() bool
- func (p *Parser) Log()
- func (p *Parser) Parse(prog string) (*ast.Program, error)
- func (p *Parser) ParseAssignment() ast.Statement
- func (p *Parser) ParseBracketExpression() ast.Expression
- func (p *Parser) ParseCompareExpression() ast.Expression
- func (p *Parser) ParseExpression() ast.Expression
- func (p *Parser) ParseFuncCall() ast.Expression
- func (p *Parser) ParseGoto() ast.Statement
- func (p *Parser) ParseIf() ast.Statement
- func (p *Parser) ParseLine() *ast.Line
- func (p *Parser) ParseLogicExpression() ast.Expression
- func (p *Parser) ParsePostOpExpression() ast.Expression
- func (p *Parser) ParsePreOpExpression() ast.Expression
- func (p *Parser) ParsePreOrPostOperation() ast.Statement
- func (p *Parser) ParseProdExpression() ast.Expression
- func (p *Parser) ParseProgram() *ast.Program
- func (p *Parser) ParseSingleExpression() ast.Expression
- func (p *Parser) ParseStatement() ast.Statement
- func (p *Parser) ParseSumExpression() ast.Expression
- func (p *Parser) ParseUnaryExpression() ast.Expression
- func (p *Parser) Reset()
- func (p *Parser) SkipLine()
- type Printer
- type YololParserFunctions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Parser ¶
type Parser struct {
Tokenizer *ast.Tokenizer
CurrentToken *ast.Token
NextToken *ast.Token
PrevToken *ast.Token
// if true, there was whitespace between CurrentToken and NextToken
NextWouldBeWhitespace bool
// if true, current token was preceeded by whitespace
SkippedWhitespace bool
// using an interface of ourself to call the parsing-methods allows them to be overridden by 'subclasses'
This YololParserFunctions
// Contains all errors encountered during parsing
Errors Errors
// If true, return all found errors, not only one per line
AllErrors bool
// If true, print debug logs
DebugLog bool
}
Parser parses a yolol programm into an AST
func (*Parser) Advance ¶
Advance advances the current token to the next (non whitespace) token in the list
func (*Parser) Error ¶
Error appends an error to the list of errors encountered during parsing if p.AllErrors is false, only the first error per line is appended to the list of errors
func (*Parser) ErrorCurrent ¶
ErrorCurrent calls Error() with the position of the current token
func (*Parser) Expect ¶
Expect checks if the current token has the given type and value if true, the tokens position is returned, otherwise an error is logged alsways advances to the next token
func (*Parser) ParseAssignment ¶
ParseAssignment parses an assignment-node
func (*Parser) ParseBracketExpression ¶
func (p *Parser) ParseBracketExpression() ast.Expression
ParseBracketExpression parses a racketed expression
func (*Parser) ParseCompareExpression ¶
func (p *Parser) ParseCompareExpression() ast.Expression
ParseCompareExpression parses a compare expression
func (*Parser) ParseExpression ¶
func (p *Parser) ParseExpression() ast.Expression
ParseExpression parses an expression
func (*Parser) ParseFuncCall ¶
func (p *Parser) ParseFuncCall() ast.Expression
ParseFuncCall parse a function call
func (*Parser) ParseLogicExpression ¶
func (p *Parser) ParseLogicExpression() ast.Expression
ParseLogicExpression parses a logical expression
func (*Parser) ParsePostOpExpression ¶
func (p *Parser) ParsePostOpExpression() ast.Expression
ParsePostOpExpression parse post-expression
func (*Parser) ParsePreOpExpression ¶
func (p *Parser) ParsePreOpExpression() ast.Expression
ParsePreOpExpression parse pre-expression
func (*Parser) ParsePreOrPostOperation ¶
ParsePreOrPostOperation parses a pre-/post operation (x++, ++x) as a statement
func (*Parser) ParseProdExpression ¶
func (p *Parser) ParseProdExpression() ast.Expression
ParseProdExpression parses a product expression
func (*Parser) ParseProgram ¶
ParseProgram parses a programm-node
func (*Parser) ParseSingleExpression ¶
func (p *Parser) ParseSingleExpression() ast.Expression
ParseSingleExpression parses a single expression
func (*Parser) ParseStatement ¶
ParseStatement parses a statement-node
func (*Parser) ParseSumExpression ¶
func (p *Parser) ParseSumExpression() ast.Expression
ParseSumExpression parses a sum-expression
func (*Parser) ParseUnaryExpression ¶
func (p *Parser) ParseUnaryExpression() ast.Expression
ParseUnaryExpression parses an unary expression
type Printer ¶
type Printer struct {
// This function is called whenever an unknown node-type is encountered.
// It can be used to add support for additional types to the generator
// returns the yolol-code for the giben node or an error
UnknownHandlerFunc func(node ast.Node, visitType int) (string, error)
}
Printer generates yolol-code from an AST
type YololParserFunctions ¶
type YololParserFunctions interface {
ParseStatement() ast.Statement
ParsePreOrPostOperation() ast.Statement
ParseGoto() ast.Statement
ParseAssignment() ast.Statement
ParseIf() ast.Statement
ParseExpression() ast.Expression
ParseLogicExpression() ast.Expression
ParseCompareExpression() ast.Expression
ParseSumExpression() ast.Expression
ParseProdExpression() ast.Expression
ParseUnaryExpression() ast.Expression
ParseBracketExpression() ast.Expression
ParseSingleExpression() ast.Expression
ParseFuncCall() ast.Expression
ParsePreOpExpression() ast.Expression
ParsePostOpExpression() ast.Expression
}
YololParserFunctions is used together with Parser.This to allow 'subclasses' to override 'virtual functions'