refactoring: update api

This commit is contained in:
Vadym Slizov
2020-12-29 21:23:22 +02:00
parent cb4b4e69c4
commit e3b133f3de
17 changed files with 4086 additions and 1094 deletions

View File

@@ -1,9 +1,10 @@
package php5
import (
builder "github.com/z7zmey/php-parser/internal/position"
"github.com/z7zmey/php-parser/internal/position"
"github.com/z7zmey/php-parser/internal/scanner"
"github.com/z7zmey/php-parser/pkg/ast"
"github.com/z7zmey/php-parser/pkg/cfg"
"github.com/z7zmey/php-parser/pkg/errors"
"github.com/z7zmey/php-parser/pkg/token"
)
@@ -14,15 +15,15 @@ type Parser struct {
currentToken *token.Token
rootNode ast.Vertex
errHandlerFunc func(*errors.Error)
builder *builder.Builder
builder *position.Builder
}
// NewParser creates and returns new Parser
func NewParser(lexer *scanner.Lexer, errHandlerFunc func(*errors.Error)) *Parser {
func NewParser(lexer *scanner.Lexer, config cfg.Config) *Parser {
return &Parser{
Lexer: lexer,
errHandlerFunc: errHandlerFunc,
builder: builder.NewBuilder(),
errHandlerFunc: config.ErrorHandlerFunc,
builder: position.NewBuilder(),
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -6,6 +6,8 @@ import (
"github.com/z7zmey/php-parser/internal/php5"
"github.com/z7zmey/php-parser/internal/scanner"
"github.com/z7zmey/php-parser/pkg/cfg"
"github.com/z7zmey/php-parser/pkg/version"
)
func BenchmarkPhp5(b *testing.B) {
@@ -15,8 +17,14 @@ func BenchmarkPhp5(b *testing.B) {
}
for n := 0; n < b.N; n++ {
lexer := scanner.NewLexer([]byte(src), "5.6", nil)
php5parser := php5.NewParser(lexer, nil)
config := cfg.Config{
Version: &version.Version{
Major: 5,
Minor: 6,
},
}
lexer := scanner.NewLexer(src, config)
php5parser := php5.NewParser(lexer, config)
php5parser.Parse()
}
}