aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/complete/syntax/parser_call_stack.cpp
diff options
context:
space:
mode:
authorvityaman <vityaman.dev@yandex.ru>2025-03-28 22:01:21 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2025-03-28 22:36:16 +0300
commitb60cb8f5ce78ae5f63304a534278e124d31398b0 (patch)
tree033d726f561f37e4e258460159b3b379aa9c70f6 /yql/essentials/sql/v1/complete/syntax/parser_call_stack.cpp
parentdf00f0d151a43de80f6e41291d9267afbbfb18a4 (diff)
downloadydb-b60cb8f5ce78ae5f63304a534278e124d31398b0.tar.gz
YQL-19747 Complete Function Names
- Function names are suggested now - Changed the module structure - Checking ruleIndex independence on mode (ansi | default) via unit tests --- Pull Request resolved: https://github.com/ytsaurus/ytsaurus/pull/1163 commit_hash:1b1a27d2cff8db663c5c7e8efb57896476823315
Diffstat (limited to 'yql/essentials/sql/v1/complete/syntax/parser_call_stack.cpp')
-rw-r--r--yql/essentials/sql/v1/complete/syntax/parser_call_stack.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/yql/essentials/sql/v1/complete/syntax/parser_call_stack.cpp b/yql/essentials/sql/v1/complete/syntax/parser_call_stack.cpp
new file mode 100644
index 00000000000..855d9af1601
--- /dev/null
+++ b/yql/essentials/sql/v1/complete/syntax/parser_call_stack.cpp
@@ -0,0 +1,65 @@
+#include "parser_call_stack.h"
+
+#include "grammar.h"
+
+#include <util/generic/vector.h>
+#include <util/generic/algorithm.h>
+#include <util/generic/yexception.h>
+
+namespace NSQLComplete {
+
+ const TVector<TRuleId> KeywordRules = {
+ RULE(Keyword),
+ RULE(Keyword_expr_uncompat),
+ RULE(Keyword_table_uncompat),
+ RULE(Keyword_select_uncompat),
+ RULE(Keyword_alter_uncompat),
+ RULE(Keyword_in_uncompat),
+ RULE(Keyword_window_uncompat),
+ RULE(Keyword_hint_uncompat),
+ RULE(Keyword_as_compat),
+ RULE(Keyword_compat),
+ };
+
+ const TVector<TRuleId> TypeNameRules = {
+ RULE(Type_name_simple),
+ };
+
+ const TVector<TRuleId> FunctionNameRules = {
+ RULE(Id_expr),
+ RULE(An_id_or_type),
+ RULE(Id_or_type),
+ };
+
+ bool EndsWith(const TParserCallStack& suffix, const TParserCallStack& stack) {
+ if (stack.size() < suffix.size()) {
+ return false;
+ }
+ const size_t prefixSize = stack.size() - suffix.size();
+ return Equal(std::begin(stack) + prefixSize, std::end(stack), std::begin(suffix));
+ }
+
+ bool ContainsRule(TRuleId rule, const TParserCallStack& stack) {
+ return Find(stack, rule) != std::end(stack);
+ }
+
+ bool IsLikelyTypeStack(const TParserCallStack& stack) {
+ return EndsWith({RULE(Type_name_simple)}, stack);
+ }
+
+ bool IsLikelyFunctionStack(const TParserCallStack& stack) {
+ return EndsWith({RULE(Unary_casual_subexpr), RULE(Id_expr)}, stack) ||
+ EndsWith({RULE(Unary_casual_subexpr),
+ RULE(Atom_expr),
+ RULE(An_id_or_type)}, stack);
+ }
+
+ std::unordered_set<TRuleId> GetC3PreferredRules() {
+ std::unordered_set<TRuleId> preferredRules;
+ preferredRules.insert(std::begin(KeywordRules), std::end(KeywordRules));
+ preferredRules.insert(std::begin(TypeNameRules), std::end(TypeNameRules));
+ preferredRules.insert(std::begin(FunctionNameRules), std::end(FunctionNameRules));
+ return preferredRules;
+ }
+
+} // namespace NSQLComplete