#18 replace heredocLabel variable from global

This commit is contained in:
z7zmey 2018-05-24 12:14:30 +03:00
parent 72cf9d106e
commit e7a9de3dfc
3 changed files with 28 additions and 31 deletions

View File

@ -440,6 +440,7 @@ type Lexer struct {
StateStack []int StateStack []int
PhpDocComment string PhpDocComment string
Comments []comment.Comment Comments []comment.Comment
heredocLabel []lex.Char
} }
// Rune2Class returns the rune integer id // Rune2Class returns the rune integer id
@ -467,7 +468,7 @@ func NewLexer(src io.Reader, fName string) *Lexer {
if err != nil { if err != nil {
panic(err) panic(err)
} }
return &Lexer{lx, []int{0}, "", nil} return &Lexer{lx, []int{0}, "", nil, nil}
} }
func (l *Lexer) ungetChars(n int) []lex.Char { func (l *Lexer) ungetChars(n int) []lex.Char {

View File

@ -29,8 +29,6 @@ const (
BACKQUOTE BACKQUOTE
) )
var heredocLabel []lex.Char
func isValidFirstVarNameRune(r rune) bool { func isValidFirstVarNameRune(r rune) bool {
return r >= 'A' && r <= 'Z' || r == '_' || r >= 'a' && r <= 'z' || r >= '\u007f' && r <= 'ÿ' return r >= 'A' && r <= 'Z' || r == '_' || r >= 'a' && r <= 'z' || r >= '\u007f' && r <= 'ÿ'
} }
@ -8494,19 +8492,19 @@ yyrule141: // [b]?\<\<\<[ \t]*({VAR_NAME}|([']{VAR_NAME}['])|(["]{VAR_NAME}["]))
default: default:
l.begin(HEREDOC) l.begin(HEREDOC)
} }
heredocLabel = make([]lex.Char, lblLast-lblFirst+1) l.heredocLabel = make([]lex.Char, lblLast-lblFirst+1)
copy(heredocLabel, tb[lblFirst:lblLast+1]) copy(l.heredocLabel, tb[lblFirst:lblLast+1])
ungetCnt := len(heredocLabel) ungetCnt := len(l.heredocLabel)
searchLabelAhead := []lex.Char{} searchLabelAhead := []lex.Char{}
for i := 0; i < len(heredocLabel); i++ { for i := 0; i < len(l.heredocLabel); i++ {
if c == -1 { if c == -1 {
break break
} }
searchLabelAhead = append(searchLabelAhead, l.Lookahead()) searchLabelAhead = append(searchLabelAhead, l.Lookahead())
c = l.Next() c = l.Next()
} }
if bytes.Equal(l.charsToBytes(heredocLabel), l.charsToBytes(searchLabelAhead)) && ';' == rune(c) { if bytes.Equal(l.charsToBytes(l.heredocLabel), l.charsToBytes(searchLabelAhead)) && ';' == rune(c) {
ungetCnt++ ungetCnt++
c = l.Next() c = l.Next()
if '\n' == rune(c) || '\r' == rune(c) { if '\n' == rune(c) || '\r' == rune(c) {
@ -8528,14 +8526,14 @@ yyrule142: // .|[ \t\n\r]
break break
} }
if '\n' == rune(c) || '\r' == rune(c) { if '\n' == rune(c) || '\r' == rune(c) {
if bytes.Equal(append(l.charsToBytes(heredocLabel), ';'), searchLabel) { if bytes.Equal(append(l.charsToBytes(l.heredocLabel), ';'), searchLabel) {
l.begin(HEREDOC_END) l.begin(HEREDOC_END)
tb = l.ungetChars(len(heredocLabel) + 1) tb = l.ungetChars(len(l.heredocLabel) + 1)
break break
} }
if bytes.Equal(l.charsToBytes(heredocLabel), searchLabel) { if bytes.Equal(l.charsToBytes(l.heredocLabel), searchLabel) {
l.begin(HEREDOC_END) l.begin(HEREDOC_END)
tb = l.ungetChars(len(heredocLabel)) tb = l.ungetChars(len(l.heredocLabel))
break break
} }
@ -8734,15 +8732,15 @@ yyrule152: // .|[ \t\n\r]
} }
fallthrough fallthrough
case '\n': case '\n':
if bytes.Equal(append(l.charsToBytes(heredocLabel), ';'), searchLabel) { if bytes.Equal(append(l.charsToBytes(l.heredocLabel), ';'), searchLabel) {
l.begin(HEREDOC_END) l.begin(HEREDOC_END)
tb = l.ungetChars(len(heredocLabel) + 1 + nls) tb = l.ungetChars(len(l.heredocLabel) + 1 + nls)
lval.Token(l.newToken(tb)) lval.Token(l.newToken(tb))
return T_ENCAPSED_AND_WHITESPACE return T_ENCAPSED_AND_WHITESPACE
} }
if bytes.Equal(l.charsToBytes(heredocLabel), searchLabel) { if bytes.Equal(l.charsToBytes(l.heredocLabel), searchLabel) {
l.begin(HEREDOC_END) l.begin(HEREDOC_END)
tb = l.ungetChars(len(heredocLabel) + nls) tb = l.ungetChars(len(l.heredocLabel) + nls)
lval.Token(l.newToken(tb)) lval.Token(l.newToken(tb))
return T_ENCAPSED_AND_WHITESPACE return T_ENCAPSED_AND_WHITESPACE
} }

View File

@ -28,8 +28,6 @@ const (
BACKQUOTE BACKQUOTE
) )
var heredocLabel []lex.Char
func isValidFirstVarNameRune(r rune) bool { func isValidFirstVarNameRune(r rune) bool {
return r >= 'A' && r <= 'Z' || r == '_' || r >= 'a' && r <= 'z' || r >= '\u007f' && r <= 'ÿ' return r >= 'A' && r <= 'Z' || r == '_' || r >= 'a' && r <= 'z' || r >= '\u007f' && r <= 'ÿ'
} }
@ -381,12 +379,12 @@ NEW_LINE (\r|\n|\r\n)
l.begin(HEREDOC) l.begin(HEREDOC)
} }
heredocLabel = make([]lex.Char, lblLast - lblFirst + 1) l.heredocLabel = make([]lex.Char, lblLast - lblFirst + 1)
copy(heredocLabel, tb[lblFirst:lblLast+1]) copy(l.heredocLabel, tb[lblFirst:lblLast+1])
ungetCnt := len(heredocLabel) ungetCnt := len(l.heredocLabel)
searchLabelAhead := []lex.Char{} searchLabelAhead := []lex.Char{}
for i := 0; i < len(heredocLabel); i++ { for i := 0; i < len(l.heredocLabel); i++ {
if c == -1 { if c == -1 {
break; break;
} }
@ -394,7 +392,7 @@ NEW_LINE (\r|\n|\r\n)
c = l.Next() c = l.Next()
} }
if bytes.Equal(l.charsToBytes(heredocLabel), l.charsToBytes(searchLabelAhead)) && ';' == rune(c) { if bytes.Equal(l.charsToBytes(l.heredocLabel), l.charsToBytes(searchLabelAhead)) && ';' == rune(c) {
ungetCnt++ ungetCnt++
c = l.Next() c = l.Next()
if '\n' == rune(c) || '\r' == rune(c) { if '\n' == rune(c) || '\r' == rune(c) {
@ -417,15 +415,15 @@ NEW_LINE (\r|\n|\r\n)
} }
if '\n' == rune(c) || '\r' == rune(c) { if '\n' == rune(c) || '\r' == rune(c) {
if bytes.Equal(append(l.charsToBytes(heredocLabel), ';'), searchLabel) { if bytes.Equal(append(l.charsToBytes(l.heredocLabel), ';'), searchLabel) {
l.begin(HEREDOC_END) l.begin(HEREDOC_END)
tb = l.ungetChars(len(heredocLabel)+1) tb = l.ungetChars(len(l.heredocLabel)+1)
break; break;
} }
if bytes.Equal(l.charsToBytes(heredocLabel), searchLabel) { if bytes.Equal(l.charsToBytes(l.heredocLabel), searchLabel) {
l.begin(HEREDOC_END) l.begin(HEREDOC_END)
tb = l.ungetChars(len(heredocLabel)) tb = l.ungetChars(len(l.heredocLabel))
break; break;
} }
@ -597,16 +595,16 @@ NEW_LINE (\r|\n|\r\n)
fallthrough fallthrough
case '\n': case '\n':
if bytes.Equal(append(l.charsToBytes(heredocLabel), ';'), searchLabel) { if bytes.Equal(append(l.charsToBytes(l.heredocLabel), ';'), searchLabel) {
l.begin(HEREDOC_END) l.begin(HEREDOC_END)
tb = l.ungetChars(len(heredocLabel)+1+nls) tb = l.ungetChars(len(l.heredocLabel)+1+nls)
lval.Token(l.newToken(tb)); lval.Token(l.newToken(tb));
return T_ENCAPSED_AND_WHITESPACE return T_ENCAPSED_AND_WHITESPACE
} }
if bytes.Equal(l.charsToBytes(heredocLabel), searchLabel) { if bytes.Equal(l.charsToBytes(l.heredocLabel), searchLabel) {
l.begin(HEREDOC_END) l.begin(HEREDOC_END)
tb = l.ungetChars(len(heredocLabel)+nls) tb = l.ungetChars(len(l.heredocLabel)+nls)
lval.Token(l.newToken(tb)); lval.Token(l.newToken(tb));
return T_ENCAPSED_AND_WHITESPACE return T_ENCAPSED_AND_WHITESPACE
} }