From bd281ff21b798b42aa8e4a56997e7d8b01781e15 Mon Sep 17 00:00:00 2001 From: Denis Arh Date: Fri, 18 Oct 2019 17:44:20 +0200 Subject: [PATCH] Improve ql to support . syntax --- pkg/ql/ast_parser.go | 13 ++++++++++++- pkg/ql/ast_parser_test.go | 8 ++++++++ pkg/ql/lexer.go | 1 + pkg/ql/token_codes.go | 1 + 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pkg/ql/ast_parser.go b/pkg/ql/ast_parser.go index 4d177d457..5c1e8f244 100644 --- a/pkg/ql/ast_parser.go +++ b/pkg/ql/ast_parser.go @@ -217,7 +217,18 @@ func (p *Parser) parseIdent(t Token) (list ASTNode, err error) { } } - return p.OnIdent(Ident{Value: t.literal}) + i := Ident{Value: t.literal} + + if p.peekToken(1).Is(DOT) { + p.nextToken() + i.Value += "." + l2 := p.nextToken() + if l2.Is(IDENT) { + i.Value += l2.literal + } + } + + return p.OnIdent(i) } func (p *Parser) parseSet() (list ASTSet, err error) { diff --git a/pkg/ql/ast_parser_test.go b/pkg/ql/ast_parser_test.go index 71007aaa7..2b2e0188f 100644 --- a/pkg/ql/ast_parser_test.go +++ b/pkg/ql/ast_parser_test.go @@ -269,6 +269,14 @@ func TestAstParser_ColumnParser(t *testing.T) { }, }, }, + { + in: `a.b`, + cols: Columns{ + Column{ + Expr: ASTNodes{Ident{Value: "a.b"}}, + }, + }, + }, { in: `DATE_FORMAT(some_date, '%Y-%m-01')`, cols: Columns{ diff --git a/pkg/ql/lexer.go b/pkg/ql/lexer.go index 10f757166..876afa828 100644 --- a/pkg/ql/lexer.go +++ b/pkg/ql/lexer.go @@ -44,6 +44,7 @@ func NewLexer(r io.Reader) *Lexer { // @todo ensure operator order (eg != is valid, =! is not) &TokenConsumerGeneric{token: OPERATOR, whitelist: CHAR_WHITELIST_OPERATORS}, &TokenConsumerGeneric{token: COMMA, whitelist: ",", maxLength: 1}, + &TokenConsumerGeneric{token: DOT, whitelist: ".", maxLength: 1}, &TokenConsumerGeneric{token: PARENTHESIS_OPEN, whitelist: "(", maxLength: 1}, &TokenConsumerGeneric{token: PARENTHESIS_CLOSE, whitelist: ")", maxLength: 1}, &TokenConsumerString{}, diff --git a/pkg/ql/token_codes.go b/pkg/ql/token_codes.go index 8ea28b1da..bd2fd9f64 100644 --- a/pkg/ql/token_codes.go +++ b/pkg/ql/token_codes.go @@ -19,6 +19,7 @@ const ( NUMBER // 4 STRING COMMA // , + DOT // . OPERATOR // + - / * PARENTHESIS_OPEN PARENTHESIS_CLOSE