[refactoring] scanner.Lexer.withHiddenTokens
This commit is contained in:
@@ -21,17 +21,23 @@ type Parser struct {
|
||||
positionBuilder *positionbuilder.PositionBuilder
|
||||
rootNode ast.Vertex
|
||||
errors []*errors.Error
|
||||
withTokens bool
|
||||
}
|
||||
|
||||
// NewParser creates and returns new Parser
|
||||
func NewParser(src []byte, v string) *Parser {
|
||||
parser := &Parser{}
|
||||
func NewParser(src []byte, v string, withTokens bool) *Parser {
|
||||
parser := &Parser{
|
||||
withTokens: withTokens,
|
||||
}
|
||||
|
||||
lexer := scanner.NewLexer(src, func(e *errors.Error) {
|
||||
parser.errors = append(parser.errors, e)
|
||||
})
|
||||
lexer.PHPVersion = v
|
||||
scannerConfig := scanner.Config{
|
||||
WithHiddenTokens: withTokens,
|
||||
ErrHandlerFunc: func(e *errors.Error) {
|
||||
parser.errors = append(parser.errors, e)
|
||||
},
|
||||
}
|
||||
|
||||
lexer := scanner.NewLexer(src, v, scannerConfig)
|
||||
parser.Lexer = lexer
|
||||
|
||||
return parser
|
||||
@@ -57,10 +63,6 @@ func (l *Parser) GetErrors() []*errors.Error {
|
||||
return l.errors
|
||||
}
|
||||
|
||||
func (l *Parser) WithTokens() {
|
||||
l.Lexer.SetWithHiddenTokens(true)
|
||||
}
|
||||
|
||||
// Parse the php7 Parser entrypoint
|
||||
func (l *Parser) Parse() int {
|
||||
// init
|
||||
@@ -96,7 +98,7 @@ func isDollar(r rune) bool {
|
||||
}
|
||||
|
||||
func (l *Parser) MoveFreeFloating(src ast.Vertex, dst ast.Vertex) {
|
||||
if l.Lexer.GetWithHiddenTokens() == false {
|
||||
if l.withTokens == false {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -109,7 +111,7 @@ func (l *Parser) MoveFreeFloating(src ast.Vertex, dst ast.Vertex) {
|
||||
}
|
||||
|
||||
func (l *Parser) setFreeFloating(dst ast.Vertex, p token.Position, strings []token.Token) {
|
||||
if l.Lexer.GetWithHiddenTokens() == false {
|
||||
if l.withTokens == false {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -126,7 +128,7 @@ func (l *Parser) setFreeFloating(dst ast.Vertex, p token.Position, strings []tok
|
||||
}
|
||||
|
||||
func (l *Parser) GetFreeFloatingToken(t *scanner.Token) []token.Token {
|
||||
if l.Lexer.GetWithHiddenTokens() == false {
|
||||
if l.withTokens == false {
|
||||
return []token.Token{}
|
||||
}
|
||||
|
||||
@@ -139,7 +141,7 @@ func (l *Parser) GetFreeFloatingToken(t *scanner.Token) []token.Token {
|
||||
}
|
||||
|
||||
func (l *Parser) addDollarToken(v ast.Vertex) {
|
||||
if l.Lexer.GetWithHiddenTokens() == false {
|
||||
if l.withTokens == false {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -152,7 +154,7 @@ func (l *Parser) addDollarToken(v ast.Vertex) {
|
||||
}
|
||||
|
||||
func (l *Parser) splitSemiColonAndPhpCloseTag(htmlNode ast.Vertex, prevNode ast.Vertex) {
|
||||
if l.Lexer.GetWithHiddenTokens() == false {
|
||||
if l.withTokens == false {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -381,7 +381,7 @@ CAD;
|
||||
`
|
||||
|
||||
for n := 0; n < b.N; n++ {
|
||||
php7parser := php7.NewParser([]byte(src), "7.4")
|
||||
php7parser := php7.NewParser([]byte(src), "7.4", false)
|
||||
php7parser.Parse()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19633,7 +19633,7 @@ func TestPhp7(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
php7parser := php7.NewParser([]byte(src), "7.4")
|
||||
php7parser := php7.NewParser([]byte(src), "7.4", false)
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
@@ -19770,7 +19770,7 @@ func TestPhp5Strings(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
php7parser := php7.NewParser([]byte(src), "7.4")
|
||||
php7parser := php7.NewParser([]byte(src), "7.4", false)
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
@@ -19996,7 +19996,7 @@ CAD;
|
||||
},
|
||||
}
|
||||
|
||||
php7parser := php7.NewParser([]byte(src), "7.4")
|
||||
php7parser := php7.NewParser([]byte(src), "7.4", false)
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
@@ -20016,7 +20016,7 @@ func TestPhp7ControlCharsErrors(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
php7parser := php7.NewParser([]byte(src), "7.4")
|
||||
php7parser := php7.NewParser([]byte(src), "7.4", false)
|
||||
php7parser.Parse()
|
||||
actual := php7parser.GetErrors()
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
Reference in New Issue
Block a user