refactor php7

This commit is contained in:
Vadym Slizov
2020-05-13 00:16:36 +03:00
parent aab9da03f0
commit 6a84d58ee6
54 changed files with 29034 additions and 28821 deletions

34
pkg/parser/parser.go Normal file
View File

@@ -0,0 +1,34 @@
package parser
import (
"github.com/z7zmey/php-parser/internal/php5"
"github.com/z7zmey/php-parser/internal/php7"
"github.com/z7zmey/php-parser/internal/version"
"github.com/z7zmey/php-parser/pkg/ast"
"github.com/z7zmey/php-parser/pkg/errors"
)
// Parser interface
type Parser interface {
Parse() int
GetRootNode() ast.Vertex
GetErrors() []*errors.Error
WithTokens()
}
func NewParser(src []byte, v string) (Parser, error) {
var parser Parser
r, err := version.Compare(v, "7.0")
if err != nil {
return nil, err
}
if r == -1 {
parser = php5.NewParser(src, v)
} else {
parser = php7.NewParser(src, v)
}
return parser, nil
}