bool ParserColumnsOrIndicesDeclarationList::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { ASTPtr list; if (!ParserList(std::make_unique<ParserColumnAndIndexDeclaraion>(), std::make_unique<ParserToken>(TokenType::Comma), false) .parse(pos, list, expected)) return false; ASTPtr columns = std::make_shared<ASTExpressionList>(); ASTPtr indices = std::make_shared<ASTExpressionList>(); for (const auto & elem : list->children) { if (typeid_cast<const ASTColumnDeclaration *>(elem.get())) columns->children.push_back(elem); else if (typeid_cast<const ASTIndexDeclaration *>(elem.get())) indices->children.push_back(elem); else return false; } auto res = std::make_shared<ASTColumns>(); if (!columns->children.empty()) res->set(res->columns, columns); if (!indices->children.empty()) res->set(res->indices, indices); node = res; return true; }
bool ParserCompoundIdentifier::parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected) { Pos begin = pos; ASTPtr id_list; if (!ParserList(ParserPtr(new ParserIdentifier), ParserPtr(new ParserString(".")), false) .parse(pos, end, id_list, max_parsed_pos, expected)) return false; String name; const ASTExpressionList & list = static_cast<const ASTExpressionList &>(*id_list.get()); for (const auto & child : list.children) { if (!name.empty()) name += '.'; name += static_cast<const ASTIdentifier &>(*child.get()).name; } node = std::make_shared<ASTIdentifier>(StringRange(begin, pos), name); /// В children запомним идентификаторы-составляющие, если их больше одного. if (list.children.size() > 1) node->children.insert(node->children.end(), list.children.begin(), list.children.end()); return true; }
bool ParserColumnDeclarationList::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { return ParserList(std::make_unique<ParserColumnDeclaration>(), std::make_unique<ParserToken>(TokenType::Comma), false) .parse(pos, node, expected); }
bool ParserNameTypePairList::parseImpl(Pos & pos, ASTPtr & node, Expected & expected) { return ParserList(std::make_unique<ParserNameTypePair>(), std::make_unique<ParserToken>(TokenType::Comma), false) .parse(pos, node, expected); }