From cecf06f44d784cb9428adfed86c9ec0d7c4d8f2a Mon Sep 17 00:00:00 2001 From: Tomasz Grabiec Date: Mon, 9 Feb 2015 20:14:48 +0100 Subject: [PATCH] cql3: Move parser out of cql3 namespace This moves parser from cql3 to cql3_parser namespace to avoid name conflicts between parser rules and classes defined in the cql3 namespace. In particular the "term" rule would conflict with the "term" class, leading to compilation errors. I figured it will be easier to change namespace than to rename all rule occurances. --- cql3/Cql.g | 53 +++++++++++++++++++++++---------------------- transport/server.cc | 8 +++---- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/cql3/Cql.g b/cql3/Cql.g index 256a61cbff..d8751960fc 100644 --- a/cql3/Cql.g +++ b/cql3/Cql.g @@ -23,7 +23,7 @@ options { language = Cpp; } -@parser::namespace{cql3} +@parser::namespace{cql3_parser} @parser::includes { #include "cql3/statements/select_statement.hh" @@ -39,9 +39,10 @@ options { } @parser::traits { -using namespace cql3; using namespace cql3::statements; using namespace cql3::selection; +using cql3::cql3_type; +using cql3::native_cql3_type; } @header { @@ -191,7 +192,7 @@ using namespace cql3::selection; #endif } -@lexer::namespace{cql3} +@lexer::namespace{cql3_parser} @lexer::traits { class CqlLexer; @@ -346,7 +347,7 @@ selectClause returns [std::vector> expr] ; selector returns [shared_ptr s] - @init{ shared_ptr alias; } + @init{ shared_ptr alias; } : us=unaliasedSelector (K_AS c=ident { alias = c; })? { $s = make_shared(us, alias); } ; @@ -981,22 +982,22 @@ userOption[UserOptions opts] // Column Identifiers. These need to be treated differently from other // identifiers because the underlying comparator is not necessarily text. See // CASSANDRA-8178 for details. -cident returns [shared_ptr id] - : t=IDENT { $id = make_shared(sstring{$t.text}, false); } - | t=QUOTED_NAME { $id = make_shared(sstring{$t.text}, true); } - | k=unreserved_keyword { $id = make_shared(k, false); } +cident returns [shared_ptr id] + : t=IDENT { $id = make_shared(sstring{$t.text}, false); } + | t=QUOTED_NAME { $id = make_shared(sstring{$t.text}, true); } + | k=unreserved_keyword { $id = make_shared(k, false); } ; // Identifiers that do not refer to columns or where the comparator is known to be text -ident returns [shared_ptr id] - : t=IDENT { $id = make_shared(sstring{$t.text}, false); } - | t=QUOTED_NAME { $id = make_shared(sstring{$t.text}, true); } - | k=unreserved_keyword { $id = make_shared(k, false); } +ident returns [shared_ptr id] + : t=IDENT { $id = make_shared(sstring{$t.text}, false); } + | t=QUOTED_NAME { $id = make_shared(sstring{$t.text}, true); } + | k=unreserved_keyword { $id = make_shared(k, false); } ; // Keyspace & Column family names keyspaceName returns [sstring id] - @init { auto name = make_shared(); } + @init { auto name = make_shared(); } : cfOrKsName[name, true] { $id = name->get_keyspace(); } ; @@ -1013,8 +1014,8 @@ idxOrKsName[IndexName name, boolean isKs] ; #endif -columnFamilyName returns [shared_ptr name] - @init { $name = make_shared(); } +columnFamilyName returns [shared_ptr name] + @init { $name = make_shared(); } : (cfOrKsName[name, true] '.')? cfOrKsName[name, false] ; @@ -1024,7 +1025,7 @@ userTypeName returns [UTName name] ; #endif -cfOrKsName[shared_ptr name, bool isKs] +cfOrKsName[shared_ptr name, bool isKs] : t=IDENT { if (isKs) $name->set_keyspace($t.text, false); else $name->set_column_family($t.text, false); } | t=QUOTED_NAME { if (isKs) $name->set_keyspace($t.text, true); else $name->set_column_family($t.text, true); } | k=unreserved_keyword { if (isKs) $name->set_keyspace(k, false); else $name->set_column_family(k, false); } @@ -1033,15 +1034,15 @@ cfOrKsName[shared_ptr name, bool isKs] #endif ; -constant returns [shared_ptr constant] +constant returns [shared_ptr constant] @init{std::string sign;} - : t=STRING_LITERAL { $constant = constants::literal::string(sstring{$t.text}); } - | t=INTEGER { $constant = constants::literal::integer(sstring{$t.text}); } - | t=FLOAT { $constant = constants::literal::floating_point(sstring{$t.text}); } - | t=BOOLEAN { $constant = constants::literal::bool_(sstring{$t.text}); } - | t=UUID { $constant = constants::literal::uuid(sstring{$t.text}); } - | t=HEXNUMBER { $constant = constants::literal::hex(sstring{$t.text}); } - | { sign=""; } ('-' {sign = "-"; } )? t=(K_NAN | K_INFINITY) { $constant = constants::literal::floating_point(sstring{sign + $t.text}); } + : t=STRING_LITERAL { $constant = cql3::constants::literal::string(sstring{$t.text}); } + | t=INTEGER { $constant = cql3::constants::literal::integer(sstring{$t.text}); } + | t=FLOAT { $constant = cql3::constants::literal::floating_point(sstring{$t.text}); } + | t=BOOLEAN { $constant = cql3::constants::literal::bool_(sstring{$t.text}); } + | t=UUID { $constant = cql3::constants::literal::uuid(sstring{$t.text}); } + | t=HEXNUMBER { $constant = cql3::constants::literal::hex(sstring{$t.text}); } + | { sign=""; } ('-' {sign = "-"; } )? t=(K_NAN | K_INFINITY) { $constant = cql3::constants::literal::floating_point(sstring{sign + $t.text}); } ; #if 0 @@ -1094,9 +1095,9 @@ value returns [Term.Raw value] ; #endif -intValue returns [::shared_ptr value] +intValue returns [::shared_ptr value] : - | t=INTEGER { $value = constants::literal::integer(sstring{$t.text}); } + | t=INTEGER { $value = cql3::constants::literal::integer(sstring{$t.text}); } #if 0 | ':' id=ident { $value = newBindVariables(id); } | QMARK { $value = newBindVariables(null); } diff --git a/transport/server.cc b/transport/server.cc index 012f984f03..bcd71fde4d 100644 --- a/transport/server.cc +++ b/transport/server.cc @@ -362,10 +362,10 @@ future<> cql_server::connection::process_query(uint16_t stream, temporary_buffer auto flags = read_byte(buf); #endif print("processing query: '%s' ...\n", query); - cql3::CqlLexer::InputStreamType input{reinterpret_cast(query.begin()), ANTLR_ENC_UTF8, static_cast(query.size()), nullptr}; - cql3::CqlLexer lexer{&input}; - cql3::CqlParser::TokenStreamType tstream(ANTLR_SIZE_HINT, lexer.get_tokSource()); - cql3::CqlParser parser{&tstream}; + cql3_parser::CqlLexer::InputStreamType input{reinterpret_cast(query.begin()), ANTLR_ENC_UTF8, static_cast(query.size()), nullptr}; + cql3_parser::CqlLexer lexer{&input}; + cql3_parser::CqlParser::TokenStreamType tstream(ANTLR_SIZE_HINT, lexer.get_tokSource()); + cql3_parser::CqlParser parser{&tstream}; auto stmt = parser.query(); assert(stmt != nullptr); return make_ready_future<>();