dbms: allow non-parenthesised expressions in array access operator []. [#METR-14585]

This commit is contained in:
Andrey Mironov 2015-01-16 13:17:58 +03:00
parent 081f435952
commit 00324f2f9c
2 changed files with 21 additions and 17 deletions

View File

@ -40,13 +40,21 @@ class ParserLeftAssociativeBinaryOperatorList : public IParserBase
{
private:
Operators_t operators;
ParserPtr elem_parser;
ParserPtr first_elem_parser;
ParserPtr remaining_elem_parser;
public:
/** operators_ - допустимые операторы и соответствующие им функции
*/
ParserLeftAssociativeBinaryOperatorList(Operators_t operators_, ParserPtr && elem_parser_)
: operators(operators_), elem_parser(std::move(elem_parser_))
ParserLeftAssociativeBinaryOperatorList(Operators_t operators_, ParserPtr && first_elem_parser_)
: operators(operators_), first_elem_parser(std::move(first_elem_parser_))
{
}
ParserLeftAssociativeBinaryOperatorList(Operators_t operators_, ParserPtr && first_elem_parser_,
ParserPtr && remaining_elem_parser_)
: operators(operators_), first_elem_parser(std::move(first_elem_parser_)),
remaining_elem_parser(std::move(remaining_elem_parser_))
{
}
@ -107,17 +115,11 @@ class ParserAccessExpression : public IParserBase
{
private:
static const char * operators[];
ParserLeftAssociativeBinaryOperatorList operator_parser;
public:
ParserAccessExpression();
protected:
const char * getName() const { return "access expression"; }
bool parseImpl(Pos & pos, Pos end, ASTPtr & node, Expected & expected)
{
return operator_parser.parse(pos, end, node, expected);
}
bool parseImpl(Pos & pos, Pos end, ASTPtr & node, Expected & expected);
};

View File

@ -118,7 +118,7 @@ bool ParserLeftAssociativeBinaryOperatorList::parseImpl(Pos & pos, Pos end, ASTP
if (first)
{
ASTPtr elem;
if (!elem_parser->parse(pos, end, elem, expected))
if (!first_elem_parser->parse(pos, end, elem, expected))
return false;
node = elem;
@ -155,7 +155,7 @@ bool ParserLeftAssociativeBinaryOperatorList::parseImpl(Pos & pos, Pos end, ASTP
ASTPtr exp_list_node = p_exp_list;
ASTPtr elem;
if (!elem_parser->parse(pos, end, elem, expected))
if (!(remaining_elem_parser ? remaining_elem_parser : first_elem_parser)->parse(pos, end, elem, expected))
return false;
/// первым аргументом функции будет предыдущий элемент, вторым - следующий
@ -432,11 +432,13 @@ bool ParserUnaryMinusExpression::parseImpl(Pos & pos, Pos end, ASTPtr & node, Ex
}
ParserAccessExpression::ParserAccessExpression()
: operator_parser(
operators,
ParserPtr(new ParserExpressionElement))
bool ParserAccessExpression::parseImpl(Pos &pos, Pos end, ASTPtr &node, Expected &expected)
{
return ParserLeftAssociativeBinaryOperatorList{
operators,
ParserPtr(new ParserExpressionElement),
ParserPtr(new ParserExpressionWithOptionalAlias)
}.parse(pos, end, node, expected);
}