Move parser into parser package

This commit is contained in:
Asdine El Hrychy
2019-11-24 15:56:19 +01:00
parent 26b493dbe8
commit ccbc84011f
35 changed files with 1323 additions and 1343 deletions

View File

@@ -2,10 +2,6 @@ package genji
import (
"errors"
"fmt"
"strings"
"github.com/asdine/genji/internal/scanner"
)
var (
@@ -33,24 +29,3 @@ var (
// ErrResultClosed is returned when trying to close an already closed result.
ErrResultClosed = errors.New("result already closed")
)
// ParseError represents an error that occurred during parsing.
type ParseError struct {
Message string
Found string
Expected []string
Pos scanner.Pos
}
// newParseError returns a new instance of ParseError.
func newParseError(found string, expected []string, pos scanner.Pos) *ParseError {
return &ParseError{Found: found, Expected: expected, Pos: pos}
}
// Error returns the string representation of the error.
func (e *ParseError) Error() string {
if e.Message != "" {
return fmt.Sprintf("%s at line %d, char %d", e.Message, e.Pos.Line+1, e.Pos.Char+1)
}
return fmt.Sprintf("found %s, expected %s at line %d, char %d", e.Found, strings.Join(e.Expected, ", "), e.Pos.Line+1, e.Pos.Char+1)
}