[#82] handle php version

This commit is contained in:
z7zmey
2019-12-26 17:57:56 +02:00
parent 6afa2a089b
commit ec6be0d9bd
90 changed files with 673 additions and 616 deletions

View File

@@ -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,
@@ -62,7 +63,7 @@ func (l *Parser) Parse() int {
// init
l.Lexer.SetErrors(nil)
l.rootNode = nil
l.positionBuilder = &parser.PositionBuilder{}
l.positionBuilder = &positionbuilder.PositionBuilder{}
// parse

View File

@@ -413,7 +413,7 @@ CAD;
`
for n := 0; n < b.N; n++ {
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
}
}

View File

@@ -18401,7 +18401,7 @@ func TestPhp5(t *testing.T) {
},
}
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual := php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -18516,7 +18516,7 @@ func TestPhp5Strings(t *testing.T) {
},
}
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual := php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -18706,7 +18706,7 @@ CAD;
},
}
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual := php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
@@ -18726,7 +18726,7 @@ func TestPhp5ControlCharsErrors(t *testing.T) {
},
}
php5parser := php5.NewParser([]byte(src))
php5parser := php5.NewParser([]byte(src), "5.6")
php5parser.Parse()
actual := php5parser.GetErrors()
assert.DeepEqual(t, expected, actual)