php-parser/parser/parser.go

35 lines
621 B
Go
Raw Normal View History

package parser
2018-04-10 17:15:15 +00:00
import (
"github.com/z7zmey/php-parser/errors"
"github.com/z7zmey/php-parser/node"
2019-12-26 15:57:56 +00:00
"github.com/z7zmey/php-parser/php5"
"github.com/z7zmey/php-parser/php7"
"github.com/z7zmey/php-parser/version"
2018-04-10 17:15:15 +00:00
)
// Parser interface
2018-04-10 17:15:15 +00:00
type Parser interface {
Parse() int
GetRootNode() node.Node
GetErrors() []*errors.Error
2019-02-25 14:52:47 +00:00
WithFreeFloating()
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
}