Ejemplo n.º 1
0
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)
		}
	}
}
Ejemplo n.º 2
0
// 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
}
Ejemplo n.º 3
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
}
Ejemplo n.º 4
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
}