feat: expose the lexer to be used by users

This commit is contained in:
Laytan Laats
2023-04-11 22:38:29 +02:00
parent f98b59a5f0
commit 6b3673ece4
3 changed files with 41 additions and 13 deletions

28
pkg/lexer/lexer.go Normal file
View File

@@ -0,0 +1,28 @@
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
}