2023-04-11 20:38:29 +00:00
|
|
|
package lexer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2023-12-09 21:36:19 +00:00
|
|
|
"git.maride.cc/maride/php-parser/internal/php7"
|
|
|
|
"git.maride.cc/maride/php-parser/internal/php8"
|
|
|
|
"git.maride.cc/maride/php-parser/pkg/conf"
|
|
|
|
"git.maride.cc/maride/php-parser/pkg/token"
|
2023-04-11 20:38:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var ErrVersionOutOfRange = errors.New("the version is out of supported range")
|
|
|
|
|
|
|
|
type Lexer interface {
|
|
|
|
Lex() *token.Token
|
|
|
|
}
|
|
|
|
|
|
|
|
func New(src []byte, config conf.Config) (Lexer, error) {
|
|
|
|
if config.Version.InPhp7Range() {
|
|
|
|
return php7.NewLexer(src, config), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if config.Version.InPhp8Range() {
|
|
|
|
return php8.NewLexer(src, config), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, ErrVersionOutOfRange
|
|
|
|
}
|