Exemple #1
0
// 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
}
Exemple #2
0
// 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
}