fix parsing of ternary operator

This commit is contained in:
Anton Popov 2021-05-04 16:16:27 +03:00
parent 2b79bf838f
commit fad4e6c335
4 changed files with 26 additions and 6 deletions

View File

@ -65,4 +65,17 @@ bool ParserKeyword::parseImpl(Pos & pos, ASTPtr & /*node*/, Expected & expected)
return true; return true;
} }
bool ParserDoubleColon::parseImpl(Pos & pos, ASTPtr & /*node*/, Expected & expected)
{
/// Do not move position if only one colon mathced.
Pos begin = pos;
if (parser_colon.ignore(begin, expected) && parser_colon.ignore(begin, expected))
{
pos = begin;
return true;
}
return false;
}
} }

View File

@ -56,4 +56,15 @@ public:
bool parseImpl(Pos & /*pos*/, ASTPtr & /*node*/, Expected & /*expected*/) override { return true; } bool parseImpl(Pos & /*pos*/, ASTPtr & /*node*/, Expected & /*expected*/) override { return true; }
}; };
class ParserDoubleColon : public IParserBase
{
public:
const char * getName() const override { return "double colon"; }
bool parseImpl(Pos & pos, ASTPtr & node, Expected & expected) override;
private:
ParserToken parser_colon{TokenType::Colon};
};
} }

View File

@ -866,11 +866,9 @@ bool ParserCastOperator::parseImpl(Pos & pos, ASTPtr & node, Expected & expected
return false; return false;
ASTPtr type_ast; ASTPtr type_ast;
ParserToken parser_colon(TokenType::Colon);
const char * data_end = pos->begin; const char * data_end = pos->begin;
if (parser_colon.ignore(pos, expected) if (ParserDoubleColon().ignore(pos, expected)
&& parser_colon.ignore(pos, expected)
&& ParserDataType().parse(pos, type_ast, expected)) && ParserDataType().parse(pos, type_ast, expected))
{ {
auto type = DataTypeFactory::instance().get(type_ast); auto type = DataTypeFactory::instance().get(type_ast);

View File

@ -564,9 +564,7 @@ bool ParserCastExpression::parseImpl(Pos & pos, ASTPtr & node, Expected & expect
return false; return false;
ASTPtr type_ast; ASTPtr type_ast;
ParserToken parser_colon(TokenType::Colon); if (ParserDoubleColon().ignore(pos, expected)
if (parser_colon.ignore(pos, expected)
&& parser_colon.ignore(pos, expected)
&& ParserDataType().parse(pos, type_ast, expected)) && ParserDataType().parse(pos, type_ast, expected))
{ {
node = createFunctionCast(expr_ast, type_ast); node = createFunctionCast(expr_ast, type_ast);