#67: skip unexpected character in input

This commit is contained in:
z7zmey
2018-11-05 16:56:27 +02:00
parent 4133a65afe
commit 69e3111221
12 changed files with 2633 additions and 2433 deletions

View File

@@ -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())