2018-01-26 13:24:56 +00:00
|
|
|
package php7
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
goToken "go/token"
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"github.com/cznic/golex/lex"
|
|
|
|
|
2018-04-09 20:08:29 +00:00
|
|
|
"github.com/z7zmey/php-parser/errors"
|
2018-01-26 13:24:56 +00:00
|
|
|
"github.com/z7zmey/php-parser/scanner"
|
|
|
|
"github.com/z7zmey/php-parser/token"
|
|
|
|
)
|
|
|
|
|
|
|
|
type lexer struct {
|
2018-02-06 10:39:42 +00:00
|
|
|
scanner.Lexer
|
2018-04-09 20:08:29 +00:00
|
|
|
lastToken *token.Token
|
|
|
|
errors []*errors.Error
|
2018-01-26 13:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (l *lexer) Lex(lval *yySymType) int {
|
2018-04-09 20:08:29 +00:00
|
|
|
t := l.Lexer.Lex(lval)
|
|
|
|
l.lastToken = &lval.token
|
|
|
|
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *lexer) Error(msg string) {
|
|
|
|
l.errors = append(l.errors, errors.NewError(msg, *l.lastToken))
|
2018-01-26 13:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (lval *yySymType) Token(t token.Token) {
|
2018-02-06 10:39:42 +00:00
|
|
|
lval.token = t
|
2018-01-26 13:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newLexer(src io.Reader, fName string) *lexer {
|
|
|
|
file := goToken.NewFileSet().AddFile(fName, -1, 1<<31-1)
|
|
|
|
lx, err := lex.New(file, bufio.NewReader(src), lex.RuneClass(scanner.Rune2Class))
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2018-04-09 20:08:29 +00:00
|
|
|
scanner := scanner.Lexer{
|
|
|
|
Lexer: lx,
|
|
|
|
StateStack: []int{0},
|
|
|
|
PhpDocComment: "",
|
|
|
|
Comments: nil,
|
|
|
|
}
|
|
|
|
|
2018-01-26 13:24:56 +00:00
|
|
|
return &lexer{
|
2018-04-09 20:08:29 +00:00
|
|
|
scanner,
|
|
|
|
nil,
|
|
|
|
nil,
|
2018-01-26 13:24:56 +00:00
|
|
|
}
|
|
|
|
}
|