#include "format.h" #include "grammar.h" #include #include #include namespace NSQLComplete { namespace { static const THashSet Keywords = [] { const auto& grammar = GetSqlGrammar(); const auto& vocabulary = grammar.GetVocabulary(); THashSet keywords; for (auto& token : grammar.GetKeywordTokens()) { keywords.emplace(Display(vocabulary, token)); } return keywords; }(); static const THashSet TypeConstructors = { "DECIMAL", "OPTIONAL", "TUPLE", "STRUCT", "VARIANT", "LIST", "STREAM", "FLOW", "DICT", "SET", "ENUM", "RESOURCE", "TAGGED", "CALLABLE", }; } // namespace TString FormatKeywords(const TVector& seq) { if (seq.empty()) { return ""; } size_t i = 0; TString text = seq[i++]; if (2 <= seq.size() && TypeConstructors.contains(text) && (seq[i] == "<" || seq[i] == "(")) { text.to_title(); text.append(seq[i]); i += 1; } for (; i < seq.size(); ++i) { const auto& token = seq[i]; if (Keywords.contains(token)) { text += " "; } text += token; } return text; } TString Quoted(TString content) { content.prepend('`'); content.append('`'); return content; } TString Unquoted(TString content) { Y_ENSURE(2 <= content.size() && content.front() == '`' && content.back() == '`'); content.erase(0, 1); content.pop_back(); return content; } } // namespace NSQLComplete