[#82] handle php version
This commit is contained in:
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/z7zmey/php-parser/errors"
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/parser"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/positionbuilder"
|
||||
"github.com/z7zmey/php-parser/scanner"
|
||||
)
|
||||
|
||||
@@ -19,13 +19,14 @@ func (lval *yySymType) Token(t *scanner.Token) {
|
||||
type Parser struct {
|
||||
Lexer scanner.Scanner
|
||||
currentToken *scanner.Token
|
||||
positionBuilder *parser.PositionBuilder
|
||||
positionBuilder *positionbuilder.PositionBuilder
|
||||
rootNode node.Node
|
||||
}
|
||||
|
||||
// NewParser creates and returns new Parser
|
||||
func NewParser(src []byte) *Parser {
|
||||
func NewParser(src []byte, v string) *Parser {
|
||||
lexer := scanner.NewLexer(src)
|
||||
lexer.PHPVersion = v
|
||||
|
||||
return &Parser{
|
||||
lexer,
|
||||
@@ -61,7 +62,7 @@ func (l *Parser) Parse() int {
|
||||
// init
|
||||
l.Lexer.SetErrors(nil)
|
||||
l.rootNode = nil
|
||||
l.positionBuilder = &parser.PositionBuilder{}
|
||||
l.positionBuilder = &positionbuilder.PositionBuilder{}
|
||||
|
||||
// parse
|
||||
|
||||
|
||||
@@ -381,7 +381,7 @@ CAD;
|
||||
`
|
||||
|
||||
for n := 0; n < b.N; n++ {
|
||||
php7parser := php7.NewParser([]byte(src))
|
||||
php7parser := php7.NewParser([]byte(src), "7.4")
|
||||
php7parser.Parse()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16118,7 +16118,7 @@ func TestPhp7(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
php7parser := php7.NewParser([]byte(src))
|
||||
php7parser := php7.NewParser([]byte(src), "7.4")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
@@ -16233,7 +16233,7 @@ func TestPhp5Strings(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
php7parser := php7.NewParser([]byte(src))
|
||||
php7parser := php7.NewParser([]byte(src), "7.4")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
@@ -16423,7 +16423,7 @@ CAD;
|
||||
},
|
||||
}
|
||||
|
||||
php7parser := php7.NewParser([]byte(src))
|
||||
php7parser := php7.NewParser([]byte(src), "7.4")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
@@ -16443,7 +16443,7 @@ func TestPhp7ControlCharsErrors(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
php7parser := php7.NewParser([]byte(src))
|
||||
php7parser := php7.NewParser([]byte(src), "7.4")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetErrors()
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
Reference in New Issue
Block a user