Skip to content

Commit 45e523b

Browse files
committed
fix if the lua token is the name of the upstream
1 parent 48d8fdd commit 45e523b

File tree

1 file changed

+5
-24
lines changed

1 file changed

+5
-24
lines changed

lex.go

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,15 @@ func tokenize(reader io.Reader, tokenCh chan NgxToken, options LexOptions) {
103103
depth := 0
104104
var la, quote string
105105

106+
// check the lua token is not the directive start
107+
processdLine := make(map[int]bool)
108+
106109
scanner := bufio.NewScanner(reader)
107110
scanner.Split(bufio.ScanRunes)
108111

109112
emit := func(line int, quoted bool, err error) {
110113
tokenCh <- NgxToken{Value: token.String(), Line: line, IsQuoted: quoted, Error: err}
114+
processdLine[line] = true
111115
token.Reset()
112116
lexState = skipSpace
113117
}
@@ -158,7 +162,7 @@ func tokenize(reader io.Reader, tokenCh chan NgxToken, options LexOptions) {
158162

159163
if token.Len() > 0 {
160164
tokenStr := token.String()
161-
if ext, ok := externalLexers[tokenStr]; ok {
165+
if ext, ok := externalLexers[tokenStr]; ok && !processdLine[tokenLine] {
162166
emit(tokenStartLine, false, nil)
163167
externalScanner.tokenLine = tokenLine
164168
extTokenCh := ext.Lex(tokenStr)
@@ -440,26 +444,3 @@ func (ll *LuaLexer) Lex(matchedToken string) <-chan NgxToken {
440444

441445
return tokenCh
442446
}
443-
444-
// TODO: 1. check for opening brace?
445-
// assume nested parathesis only with () and [], no curly parathesis
446-
// ignore space until first {
447-
// // rewrite_by_lua_block x will be accepted -- work on this case
448-
// stricly check that first non space character is {
449-
450-
/* commit 2. do we strictly check for equal number of open and close braces rewite_by_lua_block { {1,2 // parser will use close from outside of lua block
451-
452-
http{ server {
453-
rewite_by_lua_block { {1,2
454-
455-
}}
456-
457-
==>
458-
scenario 1
459-
error for http and server block
460-
rewite_by_lua_block { {1,2}}
461-
462-
scenario 2
463-
error for rewite_by_lua_block with insufficient close
464-
http and server parse succeeds
465-
*/

0 commit comments

Comments
 (0)