[refactoring] remove lexer config struct
This commit is contained in:
		
							parent
							
								
									7eff83624e
								
							
						
					
					
						commit
						424f7a132c
					
				| @ -25,14 +25,9 @@ func NewParser(src []byte, v string, withTokens bool) *Parser { | |||||||
| 		withTokens: withTokens, | 		withTokens: withTokens, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	scannerConfig := scanner.Config{ | 	lexer := scanner.NewLexer(src, v, withTokens, func(e *errors.Error) { | ||||||
| 		WithHiddenTokens: withTokens, |  | ||||||
| 		ErrHandlerFunc: func(e *errors.Error) { |  | ||||||
| 		parser.errors = append(parser.errors, e) | 		parser.errors = append(parser.errors, e) | ||||||
| 		}, | 	}) | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	lexer := scanner.NewLexer(src, v, scannerConfig) |  | ||||||
| 	parser.Lexer = lexer | 	parser.Lexer = lexer | ||||||
| 
 | 
 | ||||||
| 	return parser | 	return parser | ||||||
|  | |||||||
| @ -24,53 +24,48 @@ func NewParser(src []byte, v string, withTokens bool) *Parser { | |||||||
| 		withTokens: withTokens, | 		withTokens: withTokens, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	scannerConfig := scanner.Config{ | 	lexer := scanner.NewLexer(src, v, withTokens, func(e *errors.Error) { | ||||||
| 		WithHiddenTokens: withTokens, |  | ||||||
| 		ErrHandlerFunc: func(e *errors.Error) { |  | ||||||
| 		parser.errors = append(parser.errors, e) | 		parser.errors = append(parser.errors, e) | ||||||
| 		}, | 	}) | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	lexer := scanner.NewLexer(src, v, scannerConfig) |  | ||||||
| 	parser.Lexer = lexer | 	parser.Lexer = lexer | ||||||
| 
 | 
 | ||||||
| 	return parser | 	return parser | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (l *Parser) Lex(lval *yySymType) int { | func (p *Parser) Lex(lval *yySymType) int { | ||||||
| 	t := l.Lexer.Lex() | 	t := p.Lexer.Lex() | ||||||
| 
 | 
 | ||||||
| 	l.currentToken = t | 	p.currentToken = t | ||||||
| 	lval.token = t | 	lval.token = t | ||||||
| 
 | 
 | ||||||
| 	return int(t.ID) | 	return int(t.ID) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (l *Parser) Error(msg string) { | func (p *Parser) Error(msg string) { | ||||||
| 	var pos = l.currentToken.Position | 	var pos = p.currentToken.Position | ||||||
| 
 | 
 | ||||||
| 	l.errors = append(l.errors, errors.NewError(msg, &pos)) | 	p.errors = append(p.errors, errors.NewError(msg, &pos)) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // GetErrors returns errors list | // GetErrors returns errors list | ||||||
| func (l *Parser) GetErrors() []*errors.Error { | func (p *Parser) GetErrors() []*errors.Error { | ||||||
| 	return l.errors | 	return p.errors | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Parse the php7 Parser entrypoint | // Parse the php7 Parser entrypoint | ||||||
| func (l *Parser) Parse() int { | func (p *Parser) Parse() int { | ||||||
| 	// init | 	// init | ||||||
| 	l.errors = nil | 	p.errors = nil | ||||||
| 	l.rootNode = nil | 	p.rootNode = nil | ||||||
| 
 | 
 | ||||||
| 	// parse | 	// parse | ||||||
| 
 | 
 | ||||||
| 	return yyParse(l) | 	return yyParse(p) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // GetRootNode returns root node | // GetRootNode returns root node | ||||||
| func (l *Parser) GetRootNode() ast.Vertex { | func (p *Parser) GetRootNode() ast.Vertex { | ||||||
| 	return l.rootNode | 	return p.rootNode | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // helpers | // helpers | ||||||
| @ -86,8 +81,8 @@ func isDollar(r rune) bool { | |||||||
| 	return r == '$' | 	return r == '$' | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (l *Parser) MoveFreeFloating(src ast.Vertex, dst ast.Vertex) { | func (p *Parser) MoveFreeFloating(src ast.Vertex, dst ast.Vertex) { | ||||||
| 	if l.withTokens == false { | 	if p.withTokens == false { | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| @ -95,7 +90,7 @@ func (l *Parser) MoveFreeFloating(src ast.Vertex, dst ast.Vertex) { | |||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	l.setFreeFloating(dst, token.Start, src.GetNode().Tokens[token.Start]) | 	p.setFreeFloating(dst, token.Start, src.GetNode().Tokens[token.Start]) | ||||||
| 	delete(src.GetNode().Tokens, token.Start) | 	delete(src.GetNode().Tokens, token.Start) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -116,8 +111,8 @@ func (p *Parser) setFreeFloating(dst ast.Vertex, pos token.Position, strings []t | |||||||
| 	(*dstCollection)[pos] = strings | 	(*dstCollection)[pos] = strings | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (l *Parser) GetFreeFloatingToken(t *scanner.Token) []token.Token { | func (p *Parser) GetFreeFloatingToken(t *scanner.Token) []token.Token { | ||||||
| 	if l.withTokens == false { | 	if p.withTokens == false { | ||||||
| 		return []token.Token{} | 		return []token.Token{} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| @ -129,12 +124,12 @@ func (l *Parser) GetFreeFloatingToken(t *scanner.Token) []token.Token { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (l *Parser) addDollarToken(v ast.Vertex) { | func (p *Parser) addDollarToken(v ast.Vertex) { | ||||||
| 	if l.withTokens == false { | 	if p.withTokens == false { | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	l.setFreeFloating(v, token.Dollar, []token.Token{ | 	p.setFreeFloating(v, token.Dollar, []token.Token{ | ||||||
| 		{ | 		{ | ||||||
| 			ID:    token.ID('$'), | 			ID:    token.ID('$'), | ||||||
| 			Value: []byte("$"), | 			Value: []byte("$"), | ||||||
| @ -142,8 +137,8 @@ func (l *Parser) addDollarToken(v ast.Vertex) { | |||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (l *Parser) splitSemiColonAndPhpCloseTag(htmlNode ast.Vertex, prevNode ast.Vertex) { | func (p *Parser) splitSemiColonAndPhpCloseTag(htmlNode ast.Vertex, prevNode ast.Vertex) { | ||||||
| 	if l.withTokens == false { | 	if p.withTokens == false { | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| @ -154,7 +149,7 @@ func (l *Parser) splitSemiColonAndPhpCloseTag(htmlNode ast.Vertex, prevNode ast. | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if semiColon[0].Value[0] == ';' { | 	if semiColon[0].Value[0] == ';' { | ||||||
| 		l.setFreeFloating(prevNode, token.SemiColon, []token.Token{ | 		p.setFreeFloating(prevNode, token.SemiColon, []token.Token{ | ||||||
| 			{ | 			{ | ||||||
| 				ID:    token.ID(';'), | 				ID:    token.ID(';'), | ||||||
| 				Value: semiColon[0].Value[0:1], | 				Value: semiColon[0].Value[0:1], | ||||||
| @ -181,7 +176,7 @@ func (l *Parser) splitSemiColonAndPhpCloseTag(htmlNode ast.Vertex, prevNode ast. | |||||||
| 		Value: semiColon[0].Value[vlen-tlen:], | 		Value: semiColon[0].Value[vlen-tlen:], | ||||||
| 	}) | 	}) | ||||||
| 
 | 
 | ||||||
| 	l.setFreeFloating(htmlNode, token.Start, append(phpCloseTag, htmlNode.GetNode().Tokens[token.Start]...)) | 	p.setFreeFloating(htmlNode, token.Start, append(phpCloseTag, htmlNode.GetNode().Tokens[token.Start]...)) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (p *Parser) returnTokenToPool(yyDollar []yySymType, yyVAL *yySymType) { | func (p *Parser) returnTokenToPool(yyDollar []yySymType, yyVAL *yySymType) { | ||||||
|  | |||||||
| @ -10,13 +10,6 @@ import ( | |||||||
| 	"github.com/z7zmey/php-parser/pkg/token" | 	"github.com/z7zmey/php-parser/pkg/token" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type Config struct { |  | ||||||
| 	WithHiddenTokens bool |  | ||||||
| 	ErrHandlerFunc   func(*errors.Error) |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| var DefaultConfig = Config{} |  | ||||||
| 
 |  | ||||||
| type Lexer struct { | type Lexer struct { | ||||||
| 	data             []byte | 	data             []byte | ||||||
| 	phpVersion       string | 	phpVersion       string | ||||||
| @ -34,12 +27,12 @@ type Lexer struct { | |||||||
| 	newLines     NewLines | 	newLines     NewLines | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func NewLexer(data []byte, phpVersion string, config Config) *Lexer { | func NewLexer(data []byte, phpVersion string, withHiddenTokens bool, errHandlerFunc func(*errors.Error)) *Lexer { | ||||||
| 	lex := &Lexer{ | 	lex := &Lexer{ | ||||||
| 		data:             data, | 		data:             data, | ||||||
| 		phpVersion:       phpVersion, | 		phpVersion:       phpVersion, | ||||||
| 		errHandlerFunc:   config.ErrHandlerFunc, | 		withHiddenTokens: withHiddenTokens, | ||||||
| 		withHiddenTokens: config.WithHiddenTokens, | 		errHandlerFunc:   errHandlerFunc, | ||||||
| 
 | 
 | ||||||
| 		pe:    len(data), | 		pe:    len(data), | ||||||
| 		stack: make([]int, 0), | 		stack: make([]int, 0), | ||||||
|  | |||||||
| @ -353,7 +353,7 @@ func TestTokens(t *testing.T) { | |||||||
| 		T_UNSET_CAST.String(), | 		T_UNSET_CAST.String(), | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 	actual := []string{} | 	actual := []string{} | ||||||
| 
 | 
 | ||||||
| @ -381,7 +381,7 @@ func TestShebang(t *testing.T) { | |||||||
| 		"\n", | 		"\n", | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 	actual := []string{} | 	actual := []string{} | ||||||
| 
 | 
 | ||||||
| @ -401,7 +401,7 @@ func TestShebangHtml(t *testing.T) { | |||||||
| 0.1 | 0.1 | ||||||
| ` | ` | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 
 | 
 | ||||||
| 	tkn := lexer.Lex() | 	tkn := lexer.Lex() | ||||||
| @ -451,7 +451,7 @@ func TestNumberTokens(t *testing.T) { | |||||||
| 		T_DNUMBER.String(), | 		T_DNUMBER.String(), | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 	actual := []string{} | 	actual := []string{} | ||||||
| 
 | 
 | ||||||
| @ -508,7 +508,7 @@ func TestConstantStrings(t *testing.T) { | |||||||
| 		T_CONSTANT_ENCAPSED_STRING.String(), | 		T_CONSTANT_ENCAPSED_STRING.String(), | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 	actual := []string{} | 	actual := []string{} | ||||||
| 
 | 
 | ||||||
| @ -555,7 +555,7 @@ func TestSingleQuoteStringTokens(t *testing.T) { | |||||||
| 		T_CONSTANT_ENCAPSED_STRING.String(), | 		T_CONSTANT_ENCAPSED_STRING.String(), | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	actual := []string{} | 	actual := []string{} | ||||||
| 
 | 
 | ||||||
| 	for { | 	for { | ||||||
| @ -642,7 +642,7 @@ func TestTeplateStringTokens(t *testing.T) { | |||||||
| 		TokenID(int('"')).String(), | 		TokenID(int('"')).String(), | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 	actual := []string{} | 	actual := []string{} | ||||||
| 
 | 
 | ||||||
| @ -727,7 +727,7 @@ func TestBackquoteStringTokens(t *testing.T) { | |||||||
| 		TokenID(int('`')).String(), | 		TokenID(int('`')).String(), | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 	actual := []string{} | 	actual := []string{} | ||||||
| 
 | 
 | ||||||
| @ -821,7 +821,7 @@ CAT; | |||||||
| 		TokenID(int(';')).String(), | 		TokenID(int(';')).String(), | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 	actual := []string{} | 	actual := []string{} | ||||||
| 
 | 
 | ||||||
| @ -894,7 +894,7 @@ CAT | |||||||
| 		T_END_HEREDOC.String(), | 		T_END_HEREDOC.String(), | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 	actual := []string{} | 	actual := []string{} | ||||||
| 
 | 
 | ||||||
| @ -933,7 +933,7 @@ CAT; | |||||||
| 		TokenID(int(';')).String(), | 		TokenID(int(';')).String(), | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 	actual := []string{} | 	actual := []string{} | ||||||
| 
 | 
 | ||||||
| @ -964,7 +964,7 @@ func TestHereDocTokens73(t *testing.T) { | |||||||
| 		T_VARIABLE.String(), | 		T_VARIABLE.String(), | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 	actual := []string{} | 	actual := []string{} | ||||||
| 
 | 
 | ||||||
| @ -994,7 +994,7 @@ CAT;` | |||||||
| 		TokenID(int(';')).String(), | 		TokenID(int(';')).String(), | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.phpVersion = "7.2" | 	lexer.phpVersion = "7.2" | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 	actual := []string{} | 	actual := []string{} | ||||||
| @ -1027,7 +1027,7 @@ func TestInlineHtmlNopTokens(t *testing.T) { | |||||||
| 		T_INLINE_HTML.String(), | 		T_INLINE_HTML.String(), | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 	actual := []string{} | 	actual := []string{} | ||||||
| 
 | 
 | ||||||
| @ -1062,7 +1062,7 @@ func TestStringTokensAfterVariable(t *testing.T) { | |||||||
| 		"\"", | 		"\"", | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	actual := []string{} | 	actual := []string{} | ||||||
| 	actualTokens := []string{} | 	actualTokens := []string{} | ||||||
| 
 | 
 | ||||||
| @ -1095,7 +1095,7 @@ func TestSlashAfterVariable(t *testing.T) { | |||||||
| 		"3", | 		"3", | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	actual := []string{} | 	actual := []string{} | ||||||
| 	actualTokens := []string{} | 	actualTokens := []string{} | ||||||
| 
 | 
 | ||||||
| @ -1132,7 +1132,7 @@ func TestCommentEnd(t *testing.T) { | |||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 
 | 
 | ||||||
| 	lexer.Lex() | 	lexer.Lex() | ||||||
| @ -1161,7 +1161,7 @@ func TestCommentNewLine(t *testing.T) { | |||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 
 | 
 | ||||||
| 	tkn := lexer.Lex() | 	tkn := lexer.Lex() | ||||||
| @ -1190,7 +1190,7 @@ func TestCommentNewLine1(t *testing.T) { | |||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 
 | 
 | ||||||
| 	tkn := lexer.Lex() | 	tkn := lexer.Lex() | ||||||
| @ -1219,7 +1219,7 @@ func TestCommentNewLine2(t *testing.T) { | |||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 
 | 
 | ||||||
| 	tkn := lexer.Lex() | 	tkn := lexer.Lex() | ||||||
| @ -1249,7 +1249,7 @@ func TestCommentWithPhpEndTag(t *testing.T) { | |||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 
 | 
 | ||||||
| 	tkn := lexer.Lex() | 	tkn := lexer.Lex() | ||||||
| @ -1279,7 +1279,7 @@ func TestInlineComment(t *testing.T) { | |||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 
 | 
 | ||||||
| 	tkn := lexer.Lex() | 	tkn := lexer.Lex() | ||||||
| @ -1309,7 +1309,7 @@ func TestInlineComment2(t *testing.T) { | |||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 
 | 
 | ||||||
| 	lexer.Lex() | 	lexer.Lex() | ||||||
| @ -1343,7 +1343,7 @@ func TestEmptyInlineComment(t *testing.T) { | |||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 
 | 
 | ||||||
| 	lexer.Lex() | 	lexer.Lex() | ||||||
| @ -1373,7 +1373,7 @@ func TestEmptyInlineComment2(t *testing.T) { | |||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 
 | 
 | ||||||
| 	tkn := lexer.Lex() | 	tkn := lexer.Lex() | ||||||
| @ -1387,7 +1387,7 @@ func TestMethodCallTokens(t *testing.T) { | |||||||
| 	src := `<?php | 	src := `<?php | ||||||
| 	$a -> bar ( '' ) ;` | 	$a -> bar ( '' ) ;` | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 
 | 
 | ||||||
| 	expected := []token.Token{ | 	expected := []token.Token{ | ||||||
| @ -1469,7 +1469,7 @@ func TestYieldFromTokens(t *testing.T) { | |||||||
| 	src := `<?php | 	src := `<?php | ||||||
| 	yield from $a` | 	yield from $a` | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 	lexer.withHiddenTokens = true | 	lexer.withHiddenTokens = true | ||||||
| 
 | 
 | ||||||
| 	expected := []token.Token{ | 	expected := []token.Token{ | ||||||
| @ -1500,7 +1500,7 @@ func TestYieldFromTokens(t *testing.T) { | |||||||
| func TestVarNameByteChars(t *testing.T) { | func TestVarNameByteChars(t *testing.T) { | ||||||
| 	src := "<?php $\x80 $\xff" | 	src := "<?php $\x80 $\xff" | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 
 | 
 | ||||||
| 	tkn := lexer.Lex() | 	tkn := lexer.Lex() | ||||||
| 	assert.Equal(t, "$\x80", string(tkn.Value)) | 	assert.Equal(t, "$\x80", string(tkn.Value)) | ||||||
| @ -1512,7 +1512,7 @@ func TestVarNameByteChars(t *testing.T) { | |||||||
| func TestStringVarNameByteChars(t *testing.T) { | func TestStringVarNameByteChars(t *testing.T) { | ||||||
| 	src := "<?php \"$\x80 $\xff\"" | 	src := "<?php \"$\x80 $\xff\"" | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 
 | 
 | ||||||
| 	tkn := lexer.Lex() | 	tkn := lexer.Lex() | ||||||
| 	assert.Equal(t, "\"", string(tkn.Value)) | 	assert.Equal(t, "\"", string(tkn.Value)) | ||||||
| @ -1534,13 +1534,9 @@ func TestIgnoreControllCharacters(t *testing.T) { | |||||||
| 	src := "<?php \004 echo $b;" | 	src := "<?php \004 echo $b;" | ||||||
| 
 | 
 | ||||||
| 	var actualErr *errors.Error | 	var actualErr *errors.Error | ||||||
| 	config := Config{ | 	lexer := NewLexer([]byte(src), "7.4", false, func(e *errors.Error) { | ||||||
| 		ErrHandlerFunc: func(e *errors.Error) { |  | ||||||
| 		actualErr = e | 		actualErr = e | ||||||
| 		}, | 	}) | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", config) |  | ||||||
| 
 | 
 | ||||||
| 	expected := "echo" | 	expected := "echo" | ||||||
| 	tkn := lexer.Lex() | 	tkn := lexer.Lex() | ||||||
| @ -1562,7 +1558,7 @@ func TestIgnoreControllCharacters(t *testing.T) { | |||||||
| func TestIgnoreControllCharactersAtStringVarOffset(t *testing.T) { | func TestIgnoreControllCharactersAtStringVarOffset(t *testing.T) { | ||||||
| 	src := "<?php \"$a[test\004]\";" | 	src := "<?php \"$a[test\004]\";" | ||||||
| 
 | 
 | ||||||
| 	lexer := NewLexer([]byte(src), "7.4", DefaultConfig) | 	lexer := NewLexer([]byte(src), "7.4", false, nil) | ||||||
| 
 | 
 | ||||||
| 	expected := "\"" | 	expected := "\"" | ||||||
| 	tkn := lexer.Lex() | 	tkn := lexer.Lex() | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user