Documentation
¶
Index ¶
- Constants
- func RemoveParenthesis(n ast.Node)
- type Error
- type Errors
- type Parser
- func (p *Parser) Advance() *ast.Token
- func (p *Parser) Error(err *Error)
- func (p *Parser) ErrorExpectedExpression(where string)
- func (p *Parser) ErrorExpectedStatement(where string)
- func (p *Parser) ErrorString(message string, code string)
- func (p *Parser) Expect(tokenType string, tokenValue string) ast.Position
- func (p *Parser) HasNext() bool
- func (p *Parser) IsCurrent(t, value string) bool
- func (p *Parser) IsCurrentType(t string) bool
- func (p *Parser) IsCurrentValue(value string) bool
- func (p *Parser) IsCurrentValueIn(values []string) bool
- func (p *Parser) Log()
- func (p *Parser) LogI(arg int)
- func (p *Parser) Parse(prog string) (*ast.Program, error)
- func (p *Parser) ParseAssignment() ast.Statement
- func (p *Parser) ParseBinaryExpression(idx int) ast.Expression
- func (p *Parser) ParseBracketExpression() ast.Expression
- func (p *Parser) ParseExpression() ast.Expression
- func (p *Parser) ParseFactorioalExpression() ast.Expression
- func (p *Parser) ParseGoto() ast.Statement
- func (p *Parser) ParseIf() ast.Statement
- func (p *Parser) ParseLine() *ast.Line
- func (p *Parser) ParseNegationExpression() ast.Expression
- func (p *Parser) ParsePostOpExpression() ast.Expression
- func (p *Parser) ParsePreOpExpression() ast.Expression
- func (p *Parser) ParsePreOrPostOperation() *ast.Dereference
- func (p *Parser) ParseProgram() *ast.Program
- func (p *Parser) ParseSingleExpression() ast.Expression
- func (p *Parser) ParseStatement() ast.Statement
- func (p *Parser) ParseUnaryExpression() ast.Expression
- func (p *Parser) ParseUnaryNotExpression() ast.Expression
- func (p *Parser) Reset()
- func (p *Parser) SetAllErrors(b bool)
- func (p *Parser) SetDebugLog(b bool)
- func (p *Parser) SkipLine()
- type Printer
- func (p *Printer) Newline()
- func (p *Printer) OptionalSpace()
- func (p *Printer) Print(prog ast.Node) (string, error)
- func (p *Printer) Space()
- func (p *Printer) SpaceIfAfterIdentifier()
- func (p *Printer) SpaceIfFollowedByIdentifierChar()
- func (p *Printer) StatementSeparator()
- func (p *Printer) Write(content string)
- type Printermode
- type YololParser
- type YololParserFunctions
Constants ¶
const ( ErrExpectedExpression = "ErrExpectedExpression" ErrExpectedStatement = "ErrExpectedStatement" ErrExpectedToken = "ErrExpectedToken" ErrExpectedAssignop = "ErrExpectedAssignop" )
Predefined constants for Error.Code
const ( ValidateLocalVars = 1 ValidateGlobalVars = 2 ValidateLogicalNots = 4 ValidateFactorials = 8 ValidateAll = ValidateLocalVars | ValidateGlobalVars | ValidateLogicalNots | ValidateFactorials )
Variables ¶
This section is empty.
Functions ¶
func RemoveParenthesis ¶ added in v0.1.0
RemoveParenthesis removes all ()-nodes from the ast. These are superflous but were required duing parding because of bugs in starbase
Types ¶
type Error ¶
type Error struct {
// The human-readable error-message
Message string
// Where the error started
StartPosition ast.Position
// Where the error ends
EndPosition ast.Position
// Machine-Readable error-code
Code string
// A token that was expected here (optional)
ExpectedToken *ast.Token
}
Error represents an error encountered during parsing
type Parser ¶
type Parser struct {
// The tokenizer used to tokenize the input
Tokenizer *ast.Tokenizer
CurrentToken *ast.Token
// 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
// contains filtered or unexported fields
}
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 Usually it is better to use one of the higher-level Error* methods
func (*Parser) ErrorExpectedExpression ¶ added in v0.0.24
ErrorExpectedExpression is a shortcut to log an error about an expected expression at where
func (*Parser) ErrorExpectedStatement ¶ added in v0.0.24
ErrorExpectedStatement is a shortcut to log an error about an expected statement at where
func (*Parser) ErrorString ¶ added in v0.0.24
ErrorString logs an error with the given message and type at the current location
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) IsCurrent ¶ added in v0.0.13
IsCurrent checks if the current token matches the given type and value The comparison of the value is case-insensitive
func (*Parser) IsCurrentType ¶ added in v0.0.13
IsCurrentType checks if the type of the current token is equal to the given type
func (*Parser) IsCurrentValue ¶ added in v0.0.13
IsCurrentValue checks if the value of the current token is equal to the given value The comparison is case-insensitive
func (*Parser) IsCurrentValueIn ¶ added in v0.0.13
IsCurrentValueIn checks if the value of the current token is one of the provided values The comparison is case-insensitive
func (*Parser) LogI ¶ added in v0.0.23
LogI logs the visiting of a parsing function with a given argument
func (*Parser) ParseAssignment ¶
ParseAssignment parses an assignment-node
func (*Parser) ParseBinaryExpression ¶ added in v0.0.23
func (p *Parser) ParseBinaryExpression(idx int) ast.Expression
ParseBinaryExpression parses a binary expression The kind of binary-expression to be parsed is given as idx
func (*Parser) ParseBracketExpression ¶
func (p *Parser) ParseBracketExpression() ast.Expression
ParseBracketExpression parses a racketed expression
func (*Parser) ParseExpression ¶
func (p *Parser) ParseExpression() ast.Expression
ParseExpression parses an expression
func (*Parser) ParseFactorioalExpression ¶ added in v0.0.24
func (p *Parser) ParseFactorioalExpression() ast.Expression
ParseFactorioalExpression parses a factorial
func (*Parser) ParseNegationExpression ¶ added in v0.0.24
func (p *Parser) ParseNegationExpression() ast.Expression
ParseNegationExpression parses a negation
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 ¶
func (p *Parser) ParsePreOrPostOperation() *ast.Dereference
ParsePreOrPostOperation parses a pre-/post operation (x++, ++x) as a statement
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) ParseUnaryExpression ¶
func (p *Parser) ParseUnaryExpression() ast.Expression
ParseUnaryExpression parses an unary expression
func (*Parser) ParseUnaryNotExpression ¶ added in v0.1.0
func (p *Parser) ParseUnaryNotExpression() ast.Expression
ParseUnaryNotExpression parses a "not" expression
func (*Parser) Reset ¶ added in v0.0.10
func (p *Parser) Reset()
Reset prepares all internal fields for a new parsing run is called automatically by Parse(). Overriding structs must call this in their Parse()
func (*Parser) SetAllErrors ¶ added in v0.0.32
SetAllErrors enables/disables the logging of more then one error per line
func (*Parser) SetDebugLog ¶ added in v0.0.32
SetDebugLog enables/disables debug-logging
type Printer ¶
type Printer struct {
// If this functiontion is set, it is called for every AST-node, before printing anything for that node.
// It can be used to customize printing of certain nodes or add new kinds of nodes.
// If it returns an errior, that errors is bubbled up.
// The function should return true, if it can handle the given node and does not want this printer to continue processing it
PrinterExtensionFunc func(node ast.Node, visitType int, p *Printer) (bool, error)
// If true, only insert spaces where absolutely necessary
Mode Printermode
// If true, at position-information to every printed token.
// Does not produce valid yolol, but is usefull for debugging
DebugPositions bool
// contains filtered or unexported fields
}
Printer generates yolol-code from an AST
func (*Printer) Newline ¶ added in v0.0.14
func (p *Printer) Newline()
Newline adds a newline to the source-code that is currently build
func (*Printer) OptionalSpace ¶ added in v0.0.14
func (p *Printer) OptionalSpace()
OptionalSpace adds a space to the source-code that is currently build, IF we are not producing compressed output
func (*Printer) Space ¶ added in v0.0.14
func (p *Printer) Space()
Space adds a space to the source-code that is currently build
func (*Printer) SpaceIfAfterIdentifier ¶ added in v0.1.0
func (p *Printer) SpaceIfAfterIdentifier()
SpaceIfAfterIdentifier writes a space if the previously printed thing was an identifier
func (*Printer) SpaceIfFollowedByIdentifierChar ¶ added in v0.1.0
func (p *Printer) SpaceIfFollowedByIdentifierChar()
SpaceIfFollowedByIdentifierChar adds a space, if the next character is one of the chars that are allowed inside identifiers
func (*Printer) StatementSeparator ¶ added in v0.0.14
func (p *Printer) StatementSeparator()
StatementSeparator writes spaces to seperate statements on one line. Amount of spaces depends on settings
type Printermode ¶ added in v0.0.14
type Printermode int
Printermode describes various modes for the printer
const ( // PrintermodeCompact inserts only spaces that are reasonably necessary PrintermodeCompact Printermode = 0 // PrintermodeReadable inserts spaces the improve readability PrintermodeReadable Printermode = 1 )
type YololParser ¶ added in v0.0.32
type YololParser interface {
Parse(prog string) (*ast.Program, error)
SetDebugLog(b bool)
SetAllErrors(b bool)
}
YololParser is an interface that hides all overridable-methods from normal users
type YololParserFunctions ¶
type YololParserFunctions interface {
ParseStatement() ast.Statement
ParsePreOrPostOperation() *ast.Dereference
ParseGoto() ast.Statement
ParseAssignment() ast.Statement
ParseIf() ast.Statement
ParseExpression() ast.Expression
ParseBinaryExpression(int) ast.Expression
ParseUnaryExpression() ast.Expression
ParseUnaryNotExpression() ast.Expression
ParseFactorioalExpression() ast.Expression
ParseNegationExpression() ast.Expression
ParseBracketExpression() ast.Expression
ParseSingleExpression() ast.Expression
ParsePreOpExpression() ast.Expression
ParsePostOpExpression() ast.Expression
}
YololParserFunctions is used together with Parser.This to allow 'subclasses' to override 'virtual functions'