2015-12-21 13:15:13 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <DB/Parsers/ASTEnumElement.h>
|
|
|
|
#include <DB/Parsers/ExpressionElementParsers.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
class ParserEnumElement : public IParserBase
|
|
|
|
{
|
|
|
|
ParserStringLiteral name_parser;
|
2015-12-28 17:04:29 +00:00
|
|
|
ParserNumber value_parser;
|
2015-12-21 13:15:13 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
const char * getName() const override { return "enum element"; }
|
|
|
|
bool parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected) override
|
|
|
|
{
|
|
|
|
ParserString equality_sign_parser("=");
|
|
|
|
ParserWhiteSpace ws;
|
|
|
|
const auto begin = pos;
|
|
|
|
|
|
|
|
ASTPtr name;
|
|
|
|
if (!name_parser.parse(pos, end, name, max_parsed_pos, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ws.ignore(pos, end, max_parsed_pos, expected);
|
|
|
|
|
|
|
|
if (!equality_sign_parser.ignore(pos, end, max_parsed_pos, expected))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ws.ignore(pos, end, max_parsed_pos, expected);
|
|
|
|
|
|
|
|
ASTPtr value;
|
|
|
|
if (!value_parser.parse(pos, end, value, max_parsed_pos, expected))
|
|
|
|
return false;
|
|
|
|
|
2016-05-28 15:42:22 +00:00
|
|
|
node = std::make_shared<ASTEnumElement>(
|
2016-05-28 16:19:27 +00:00
|
|
|
StringRange{ begin, pos },
|
2015-12-21 13:15:13 +00:00
|
|
|
static_cast<const ASTLiteral &>(*name).value.get<String>(),
|
2016-05-28 15:42:22 +00:00
|
|
|
static_cast<const ASTLiteral &>(*value).value);
|
2015-12-21 13:15:13 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|