12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- /*
- * Public Domain Software
- *
- * I (Matthias Ladkau) am the author of the source code in this file.
- * I have placed the source code in this file in the public domain.
- *
- * For further information see: http://creativecommons.org/publicdomain/zero/1.0/
- */
- package parser
- import (
- "errors"
- "fmt"
- )
- /*
- newParserError creates a new ParserError object.
- */
- func (p *parser) newParserError(t error, d string, token LexToken) error {
- return &Error{p.name, t, d, token.Lline, token.Lpos}
- }
- /*
- Error models a parser related error.
- */
- type Error struct {
- Source string // Name of the source which was given to the parser
- Type error // Error type (to be used for equal checks)
- Detail string // Details of this error
- Line int // Line of the error
- Pos int // Position of the error
- }
- /*
- Error returns a human-readable string representation of this error.
- */
- func (pe *Error) Error() string {
- var ret string
- if pe.Detail != "" {
- ret = fmt.Sprintf("Parse error in %s: %v (%v)", pe.Source, pe.Type, pe.Detail)
- } else {
- ret = fmt.Sprintf("Parse error in %s: %v", pe.Source, pe.Type)
- }
- if pe.Line != 0 {
- return fmt.Sprintf("%s (Line:%d Pos:%d)", ret, pe.Line, pe.Pos)
- }
- return ret
- }
- /*
- Parser related error types
- */
- var (
- ErrUnexpectedEnd = errors.New("Unexpected end")
- ErrLexicalError = errors.New("Lexical error")
- ErrUnknownToken = errors.New("Unknown term")
- ErrImpossibleNullDenotation = errors.New("Term cannot start an expression")
- ErrImpossibleLeftDenotation = errors.New("Term can only start an expression")
- ErrUnexpectedToken = errors.New("Unexpected term")
- )
|