php-parser/pkg/lexer/lexer.go

29 lines
593 B
Go
Raw Normal View History

package lexer
import (
"errors"
"github.com/laytan/php-parser/internal/php7"
"github.com/laytan/php-parser/internal/php8"
"github.com/laytan/php-parser/pkg/conf"
"github.com/laytan/php-parser/pkg/token"
)
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
}