php-parser/pkg/parser/parser.go

35 lines
650 B
Go
Raw Normal View History

package parser
2018-04-10 17:15:15 +00:00
import (
2020-05-12 21:16:36 +00:00
"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"
2018-04-10 17:15:15 +00:00
)
// Parser interface
2018-04-10 17:15:15 +00:00
type Parser interface {
Parse() int
2020-05-12 21:16:36 +00:00
GetRootNode() ast.Vertex
2018-04-10 17:15:15 +00:00
GetErrors() []*errors.Error
2020-05-12 21:16:36 +00:00
WithTokens()
2018-04-10 17:15:15 +00:00
}
2019-12-26 15:57:56 +00:00
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
}