本文整理汇总了Golang中github.com/araddon/qlbridge/lex.Lexer类的典型用法代码示例。如果您正苦于以下问题:Golang Lexer类的具体用法?Golang Lexer怎么用?Golang Lexer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Lexer类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: verifyLexerTokens
func verifyLexerTokens(l *lex.Lexer, tokens []lex.Token) {
for _, goodToken := range tokens {
tok := l.NextToken()
if tok.T != goodToken.T || tok.V != goodToken.V {
panic(fmt.Sprintf("bad token: %v but wanted %v\n", tok, goodToken))
} else {
fmt.Printf("Got good token: %v\n", tok)
}
}
}
示例2: LexInfluxName
// lex value
//
// SIMPLE_NAME_VALUE | TABLE_NAME_VALUE | REGEX_VALUE
func LexInfluxName(l *lex.Lexer) lex.StateFn {
l.SkipWhiteSpaces()
firstChar := l.Peek()
u.Debugf("LexInfluxName: %v", string(firstChar))
switch firstChar {
case '"':
return lex.LexValue(l)
case '/':
// a regex
return lex.LexRegex(l)
}
return lex.LexIdentifier
}
示例3: LexMaybe
// Custom lexer for our maybe hash function
//
// SUBSCRIBE
// valuect(item) AS stuff
// FROM maybe(stuff)
// WHERE x = y
//
func LexMaybe(l *lex.Lexer) lex.StateFn {
l.SkipWhiteSpaces()
keyWord := strings.ToLower(l.PeekWord())
switch keyWord {
case "maybe":
l.ConsumeWord("maybe")
l.Emit(lex.TokenIdentity)
return lex.LexExpressionOrIdentity
}
return lex.LexExpressionOrIdentity
}
示例4: LexColumnsInflux
// Handle influx columns
// SELECT
// valuect(item) AS stuff SHORTDESC "stuff" KIND INT
//
// Examples:
//
// (colx = y OR colb = b)
// cola = 'a5'p
// cola != "a5", colb = "a6"
// REPLACE(cola,"stuff") != "hello"
// FirstName = REPLACE(LOWER(name," "))
// cola IN (1,2,3)
// cola LIKE "abc"
// eq(name,"bob") AND age > 5
//
func LexColumnsInflux(l *lex.Lexer) lex.StateFn {
l.SkipWhiteSpaces()
keyWord := strings.ToLower(l.PeekWord())
u.Debugf("LexColumnsInflux r= '%v'", string(keyWord))
switch keyWord {
case "if":
l.ConsumeWord("if")
l.Emit(lex.TokenIf)
l.Push("LexColumnsInflux", LexColumnsInflux)
return lex.LexColumns
case "shortdesc":
l.ConsumeWord("shortdesc")
l.Emit(TokenShortDesc)
l.Push("LexColumnsInflux", LexColumnsInflux)
l.Push("lexIdentifier", lex.LexValue)
return nil
case "longdesc":
l.ConsumeWord("longdesc")
l.Emit(TokenLongDesc)
l.Push("LexColumnsInflux", LexColumnsInflux)
l.Push("lexIdentifier", lex.LexValue)
return nil
case "kind":
l.ConsumeWord("kind")
l.Emit(TokenKind)
l.Push("LexColumnsInflux", lex.LexColumns)
l.Push("lexIdentifier", lex.LexIdentifier)
return nil
}
return lex.LexSelectClause
}