#67: skip unexpected character in input
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"sync"
|
||||
"unicode"
|
||||
|
||||
"github.com/z7zmey/php-parser/errors"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
|
||||
"github.com/cznic/golex/lex"
|
||||
@@ -446,6 +447,7 @@ type Lexer struct {
|
||||
tokenBytesBuf *bytes.Buffer
|
||||
TokenPool sync.Pool
|
||||
PositionPool sync.Pool
|
||||
Errors []*errors.Error
|
||||
}
|
||||
|
||||
// Rune2Class returns the rune integer id
|
||||
@@ -492,6 +494,21 @@ func NewLexer(src io.Reader, fName string) *Lexer {
|
||||
}
|
||||
}
|
||||
|
||||
func (l *Lexer) Error(msg string) {
|
||||
chars := l.Token()
|
||||
firstChar := chars[0]
|
||||
lastChar := chars[len(chars)-1]
|
||||
|
||||
pos := position.NewPosition(
|
||||
l.File.Line(firstChar.Pos()),
|
||||
l.File.Line(lastChar.Pos()),
|
||||
int(firstChar.Pos()),
|
||||
int(lastChar.Pos()),
|
||||
)
|
||||
|
||||
l.Errors = append(l.Errors, errors.NewError(msg, pos))
|
||||
}
|
||||
|
||||
func (l *Lexer) ungetChars(n int) []lex.Char {
|
||||
l.Unget(l.Lookahead())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user