refactor: move php7 scanner into php7 package
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package scanner
|
||||
package php7
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@@ -1,4 +1,4 @@
|
||||
package scanner
|
||||
package php7
|
||||
|
||||
type NewLines struct {
|
||||
data []int
|
||||
@@ -2,7 +2,6 @@ package php7
|
||||
|
||||
import (
|
||||
"github.com/VKCOM/php-parser/internal/position"
|
||||
"github.com/VKCOM/php-parser/internal/scanner"
|
||||
"github.com/VKCOM/php-parser/pkg/ast"
|
||||
"github.com/VKCOM/php-parser/pkg/conf"
|
||||
"github.com/VKCOM/php-parser/pkg/errors"
|
||||
@@ -11,7 +10,7 @@ import (
|
||||
|
||||
// Parser structure
|
||||
type Parser struct {
|
||||
Lexer *scanner.Lexer
|
||||
Lexer *Lexer
|
||||
currentToken *token.Token
|
||||
rootNode ast.Vertex
|
||||
errHandlerFunc func(*errors.Error)
|
||||
@@ -19,7 +18,7 @@ type Parser struct {
|
||||
}
|
||||
|
||||
// NewParser creates and returns new Parser
|
||||
func NewParser(lexer *scanner.Lexer, config conf.Config) *Parser {
|
||||
func NewParser(lexer *Lexer, config conf.Config) *Parser {
|
||||
return &Parser{
|
||||
Lexer: lexer,
|
||||
errHandlerFunc: config.ErrorHandlerFunc,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/VKCOM/php-parser/internal/php7"
|
||||
"github.com/VKCOM/php-parser/internal/scanner"
|
||||
"github.com/VKCOM/php-parser/pkg/conf"
|
||||
"github.com/VKCOM/php-parser/pkg/version"
|
||||
)
|
||||
@@ -24,7 +23,7 @@ func BenchmarkPhp7(b *testing.B) {
|
||||
Minor: 4,
|
||||
},
|
||||
}
|
||||
lexer := scanner.NewLexer(src, config)
|
||||
lexer := php7.NewLexer(src, config)
|
||||
php7parser := php7.NewParser(lexer, config)
|
||||
php7parser.Parse()
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// line internal/scanner/scanner.rl:1
|
||||
package scanner
|
||||
package php7
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -1,4 +1,4 @@
|
||||
package scanner
|
||||
package php7
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -500,4 +500,4 @@ func (lex *Lexer) Lex() *token.Token {
|
||||
tkn.ID = token.ID(tok)
|
||||
|
||||
return tkn
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package scanner
|
||||
package php7
|
||||
|
||||
import (
|
||||
"gotest.tools/assert"
|
||||
@@ -124,11 +124,13 @@ func (lex *Lexer) isHeredocEndBefore73(p int) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(lex.data) > p+l && lex.data[p+l] != ';' && lex.data[p+l] != '\r' && lex.data[p+l] != '\n' {
|
||||
if len(lex.data) > p+l && lex.data[p+l] != ';' && lex.data[p+l] != '\r' &&
|
||||
lex.data[p+l] != '\n' {
|
||||
return false
|
||||
}
|
||||
|
||||
if len(lex.data) > p+l+1 && lex.data[p+l] == ';' && lex.data[p+l+1] != '\r' && lex.data[p+l+1] != '\n' {
|
||||
if len(lex.data) > p+l+1 && lex.data[p+l] == ';' && lex.data[p+l+1] != '\r' &&
|
||||
lex.data[p+l+1] != '\n' {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -262,5 +264,6 @@ func isValidVarNameStart(r byte) bool {
|
||||
}
|
||||
|
||||
func isValidVarName(r byte) bool {
|
||||
return (r >= 'A' && r <= 'Z') || (r >= 'a' && r <= 'z') || (r >= '0' && r <= '9') || r == '_' || r >= 0x80
|
||||
return (r >= 'A' && r <= 'Z') || (r >= 'a' && r <= 'z') || (r >= '0' && r <= '9') || r == '_' ||
|
||||
r >= 0x80
|
||||
}
|
||||
|
||||
@@ -4177,7 +4177,7 @@ class Point {
|
||||
},
|
||||
},
|
||||
AmpersandTkn: &token.Token{
|
||||
ID: token.ID(57492),
|
||||
ID: token.T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG,
|
||||
Val: []byte("&"),
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
@@ -4302,7 +4302,7 @@ class Point {
|
||||
},
|
||||
},
|
||||
AmpersandTkn: &token.Token{
|
||||
ID: token.ID(57492),
|
||||
ID: token.T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG,
|
||||
Val: []byte("&"),
|
||||
FreeFloating: []*token.Token{
|
||||
{
|
||||
|
||||
@@ -539,4 +539,4 @@ func (lex *Lexer) Lex() *token.Token {
|
||||
tkn.ID = token.ID(tok)
|
||||
|
||||
return tkn
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,7 +317,7 @@ func TestTokens(t *testing.T) {
|
||||
token.ID(int('|')).String(),
|
||||
token.ID(int('/')).String(),
|
||||
token.ID(int('^')).String(),
|
||||
token.ID(T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG).String(),
|
||||
token.ID(token.T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG).String(),
|
||||
token.ID(int('+')).String(),
|
||||
token.ID(int('-')).String(),
|
||||
token.ID(int('*')).String(),
|
||||
|
||||
@@ -3,8 +3,8 @@ package tester
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/VKCOM/php-parser/internal/php7"
|
||||
"github.com/VKCOM/php-parser/internal/php8"
|
||||
"github.com/VKCOM/php-parser/internal/scanner"
|
||||
"github.com/VKCOM/php-parser/pkg/conf"
|
||||
"github.com/VKCOM/php-parser/pkg/token"
|
||||
"github.com/VKCOM/php-parser/pkg/version"
|
||||
@@ -46,7 +46,7 @@ func (l *LexerTokenFreeFloatingTestSuite) Run() {
|
||||
var lexer Lexer
|
||||
|
||||
if l.Version.Less(&version.Version{Major: 8, Minor: 0}) {
|
||||
lexer = scanner.NewLexer([]byte(l.Code), config)
|
||||
lexer = php7.NewLexer([]byte(l.Code), config)
|
||||
} else {
|
||||
lexer = php8.NewLexer([]byte(l.Code), config)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/VKCOM/php-parser/internal/php8"
|
||||
"github.com/VKCOM/php-parser/internal/scanner"
|
||||
"github.com/VKCOM/php-parser/internal/php7"
|
||||
"github.com/VKCOM/php-parser/pkg/conf"
|
||||
"github.com/VKCOM/php-parser/pkg/version"
|
||||
"gotest.tools/assert"
|
||||
@@ -41,7 +41,7 @@ func (l *LexerTokenStringTestSuite) Run() {
|
||||
var lexer Lexer
|
||||
|
||||
if l.Version.Less(&version.Version{Major: 8, Minor: 0}) {
|
||||
lexer = scanner.NewLexer([]byte(l.Code), config)
|
||||
lexer = php7.NewLexer([]byte(l.Code), config)
|
||||
} else {
|
||||
lexer = php8.NewLexer([]byte(l.Code), config)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/VKCOM/php-parser/internal/php8"
|
||||
"github.com/VKCOM/php-parser/internal/scanner"
|
||||
"github.com/VKCOM/php-parser/internal/php7"
|
||||
"github.com/VKCOM/php-parser/pkg/conf"
|
||||
"github.com/VKCOM/php-parser/pkg/token"
|
||||
"github.com/VKCOM/php-parser/pkg/version"
|
||||
@@ -53,7 +53,7 @@ func (l *LexerTokenStructTestSuite) Run() {
|
||||
var lexer Lexer
|
||||
|
||||
if l.Version.Less(&version.Version{Major: 8, Minor: 0}) {
|
||||
lexer = scanner.NewLexer([]byte(l.Code), config)
|
||||
lexer = php7.NewLexer([]byte(l.Code), config)
|
||||
} else {
|
||||
lexer = php8.NewLexer([]byte(l.Code), config)
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ func (p *ParserDumpTestSuite) UsePHP8() {
|
||||
}
|
||||
|
||||
func (p *ParserDumpTestSuite) Run() {
|
||||
p.t.Helper()
|
||||
|
||||
config := conf.Config{
|
||||
Version: &p.Version,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user