Documentation
¶
Overview ¶
Package parser is used to generate the abstract syntax tree (AST) for a program.
A parser is created by calling New() with a lexer as input. The parser should then be used only once, by calling parser.Parse() to produce the AST.
Index ¶
- Constants
- func Parse(ctx context.Context, input string, options ...Option) (*ast.Program, error)
- type BaseParserError
- func (e *BaseParserError) Cause() error
- func (e *BaseParserError) EndPosition() token.Position
- func (e *BaseParserError) Error() string
- func (e *BaseParserError) File() string
- func (e *BaseParserError) FriendlyErrorMessage() string
- func (e *BaseParserError) Line() int
- func (e *BaseParserError) Message() string
- func (e *BaseParserError) SourceCode() string
- func (e *BaseParserError) StartPosition() token.Position
- func (e *BaseParserError) Type() string
- func (e *BaseParserError) Unwrap() error
- type ErrorOpts
- type Option
- type Parser
- type ParserError
- type SyntaxError
Constants ¶
const ( LOWEST int PIPE // | COND // OR or AND ASSIGN // = DECLARE // := TERNARY // ? : EQUALS // == or != LESSGREATER // > or < SUM // + or - PRODUCT // * or / POWER // ** MOD // % PREFIX // -X or !X CALL // myFunction(X) INDEX // array[index], map[key] HIGHEST )
Precedence order for operators
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BaseParserError ¶
type BaseParserError struct {
// contains filtered or unexported fields
}
BaseParserError is the simplest implementation of ParserError.
func NewParserError ¶
func NewParserError(opts ErrorOpts) *BaseParserError
NewBaseParserError returns a new BaseParserError populated with the given error data.
func (*BaseParserError) Cause ¶
func (e *BaseParserError) Cause() error
func (*BaseParserError) EndPosition ¶
func (e *BaseParserError) EndPosition() token.Position
func (*BaseParserError) Error ¶
func (e *BaseParserError) Error() string
func (*BaseParserError) File ¶
func (e *BaseParserError) File() string
func (*BaseParserError) FriendlyErrorMessage ¶
func (e *BaseParserError) FriendlyErrorMessage() string
func (*BaseParserError) Line ¶
func (e *BaseParserError) Line() int
func (*BaseParserError) Message ¶
func (e *BaseParserError) Message() string
func (*BaseParserError) SourceCode ¶
func (e *BaseParserError) SourceCode() string
func (*BaseParserError) StartPosition ¶
func (e *BaseParserError) StartPosition() token.Position
func (*BaseParserError) Type ¶
func (e *BaseParserError) Type() string
func (*BaseParserError) Unwrap ¶
func (e *BaseParserError) Unwrap() error
type ErrorOpts ¶
type ErrorOpts struct { ErrType string Message string Cause error File string StartPosition token.Position EndPosition token.Position SourceCode string }
ErrorOpts is a struct that holds a variety of error data. All fields are optional, although one of `Cause` or `Message` are recommended. If `Cause` is set, `Message` will be ignored.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser object
type ParserError ¶
type ParserError interface { Type() string Message() string Cause() error File() string StartPosition() token.Position EndPosition() token.Position SourceCode() string Error() string errz.FriendlyError }
ParserError is an interface that all parser errors implement.
type SyntaxError ¶
type SyntaxError struct {
*BaseParserError
}
func NewSyntaxError ¶
func NewSyntaxError(opts ErrorOpts) *SyntaxError
NewSyntaxError returns a new SyntaxError populated with the given error data