Skip to content

Commit 8dfd693

Browse files
authored
Highlight YQL comments in YDB CLI interactive mode (#9359)
1 parent 4cd7f0a commit 8dfd693

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

ydb/public/lib/ydb_cli/commands/interactive/yql_highlight.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,14 @@ namespace NYdb {
8383
},
8484
.string = rgb666(3, 0, 0),
8585
.number = Color::BRIGHTGREEN,
86+
.comment = rgb666(2, 2, 2),
8687
.unknown = Color::DEFAULT,
8788
};
8889
}
8990

9091
YQLHighlight::ColorSchema YQLHighlight::ColorSchema::Debug() {
92+
using replxx::color::rgb666;
93+
9194
return {
9295
.keyword = Color::BLUE,
9396
.operation = Color::GRAY,
@@ -99,6 +102,7 @@ namespace NYdb {
99102
},
100103
.string = Color::GREEN,
101104
.number = Color::BRIGHTGREEN,
105+
.comment = rgb666(2, 2, 2),
102106
.unknown = Color::DEFAULT,
103107
};
104108
}
@@ -162,6 +166,9 @@ namespace NYdb {
162166
if (IsKeyword(token)) {
163167
return Coloring.keyword;
164168
}
169+
if (IsComment(token)) {
170+
return Coloring.comment;
171+
}
165172
return Coloring.unknown;
166173
}
167174

@@ -532,5 +539,9 @@ namespace NYdb {
532539
}
533540
}
534541

542+
bool YQLHighlight::IsComment(const antlr4::Token* token) const {
543+
return token->getType() == TOKEN(COMMENT);
544+
}
545+
535546
} // namespace NConsoleClient
536547
} // namespace NYdb

ydb/public/lib/ydb_cli/commands/interactive/yql_highlight.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace NYdb {
2929
} identifier;
3030
Color string;
3131
Color number;
32+
Color comment;
3233
Color unknown;
3334

3435
static ColorSchema Monaco();
@@ -53,6 +54,7 @@ namespace NYdb {
5354
bool IsQuotedIdentifier(const antlr4::Token* token) const;
5455
bool IsString(const antlr4::Token* token) const;
5556
bool IsNumber(const antlr4::Token* token) const;
57+
bool IsComment(const antlr4::Token* token) const;
5658

5759
private:
5860
ColorSchema Coloring;

ydb/public/lib/ydb_cli/commands/interactive/yql_highlight_ut.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Y_UNIT_TEST_SUITE(YqlHighlightTests) {
1919
{'s', Coloring.string},
2020
{'n', Coloring.number},
2121
{'u', Coloring.unknown},
22+
{'c', Coloring.comment},
2223
{' ', YQLHighlight::Color::DEFAULT},
2324
};
2425

@@ -183,4 +184,15 @@ Y_UNIT_TEST_SUITE(YqlHighlightTests) {
183184
}
184185
}
185186
}
187+
188+
Y_UNIT_TEST(Comment) {
189+
YQLHighlight highlight(Coloring);
190+
Check(highlight, "- select", "o kkkkkk");
191+
Check(highlight, "select -- select", "kkkkkk ccccccccc");
192+
Check(highlight, "-- select\nselect", "cccccccccckkkkkk");
193+
Check(highlight, "/* select */", "cccccccccccc");
194+
Check(highlight, "select /* select */ select", "kkkkkk cccccccccccc kkkkkk");
195+
Check(highlight, "/**/ --", "cccc cc");
196+
Check(highlight, "/*/**/*/", "ccccccoo");
197+
}
186198
}

0 commit comments

Comments
 (0)