Skip to content

Commit 013ae84

Browse files
OrlovPavelroot
andauthored
Grammar changes for antlr4 migration (#6713)
Co-authored-by: root <p.g.orlov@tinkoff.ru>
1 parent 38281ff commit 013ae84

File tree

6 files changed

+45
-43
lines changed

6 files changed

+45
-43
lines changed

ydb/library/yql/sql/v1/SQLv1.g.in

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ con_subexpr: unary_subexpr | unary_op unary_subexpr;
111111

112112
unary_op: PLUS | MINUS | TILDA | NOT;
113113

114-
unary_subexpr_suffix: (key_expr | invoke_expr |(DOT (bind_parameter | DIGITS | an_id_or_type)))* (COLLATE an_id)?;
114+
unary_subexpr_suffix: ((key_expr | invoke_expr | DOT (bind_parameter | DIGITS | an_id_or_type)))* (COLLATE an_id)?;
115115

116116
unary_casual_subexpr: (id_expr | atom_expr) unary_subexpr_suffix;
117117

@@ -171,7 +171,7 @@ exists_expr: EXISTS LPAREN (select_stmt | values_stmt) RPAREN;
171171

172172
case_expr: CASE expr? when_expr+ (ELSE expr)? END;
173173

174-
lambda: smart_parenthesis (ARROW ((LPAREN expr RPAREN) | (LBRACE_CURLY lambda_body RBRACE_CURLY)) )?;
174+
lambda: smart_parenthesis (ARROW (LPAREN expr RPAREN | LBRACE_CURLY lambda_body RBRACE_CURLY) )?;
175175

176176
in_expr: in_unary_subexpr;
177177

@@ -188,7 +188,7 @@ json_variables: json_variable (COMMA json_variable)*;
188188

189189
json_common_args: expr COMMA jsonpath_spec (PASSING json_variables)?;
190190

191-
json_case_handler: ERROR | NULL | (DEFAULT expr);
191+
json_case_handler: ERROR | NULL | DEFAULT expr;
192192

193193
json_value: JSON_VALUE LPAREN
194194
json_common_args
@@ -203,7 +203,7 @@ json_exists: JSON_EXISTS LPAREN
203203
json_exists_handler?
204204
RPAREN;
205205

206-
json_query_wrapper: (WITHOUT ARRAY?) | (WITH (CONDITIONAL | UNCONDITIONAL)? ARRAY?);
206+
json_query_wrapper: (WITHOUT ARRAY?) | WITH (CONDITIONAL | UNCONDITIONAL)? ARRAY?;
207207
json_query_handler: ERROR | NULL | (EMPTY ARRAY) | (EMPTY OBJECT);
208208

209209
json_query: JSON_QUERY LPAREN
@@ -224,7 +224,7 @@ pure_column_or_named: bind_parameter | an_id;
224224
pure_column_or_named_list: LPAREN pure_column_or_named (COMMA pure_column_or_named)* RPAREN;
225225

226226
column_name: opt_id_prefix an_id;
227-
without_column_name: (an_id DOT an_id) | an_id_without;
227+
without_column_name: an_id DOT an_id | an_id_without;
228228

229229
column_list: column_name (COMMA column_name)* COMMA?;
230230
without_column_list: without_column_name (COMMA without_column_name)* COMMA?;
@@ -241,7 +241,7 @@ invoke_expr_tail:
241241
(null_treatment | filter_clause)? (OVER window_name_or_specification)?
242242
;
243243

244-
using_call_expr: ((an_id_or_type NAMESPACE an_id_or_type) | an_id_expr | bind_parameter | (EXTERNAL FUNCTION)) invoke_expr;
244+
using_call_expr: (an_id_or_type NAMESPACE an_id_or_type | an_id_expr | bind_parameter | (EXTERNAL FUNCTION)) invoke_expr;
245245

246246
key_expr: LBRACE_SQUARE expr RBRACE_SQUARE;
247247

@@ -519,7 +519,7 @@ hopping_window_specification: HOP LPAREN expr COMMA expr COMMA expr COMMA expr R
519519

520520
result_column:
521521
opt_id_prefix ASTERISK
522-
| expr ((AS an_id_or_type) | an_id_as_compat)?
522+
| expr (AS an_id_or_type | an_id_as_compat)?
523523
;
524524

525525
join_source: ANY? flatten_source (join_op ANY? flatten_source join_constraint?)*;
@@ -533,7 +533,7 @@ flatten_by_arg:
533533

534534
flatten_source: named_single_source (FLATTEN ((OPTIONAL|LIST|DICT)? BY flatten_by_arg | COLUMNS))?;
535535

536-
named_single_source: single_source row_pattern_recognition_clause? (((AS an_id) | an_id_as_compat) pure_column_list?)? (sample_clause | tablesample_clause)?;
536+
named_single_source: single_source row_pattern_recognition_clause? ((AS an_id | an_id_as_compat) pure_column_list?)? (sample_clause | tablesample_clause)?;
537537

538538
single_source:
539539
table_ref

ydb/library/yql/sql/v1/format/sql_format.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ friend struct TStaticData;
359359
void VisitUnaryCasualSubexpr(const TRule_unary_casual_subexpr& msg) {
360360
bool invoke = false;
361361
for (auto& b : msg.GetRule_unary_subexpr_suffix2().GetBlock1()) {
362-
switch (b.Alt_case()) {
363-
case TRule_unary_subexpr_suffix::TBlock1::kAlt2: {
362+
switch (b.GetBlock1().Alt_case()) {
363+
case TRule_unary_subexpr_suffix::TBlock1::TBlock1::kAlt2: {
364364
invoke = true;
365365
break;
366366
}
@@ -385,8 +385,8 @@ friend struct TStaticData;
385385
void VisitInUnaryCasualSubexpr(const TRule_in_unary_casual_subexpr& msg) {
386386
bool invoke = false;
387387
for (auto& b : msg.GetRule_unary_subexpr_suffix2().GetBlock1()) {
388-
switch (b.Alt_case()) {
389-
case TRule_unary_subexpr_suffix::TBlock1::kAlt2: {
388+
switch (b.GetBlock1().Alt_case()) {
389+
case TRule_unary_subexpr_suffix::TBlock1::TBlock1::kAlt2: {
390390
invoke = true;
391391
break;
392392
}

ydb/library/yql/sql/v1/sql_call_expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ bool TSqlCallExpr::Init(const TRule_using_call_expr& node) {
203203
const auto& block = node.GetBlock1();
204204
switch (block.Alt_case()) {
205205
case TRule_using_call_expr::TBlock1::kAlt1: {
206-
auto& subblock = block.GetAlt1().GetBlock1();
206+
auto& subblock = block.GetAlt1();
207207
Module = Id(subblock.GetRule_an_id_or_type1(), *this);
208208
Func = Id(subblock.GetRule_an_id_or_type3(), *this);
209209
break;

ydb/library/yql/sql/v1/sql_expression.cpp

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ TNodePtr TSqlExpression::JsonValueCaseHandler(const TRule_json_case_handler& nod
561561
}
562562
case TRule_json_case_handler::kAltJsonCaseHandler3:
563563
mode = EJsonValueHandlerMode::DefaultValue;
564-
return Build(node.GetAlt_json_case_handler3().GetBlock1().GetRule_expr2());
564+
return Build(node.GetAlt_json_case_handler3().GetRule_expr2());
565565
case TRule_json_case_handler::ALT_NOT_SET:
566566
Y_ABORT("You should change implementation according to grammar changes");
567567
}
@@ -718,7 +718,7 @@ EJsonQueryWrap TSqlExpression::JsonQueryWrapper(const TRule_json_query& node) {
718718
}
719719

720720
// WITH (CONDITIONAL | UNCONDITIONAL)? ARRAY? - wrapping depends on 2nd token. Default is UNCONDITIONAL
721-
const auto& withWrapperRule = wrapperRule.GetAlt_json_query_wrapper2().GetBlock1();
721+
const auto& withWrapperRule = wrapperRule.GetAlt_json_query_wrapper2();
722722
if (!withWrapperRule.HasBlock2()) {
723723
return EJsonQueryWrap::Wrap;
724724
}
@@ -838,13 +838,13 @@ TNodePtr MatchRecognizeVarAccess(TTranslation& ctx, const TString& var, const TR
838838
return BuildMatchRecognizeVarAccess(TPosition{}, var, column, theSameVar);
839839
}
840840

841-
TNodePtr TSqlExpression::RowPatternVarAccess(const TString& alias, const TRule_unary_subexpr_suffix_TBlock1_TAlt3_TBlock1_TBlock2 block) {
841+
TNodePtr TSqlExpression::RowPatternVarAccess(const TString& alias, const TRule_unary_subexpr_suffix_TBlock1_TBlock1_TAlt3_TBlock2 block) {
842842
switch (block.GetAltCase()) {
843-
case TRule_unary_subexpr_suffix_TBlock1_TAlt3_TBlock1_TBlock2::kAlt1:
843+
case TRule_unary_subexpr_suffix_TBlock1_TBlock1_TAlt3_TBlock2::kAlt1:
844844
break;
845-
case TRule_unary_subexpr_suffix_TBlock1_TAlt3_TBlock1_TBlock2::kAlt2:
845+
case TRule_unary_subexpr_suffix_TBlock1_TBlock1_TAlt3_TBlock2::kAlt2:
846846
break;
847-
case TRule_unary_subexpr_suffix_TBlock1_TAlt3_TBlock1_TBlock2::kAlt3:
847+
case TRule_unary_subexpr_suffix_TBlock1_TBlock1_TAlt3_TBlock2::kAlt3:
848848
switch (block.GetAlt3().GetRule_an_id_or_type1().GetAltCase()) {
849849
case TRule_an_id_or_type::kAltAnIdOrType1: {
850850
const auto &idOrType = block.GetAlt3().GetRule_an_id_or_type1().GetAlt_an_id_or_type1().GetRule_id_or_type1();
@@ -869,7 +869,7 @@ TNodePtr TSqlExpression::RowPatternVarAccess(const TString& alias, const TRule_u
869869
break;
870870
}
871871
break;
872-
case TRule_unary_subexpr_suffix_TBlock1_TAlt3_TBlock1_TBlock2::ALT_NOT_SET:
872+
case TRule_unary_subexpr_suffix_TBlock1_TBlock1_TAlt3_TBlock2::ALT_NOT_SET:
873873
Y_ABORT("You should change implementation according to grammar changes");
874874
}
875875
return TNodePtr{};
@@ -932,14 +932,15 @@ TNodePtr TSqlExpression::UnaryCasualExpr(const TUnaryCasualExprRule& node, const
932932
bool isColumnRef = !expr;
933933
bool isFirstElem = true;
934934

935-
for (auto& b : suffix.GetBlock1()) {
935+
for (auto& _b : suffix.GetBlock1()) {
936+
auto& b = _b.GetBlock1();
936937
switch (b.Alt_case()) {
937-
case TRule_unary_subexpr_suffix::TBlock1::kAlt1: {
938+
case TRule_unary_subexpr_suffix::TBlock1::TBlock1::kAlt1: {
938939
// key_expr
939940
// onlyDots = false;
940941
break;
941942
}
942-
case TRule_unary_subexpr_suffix::TBlock1::kAlt2: {
943+
case TRule_unary_subexpr_suffix::TBlock1::TBlock1::kAlt2: {
943944
// invoke_expr - cannot be a column, function name
944945
if (isFirstElem) {
945946
isColumnRef = false;
@@ -948,20 +949,20 @@ TNodePtr TSqlExpression::UnaryCasualExpr(const TUnaryCasualExprRule& node, const
948949
// onlyDots = false;
949950
break;
950951
}
951-
case TRule_unary_subexpr_suffix::TBlock1::kAlt3: {
952+
case TRule_unary_subexpr_suffix::TBlock1::TBlock1::kAlt3: {
952953
// In case of MATCH_RECOGNIZE lambdas
953954
// X.Y is treated as Var.Column access
954955
if (isColumnRef && EColumnRefState::MatchRecognize == Ctx.GetColumnReferenceState()) {
955956
if (auto rowPatternVarAccess = RowPatternVarAccess(
956957
name,
957-
b.GetAlt3().GetBlock1().GetBlock2())
958+
b.GetAlt3().GetBlock2())
958959
) {
959960
return rowPatternVarAccess;
960961
}
961962
}
962963
break;
963964
}
964-
case TRule_unary_subexpr_suffix::TBlock1::ALT_NOT_SET:
965+
case TRule_unary_subexpr_suffix::TBlock1::TBlock1::ALT_NOT_SET:
965966
AltNotImplemented("unary_subexpr_suffix", b);
966967
return nullptr;
967968
}
@@ -1008,9 +1009,10 @@ TNodePtr TSqlExpression::UnaryCasualExpr(const TUnaryCasualExprRule& node, const
10081009
}
10091010

10101011
TPosition pos(Ctx.Pos());
1011-
for (auto& b : suffix.GetBlock1()) {
1012+
for (auto& _b : suffix.GetBlock1()) {
1013+
auto& b = _b.GetBlock1();
10121014
switch (b.Alt_case()) {
1013-
case TRule_unary_subexpr_suffix::TBlock1::kAlt1: {
1015+
case TRule_unary_subexpr_suffix::TBlock1::TBlock1::kAlt1: {
10141016
// key_expr
10151017
auto keyExpr = KeyExpr(b.GetAlt1().GetRule_key_expr1());
10161018
if (!keyExpr) {
@@ -1029,7 +1031,7 @@ TNodePtr TSqlExpression::UnaryCasualExpr(const TUnaryCasualExprRule& node, const
10291031
ids.clear();
10301032
break;
10311033
}
1032-
case TRule_unary_subexpr_suffix::TBlock1::kAlt2: {
1034+
case TRule_unary_subexpr_suffix::TBlock1::TBlock1::kAlt2: {
10331035
// invoke_expr - cannot be a column, function name
10341036
TSqlCallExpr call(Ctx, Mode);
10351037
if (isFirstElem && !name.Empty()) {
@@ -1055,15 +1057,15 @@ TNodePtr TSqlExpression::UnaryCasualExpr(const TUnaryCasualExprRule& node, const
10551057

10561058
break;
10571059
}
1058-
case TRule_unary_subexpr_suffix::TBlock1::kAlt3: {
1060+
case TRule_unary_subexpr_suffix::TBlock1::TBlock1::kAlt3: {
10591061
// dot
10601062
if (lastExpr) {
10611063
ids.push_back(lastExpr);
10621064
}
10631065

1064-
auto bb = b.GetAlt3().GetBlock1().GetBlock2();
1066+
auto bb = b.GetAlt3().GetBlock2();
10651067
switch (bb.Alt_case()) {
1066-
case TRule_unary_subexpr_suffix_TBlock1_TAlt3_TBlock1_TBlock2::kAlt1: {
1068+
case TRule_unary_subexpr_suffix_TBlock1_TBlock1_TAlt3_TBlock2::kAlt1: {
10671069
TString named;
10681070
if (!NamedNodeImpl(bb.GetAlt1().GetRule_bind_parameter1(), named, *this)) {
10691071
return nullptr;
@@ -1077,16 +1079,16 @@ TNodePtr TSqlExpression::UnaryCasualExpr(const TUnaryCasualExprRule& node, const
10771079
ids.back().Expr = namedNode;
10781080
break;
10791081
}
1080-
case TRule_unary_subexpr_suffix_TBlock1_TAlt3_TBlock1_TBlock2::kAlt2: {
1082+
case TRule_unary_subexpr_suffix_TBlock1_TBlock1_TAlt3_TBlock2::kAlt2: {
10811083
const TString str(Token(bb.GetAlt2().GetToken1()));
10821084
ids.push_back(str);
10831085
break;
10841086
}
1085-
case TRule_unary_subexpr_suffix_TBlock1_TAlt3_TBlock1_TBlock2::kAlt3: {
1087+
case TRule_unary_subexpr_suffix_TBlock1_TBlock1_TAlt3_TBlock2::kAlt3: {
10861088
ids.push_back(Id(bb.GetAlt3().GetRule_an_id_or_type1(), *this));
10871089
break;
10881090
}
1089-
case TRule_unary_subexpr_suffix_TBlock1_TAlt3_TBlock1_TBlock2::ALT_NOT_SET:
1091+
case TRule_unary_subexpr_suffix_TBlock1_TBlock1_TAlt3_TBlock2::ALT_NOT_SET:
10901092
Y_ABORT("You should change implementation according to grammar changes");
10911093
}
10921094

@@ -1097,7 +1099,7 @@ TNodePtr TSqlExpression::UnaryCasualExpr(const TUnaryCasualExprRule& node, const
10971099

10981100
break;
10991101
}
1100-
case TRule_unary_subexpr_suffix::TBlock1::ALT_NOT_SET:
1102+
case TRule_unary_subexpr_suffix::TBlock1::TBlock1::ALT_NOT_SET:
11011103
AltNotImplemented("unary_subexpr_suffix", b);
11021104
return nullptr;
11031105
}
@@ -1175,9 +1177,9 @@ TNodePtr TSqlExpression::LambdaRule(const TRule_lambda& rule) {
11751177
TColumnRefScope scope(Ctx, EColumnRefState::Deny);
11761178
scope.SetNoColumnErrContext("in lambda function");
11771179
if (bodyBlock.GetBlock2().HasAlt1()) {
1178-
ret = SqlLambdaExprBody(Ctx, bodyBlock.GetBlock2().GetAlt1().GetBlock1().GetRule_expr2(), exprSeq);
1180+
ret = SqlLambdaExprBody(Ctx, bodyBlock.GetBlock2().GetAlt1().GetRule_expr2(), exprSeq);
11791181
} else {
1180-
ret = SqlLambdaExprBody(Ctx, bodyBlock.GetBlock2().GetAlt2().GetBlock1().GetRule_lambda_body2(), exprSeq);
1182+
ret = SqlLambdaExprBody(Ctx, bodyBlock.GetBlock2().GetAlt2().GetRule_lambda_body2(), exprSeq);
11811183
}
11821184

11831185
TVector<TString> argNames;

ydb/library/yql/sql/v1/sql_expression.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class TSqlExpression: public TSqlTranslation {
108108

109109
TNodePtr BinOperList(const TString& opName, TVector<TNodePtr>::const_iterator begin, TVector<TNodePtr>::const_iterator end) const;
110110

111-
TNodePtr RowPatternVarAccess(const TString& alias, const TRule_unary_subexpr_suffix_TBlock1_TAlt3_TBlock1_TBlock2 block);
111+
TNodePtr RowPatternVarAccess(const TString& alias, const TRule_unary_subexpr_suffix_TBlock1_TBlock1_TAlt3_TBlock2 block);
112112

113113
struct TCaseBranch {
114114
TNodePtr Pred;

ydb/library/yql/sql/v1/sql_select.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ bool TSqlSelect::SelectTerm(TVector<TNodePtr>& terms, const TRule_result_column&
410410
bool implicitLabel = false;
411411
switch (alt.GetBlock2().Alt_case()) {
412412
case TRule_result_column_TAlt2_TBlock2::kAlt1:
413-
label = Id(alt.GetBlock2().GetAlt1().GetBlock1().GetRule_an_id_or_type2(), *this);
413+
label = Id(alt.GetBlock2().GetAlt1().GetRule_an_id_or_type2(), *this);
414414
break;
415415
case TRule_result_column_TAlt2_TBlock2::kAlt2:
416416
label = Id(alt.GetBlock2().GetAlt2().GetRule_an_id_as_compat1(), *this);
@@ -564,7 +564,7 @@ TSourcePtr TSqlSelect::NamedSingleSource(const TRule_named_single_source& node,
564564
TString label;
565565
switch (node.GetBlock3().GetBlock1().Alt_case()) {
566566
case TRule_named_single_source_TBlock3_TBlock1::kAlt1:
567-
label = Id(node.GetBlock3().GetBlock1().GetAlt1().GetBlock1().GetRule_an_id2(), *this);
567+
label = Id(node.GetBlock3().GetBlock1().GetAlt1().GetRule_an_id2(), *this);
568568
break;
569569
case TRule_named_single_source_TBlock3_TBlock1::kAlt2:
570570
label = Id(node.GetBlock3().GetBlock1().GetAlt2().GetRule_an_id_as_compat1(), *this);
@@ -663,8 +663,8 @@ bool TSqlSelect::ColumnName(TVector<TNodePtr>& keys, const TRule_without_column_
663663
TString columnName;
664664
switch (node.Alt_case()) {
665665
case TRule_without_column_name::kAltWithoutColumnName1:
666-
sourceName = Id(node.GetAlt_without_column_name1().GetBlock1().GetRule_an_id1(), *this);
667-
columnName = Id(node.GetAlt_without_column_name1().GetBlock1().GetRule_an_id3(), *this);
666+
sourceName = Id(node.GetAlt_without_column_name1().GetRule_an_id1(), *this);
667+
columnName = Id(node.GetAlt_without_column_name1().GetRule_an_id3(), *this);
668668
break;
669669
case TRule_without_column_name::kAltWithoutColumnName2:
670670
columnName = Id(node.GetAlt_without_column_name2().GetRule_an_id_without1(), *this);

0 commit comments

Comments
 (0)