MCPcopy Create free account
hub / github.com/araddon/qlbridge / LexRegex

Function LexRegex

lex/lexer.go:1106–1145  ·  view source on GitHub ↗

lex a regex: first character must be a / ^stats\./i .*/ ^stats.*/

(l *Lexer)

Source from the content-addressed store, hash-verified

1104// /^stats.*/
1105//
1106func LexRegex(l *Lexer) StateFn {
1107
1108 l.SkipWhiteSpaces()
1109 if l.IsEnd() {
1110 return l.errorToken("expected value but got EOF")
1111 }
1112
1113 rune := l.Next()
1114 if rune != '/' {
1115 return nil
1116 }
1117
1118 previousEscaped := rune == '/'
1119 // scan looking for ending character = /
1120 for rune = l.Next(); ; rune = l.Next() {
1121 if rune == eof {
1122 return l.errorToken("expected value but got EOF")
1123 }
1124 //u.Debugf("LexRegex rune=%v end?%v prevEscape?%v", string(rune), rune == eof, previousEscaped)
1125 if rune == '/' && !previousEscaped {
1126 // now that we have found what appears to be end, lets see if it
1127 // has a modifier - the i/g at end of /^stats\./i
1128 for rune = l.Next(); ; rune = l.Next() {
1129 //u.Debugf("LexRegex rune=%v end?%v prevEscape?%v", string(rune), rune == eof, previousEscaped)
1130 if rune == eof {
1131 l.Emit(TokenRegex)
1132 return nil
1133 //return l.errorToken("expected value but got EOF")
1134 }
1135 if isWhiteSpace(rune) {
1136 l.backup()
1137 l.Emit(TokenRegex)
1138 return nil
1139 }
1140 }
1141 }
1142
1143 previousEscaped = rune == '/'
1144 }
1145}
1146
1147// look for either an Expression or Identity
1148//

Callers 1

LexInfluxNameFunction · 0.92

Calls 7

isWhiteSpaceFunction · 0.85
SkipWhiteSpacesMethod · 0.80
errorTokenMethod · 0.80
EmitMethod · 0.80
backupMethod · 0.80
IsEndMethod · 0.65
NextMethod · 0.65

Tested by

no test coverage detected