Merge branch 'master' into dev
This commit is contained in:
@@ -3,6 +3,8 @@ package php7
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
|
||||
"github.com/z7zmey/php-parser/meta"
|
||||
|
||||
"github.com/z7zmey/php-parser/errors"
|
||||
@@ -21,7 +23,6 @@ type Parser struct {
|
||||
path string
|
||||
currentToken *scanner.Token
|
||||
positionBuilder *parser.PositionBuilder
|
||||
errors []*errors.Error
|
||||
rootNode node.Node
|
||||
}
|
||||
|
||||
@@ -35,7 +36,6 @@ func NewParser(src io.Reader, path string) *Parser {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,14 @@ func (l *Parser) Lex(lval *yySymType) int {
|
||||
}
|
||||
|
||||
func (l *Parser) Error(msg string) {
|
||||
l.errors = append(l.errors, errors.NewError(msg, l.currentToken))
|
||||
pos := &position.Position{
|
||||
StartLine: l.currentToken.StartLine,
|
||||
EndLine: l.currentToken.EndLine,
|
||||
StartPos: l.currentToken.StartPos,
|
||||
EndPos: l.currentToken.EndPos,
|
||||
}
|
||||
|
||||
l.Lexer.Errors = append(l.Lexer.Errors, errors.NewError(msg, pos))
|
||||
}
|
||||
|
||||
func (l *Parser) WithMeta() {
|
||||
@@ -57,7 +64,7 @@ func (l *Parser) WithMeta() {
|
||||
// Parse the php7 Parser entrypoint
|
||||
func (l *Parser) Parse() int {
|
||||
// init
|
||||
l.errors = nil
|
||||
l.Lexer.Errors = nil
|
||||
l.rootNode = nil
|
||||
l.positionBuilder = &parser.PositionBuilder{}
|
||||
|
||||
@@ -78,7 +85,7 @@ func (l *Parser) GetRootNode() node.Node {
|
||||
|
||||
// GetErrors returns errors list
|
||||
func (l *Parser) GetErrors() []*errors.Error {
|
||||
return l.errors
|
||||
return l.Lexer.Errors
|
||||
}
|
||||
|
||||
// helpers
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Code generated by goyacc -o php7/php7.go php7/php7.y. DO NOT EDIT.
|
||||
|
||||
//line php7/php7.y:2
|
||||
package php7
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/kylelemons/godebug/pretty"
|
||||
"github.com/z7zmey/php-parser/errors"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/expr"
|
||||
"github.com/z7zmey/php-parser/node/expr/assign"
|
||||
@@ -16432,3 +16433,23 @@ CAD;
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestPhp7ControlCharsErrors(t *testing.T) {
|
||||
src := "<?php \004 echo $b; \"$a[\005test]\";"
|
||||
|
||||
expected := []*errors.Error{
|
||||
{
|
||||
Msg: "WARNING: Unexpected character in input: '\004' (ASCII=4)",
|
||||
Pos: &position.Position{1, 1, 7, 7},
|
||||
},
|
||||
{
|
||||
Msg: "WARNING: Unexpected character in input: '\005' (ASCII=5)",
|
||||
Pos: &position.Position{1, 1, 22, 22},
|
||||
},
|
||||
}
|
||||
|
||||
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetErrors()
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user