Commit a1a91561 authored by Sergei Petrunia's avatar Sergei Petrunia

Code cleanup in parser:

- Comments in simple_parser.h
- Rename Optimizer_hint_parser::PARSER to Parser (it's not a template
  argument, don't use caps)
parent 534060f2
...@@ -218,29 +218,29 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer, ...@@ -218,29 +218,29 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer,
private: private:
using PARSER= Optimizer_hint_parser; // for a shorter notation using Parser= Optimizer_hint_parser; // for a shorter notation
// Rules consisting of a single token // Rules consisting of a single token
class TokenAT: public TOKEN<PARSER, TokenID::tAT> class TokenAT: public TOKEN<Parser, TokenID::tAT>
{ {
public: public:
using TOKEN::TOKEN; using TOKEN::TOKEN;
}; };
class TokenEOF: public TOKEN<PARSER, TokenID::tEOF> class TokenEOF: public TOKEN<Parser, TokenID::tEOF>
{ {
public: public:
using TOKEN::TOKEN; using TOKEN::TOKEN;
}; };
class Keyword_QB_NAME: public TOKEN<PARSER, TokenID::keyword_QB_NAME> class Keyword_QB_NAME: public TOKEN<Parser, TokenID::keyword_QB_NAME>
{ {
public: public:
using TOKEN::TOKEN; using TOKEN::TOKEN;
}; };
class Identifier: public TOKEN<PARSER, TokenID::tIDENT> class Identifier: public TOKEN<Parser, TokenID::tIDENT>
{ {
public: public:
using TOKEN::TOKEN; using TOKEN::TOKEN;
...@@ -258,13 +258,13 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer, ...@@ -258,13 +258,13 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer,
} }
}; };
class LParen: public TOKEN<PARSER, TokenID::tLPAREN> class LParen: public TOKEN<Parser, TokenID::tLPAREN>
{ {
public: public:
using TOKEN::TOKEN; using TOKEN::TOKEN;
}; };
class RParen: public TOKEN<PARSER, TokenID::tRPAREN> class RParen: public TOKEN<Parser, TokenID::tRPAREN>
{ {
public: public:
using TOKEN::TOKEN; using TOKEN::TOKEN;
...@@ -285,7 +285,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer, ...@@ -285,7 +285,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer,
id == TokenID::keyword_NO_BNL; id == TokenID::keyword_NO_BNL;
} }
}; };
class Table_level_hint_type: public TokenChoice<PARSER, class Table_level_hint_type: public TokenChoice<Parser,
Table_level_hint_type_cond> Table_level_hint_type_cond>
{ {
public: public:
...@@ -305,7 +305,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer, ...@@ -305,7 +305,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer,
id == TokenID::keyword_NO_MRR; id == TokenID::keyword_NO_MRR;
} }
}; };
class Index_level_hint_type: public TokenChoice<PARSER, class Index_level_hint_type: public TokenChoice<Parser,
Index_level_hint_type_cond> Index_level_hint_type_cond>
{ {
public: public:
...@@ -343,7 +343,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer, ...@@ -343,7 +343,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer,
/* /*
at_query_block_name ::= @ query_block_name at_query_block_name ::= @ query_block_name
*/ */
class At_query_block_name: public AND2<PARSER, TokenAT, Query_block_name> class At_query_block_name: public AND2<Parser, TokenAT, Query_block_name>
{ {
public: public:
using AND2::AND2; using AND2::AND2;
...@@ -353,7 +353,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer, ...@@ -353,7 +353,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer,
/* /*
opt_qb_name ::= [ @ query_block_name ] opt_qb_name ::= [ @ query_block_name ]
*/ */
class Opt_qb_name: public OPT<PARSER, At_query_block_name> class Opt_qb_name: public OPT<Parser, At_query_block_name>
{ {
public: public:
using OPT::OPT; using OPT::OPT;
...@@ -362,7 +362,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer, ...@@ -362,7 +362,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer,
/* /*
hint_param_table ::= table_name opt_qb_name hint_param_table ::= table_name opt_qb_name
*/ */
class Hint_param_table: public AND2<PARSER, Table_name, Opt_qb_name> class Hint_param_table: public AND2<Parser, Table_name, Opt_qb_name>
{ {
public: public:
using AND2::AND2; using AND2::AND2;
...@@ -382,7 +382,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer, ...@@ -382,7 +382,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer,
size_t count() const { return elements; } size_t count() const { return elements; }
}; };
class Opt_hint_param_table_list: public LIST<PARSER, class Opt_hint_param_table_list: public LIST<Parser,
Hint_param_table_list_container, Hint_param_table_list_container,
Hint_param_table, Hint_param_table,
TokenID::tCOMMA, 0> TokenID::tCOMMA, 0>
...@@ -403,7 +403,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer, ...@@ -403,7 +403,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer,
size_t count() const { return elements; } size_t count() const { return elements; }
}; };
class Opt_table_name_list: public LIST<PARSER, class Opt_table_name_list: public LIST<Parser,
Table_name_list_container, Table_name_list_container,
Table_name, TokenID::tCOMMA, 0> Table_name, TokenID::tCOMMA, 0>
{ {
...@@ -425,7 +425,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer, ...@@ -425,7 +425,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer,
size_t count() const { return elements; } size_t count() const { return elements; }
}; };
class Opt_hint_param_index_list: public LIST<PARSER, class Opt_hint_param_index_list: public LIST<Parser,
Hint_param_index_list_container, Hint_param_index_list_container,
Hint_param_index, Hint_param_index,
TokenID::tCOMMA, 0> TokenID::tCOMMA, 0>
...@@ -439,7 +439,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer, ...@@ -439,7 +439,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer,
hint_param_table_ext ::= hint_param_table hint_param_table_ext ::= hint_param_table
| @ query_block_name table_name | @ query_block_name table_name
*/ */
class At_query_block_name_table_name: public AND2<PARSER, class At_query_block_name_table_name: public AND2<Parser,
At_query_block_name, At_query_block_name,
Table_name> Table_name>
{ {
...@@ -465,7 +465,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer, ...@@ -465,7 +465,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer,
} }
}; };
class Hint_param_table_ext: public OR2C<PARSER, class Hint_param_table_ext: public OR2C<Parser,
Hint_param_table_ext_container, Hint_param_table_ext_container,
Hint_param_table, Hint_param_table,
At_query_block_name_table_name> At_query_block_name_table_name>
...@@ -480,7 +480,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer, ...@@ -480,7 +480,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer,
@ query_block_name opt_table_name_list @ query_block_name opt_table_name_list
*/ */
class At_query_block_name_opt_table_name_list: public AND2< class At_query_block_name_opt_table_name_list: public AND2<
PARSER, Parser,
At_query_block_name, At_query_block_name,
Opt_table_name_list> Opt_table_name_list>
{ {
...@@ -494,7 +494,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer, ...@@ -494,7 +494,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer,
| opt_hint_param_table_list | opt_hint_param_table_list
*/ */
class Table_level_hint_body: public OR2< class Table_level_hint_body: public OR2<
PARSER, Parser,
At_query_block_name_opt_table_name_list, At_query_block_name_opt_table_name_list,
Opt_hint_param_table_list> Opt_hint_param_table_list>
{ {
...@@ -503,7 +503,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer, ...@@ -503,7 +503,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer,
}; };
// table_level_hint ::= table_level_hint_type ( table_level_hint_body ) // table_level_hint ::= table_level_hint_type ( table_level_hint_body )
class Table_level_hint: public AND4<PARSER, class Table_level_hint: public AND4<Parser,
Table_level_hint_type, Table_level_hint_type,
LParen, LParen,
Table_level_hint_body, Table_level_hint_body,
...@@ -517,7 +517,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer, ...@@ -517,7 +517,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer,
// index_level_hint_body ::= hint_param_table_ext opt_hint_param_index_list // index_level_hint_body ::= hint_param_table_ext opt_hint_param_index_list
class Index_level_hint_body: public AND2<PARSER, class Index_level_hint_body: public AND2<Parser,
Hint_param_table_ext, Hint_param_table_ext,
Opt_hint_param_index_list> Opt_hint_param_index_list>
{ {
...@@ -527,7 +527,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer, ...@@ -527,7 +527,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer,
// index_level_hint ::= index_level_hint_type ( index_level_hint_body ) // index_level_hint ::= index_level_hint_type ( index_level_hint_body )
class Index_level_hint: public AND4<PARSER, class Index_level_hint: public AND4<Parser,
Index_level_hint_type, Index_level_hint_type,
LParen, LParen,
Index_level_hint_body, Index_level_hint_body,
...@@ -541,7 +541,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer, ...@@ -541,7 +541,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer,
// qb_name_hint ::= QB_NAME ( query_block_name ) // qb_name_hint ::= QB_NAME ( query_block_name )
class Qb_name_hint: public AND4<PARSER, class Qb_name_hint: public AND4<Parser,
Keyword_QB_NAME, Keyword_QB_NAME,
LParen, LParen,
Query_block_name, Query_block_name,
...@@ -559,7 +559,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer, ...@@ -559,7 +559,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer,
| table_level_hint | table_level_hint
| qb_name_hint | qb_name_hint
*/ */
class Hint: public OR3<PARSER, class Hint: public OR3<Parser,
Index_level_hint, Index_level_hint,
Table_level_hint, Table_level_hint,
Qb_name_hint> Qb_name_hint>
...@@ -579,7 +579,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer, ...@@ -579,7 +579,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer,
size_t count() const { return elements; } size_t count() const { return elements; }
}; };
class Hint_list: public LIST<PARSER, Hint_list_container, class Hint_list: public LIST<Parser, Hint_list_container,
Hint, TokenID::tNULL/*not separated list*/, 1> Hint, TokenID::tNULL/*not separated list*/, 1>
{ {
public: public:
...@@ -593,7 +593,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer, ...@@ -593,7 +593,7 @@ class Optimizer_hint_parser: public Optimizer_hint_tokenizer,
The main rule: The main rule:
hints ::= hint_list EOF hints ::= hint_list EOF
*/ */
class Hints: public AND2<PARSER, Hint_list, TokenEOF> class Hints: public AND2<Parser, Hint_list, TokenEOF>
{ {
public: public:
using AND2::AND2; using AND2::AND2;
......
...@@ -36,21 +36,24 @@ ...@@ -36,21 +36,24 @@
class Baz ... ; // "baz" is parsed into Baz object class Baz ... ; // "baz" is parsed into Baz object
// "foo" is parsed into a Foo object. // "foo" is parsed into a Foo object.
class Foo: public Parser_templates::AND2<PARSER, Bar, Baz> { class Foo: public Parser_templates::AND2<PARSER_Impl, Bar, Baz> {
using AND2::AND2; using AND2::AND2;
... ...
}; };
Inheriting AND2's constructors with "using" will generate the parsing code. Parsing code is generated by inheriting AND2's constructors with "using" like
shown above. All grammar rule-based classes should also have
- a capability to construct an "empty"(i.e. invalid) object with the default
constructor. This will be invoked when parsing fails.
- operator bool() which returns true if the object is non-empty (i.e. valid)
and false otherwise.
Parsing is done by constructing parser output from the parser object: Parsing is done by constructing parser output from the parser object:
Foo parsed_output(parser); Foo parsed_output(parser);
All parser objects should also have PARSER_Impl here is a class implementing a tokenizer and error condition
- A capability to construct an "empty" or "invalid" object with constructor storage, like Extended_string_tokenizer.
that accepts no arguments. This is necessary when parsing fails.
- operator bool() which returns true if the object is valid/non-empty and
false if otherwise.
*/ */
class Parser_templates class Parser_templates
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment