Exemple #1
0
// Parse a single Expression, returning a Tree
//
//    ParseExpression("5 * toint(item_name)")
//
func ParseExpression(expressionText string) (*Tree, error) {
	l := lex.NewLexer(expressionText, lex.LogicalExpressionDialect)
	pager := NewLexTokenPager(l)
	t := NewTree(pager)
	pager.end = lex.TokenEOF
	err := t.BuildTree(true)
	return t, err
}
Exemple #2
0
func verifyTokens(t *testing.T, sql string, tokens []lex.Token) {
	l := lex.NewLexer(sql, InfluxQlDialect)
	for _, goodToken := range tokens {
		tok := l.NextToken()
		u.Debugf("%#v  %#v", tok, goodToken)
		assert.Equalf(t, tok.V, goodToken.V, "has='%v' want='%v'", tok.V, goodToken.V)
		assert.Equalf(t, tok.T, goodToken.T, "has='%v' want='%v'", tok.V, goodToken.V)
	}
}
Exemple #3
0
// Parse a single Expression, returning a Tree
//
//    ParseExpression("5 * toint(item_name)")
//
func ParseExpression(expressionText string) (*Tree, error) {
	l := lex.NewLexer(expressionText, lex.LogicalExpressionDialect)
	pager := NewLexTokenPager(l)
	t := NewTree(pager)

	// Parser panics on unexpected syntax, convert this into an err
	err := t.BuildTree(true)
	return t, err
}
Exemple #4
0
func main() {

	/* Many *ql languages support some type of columnar layout such as:
	   name = value, name2 = value2
	*/
	l := lex.NewLexer(`
				SUBSCRIBETO
					count(x), Name
				FROM ourstream
				WHERE 
					k = REPLACE(LOWER(Name),"cde","xxx");`, ourDialect)

	verifyLexerTokens(l,
		[]lex.Token{
			Tok(TokenSubscribeTo, "SUBSCRIBETO"),
			Tok(lex.TokenUdfExpr, "count"),
			Tok(lex.TokenLeftParenthesis, "("),
			Tok(lex.TokenIdentity, "x"),
			Tok(lex.TokenRightParenthesis, ")"),
			Tok(lex.TokenComma, ","),
			Tok(lex.TokenIdentity, "Name"),
			Tok(lex.TokenFrom, "FROM"),
			Tok(lex.TokenIdentity, "ourstream"),
			Tok(lex.TokenWhere, "WHERE"),
			Tok(lex.TokenIdentity, "k"),
			Tok(lex.TokenEqual, "="),
			Tok(lex.TokenUdfExpr, "REPLACE"),
			Tok(lex.TokenLeftParenthesis, "("),
			Tok(lex.TokenUdfExpr, "LOWER"),
			Tok(lex.TokenLeftParenthesis, "("),
			Tok(lex.TokenIdentity, "Name"),
			Tok(lex.TokenRightParenthesis, ")"),
			Tok(lex.TokenComma, ","),
			Tok(lex.TokenValue, "cde"),
			Tok(lex.TokenComma, ","),
			Tok(lex.TokenValue, "xxx"),
			Tok(lex.TokenRightParenthesis, ")"),
			Tok(lex.TokenEOS, ";"),
		})
}
Exemple #5
0
// Parses string query
func Parse(query string) (*Ast, error) {
	l := lex.NewLexer(query, InfluxQlDialect)
	p := Parser{l: l, qryText: query}
	return p.parse()
}