feat: expose the lexer to be used by users
This commit is contained in:
28
pkg/lexer/lexer.go
Normal file
28
pkg/lexer/lexer.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user