#67: skip unexpected character in input
This commit is contained in:
@@ -20,7 +20,6 @@ type Parser struct {
|
||||
path string
|
||||
currentToken *scanner.Token
|
||||
positionBuilder *parser.PositionBuilder
|
||||
errors []*errors.Error
|
||||
rootNode node.Node
|
||||
comments parser.Comments
|
||||
positions parser.Positions
|
||||
@@ -38,7 +37,6 @@ func NewParser(src io.Reader, path string) *Parser {
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
nil,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,13 +48,13 @@ func (l *Parser) Lex(lval *yySymType) int {
|
||||
}
|
||||
|
||||
func (l *Parser) Error(msg string) {
|
||||
l.errors = append(l.errors, errors.NewError(msg, l.currentToken))
|
||||
l.Lexer.Errors = append(l.Lexer.Errors, errors.NewError(msg, l.currentToken.Position))
|
||||
}
|
||||
|
||||
// Parse the php7 Parser entrypoint
|
||||
func (l *Parser) Parse() int {
|
||||
// init
|
||||
l.errors = nil
|
||||
l.Lexer.Errors = nil
|
||||
l.rootNode = nil
|
||||
l.comments = parser.Comments{}
|
||||
l.positions = parser.Positions{}
|
||||
@@ -92,7 +90,7 @@ func (l *Parser) GetRootNode() node.Node {
|
||||
|
||||
// GetErrors returns errors list
|
||||
func (l *Parser) GetErrors() []*errors.Error {
|
||||
return l.errors
|
||||
return l.Lexer.Errors
|
||||
}
|
||||
|
||||
// GetComments returns comments list
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Code generated by goyacc -o php5/php5.go php5/php5.y. DO NOT EDIT.
|
||||
|
||||
//line php5/php5.y:2
|
||||
package php5
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/kylelemons/godebug/pretty"
|
||||
"github.com/z7zmey/php-parser/errors"
|
||||
"github.com/z7zmey/php-parser/node/expr"
|
||||
"github.com/z7zmey/php-parser/node/expr/assign"
|
||||
"github.com/z7zmey/php-parser/node/expr/binary"
|
||||
@@ -13,6 +14,7 @@ import (
|
||||
"github.com/z7zmey/php-parser/node/name"
|
||||
"github.com/z7zmey/php-parser/node/scalar"
|
||||
"github.com/z7zmey/php-parser/php5"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/stmt"
|
||||
@@ -3750,3 +3752,23 @@ CAD;
|
||||
actual := php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestPhp5ControlCharsErrors(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},
|
||||
},
|
||||
}
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual := php5parser.GetErrors()
|
||||
assertEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user