summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrobot-piglet <[email protected]>2025-08-08 20:53:22 +0300
committerrobot-piglet <[email protected]>2025-08-08 21:04:26 +0300
commit5365d2ffcf613e81cd3b573caed6a2f01a45fddc (patch)
tree33a2c1f27a806d4106e9afb5fbfc01b8a7252cd3
parentf0db567556daf8b56d40f99bb9346842517d756c (diff)
Intermediate changes
commit_hash:7d11e0fa6106e0eb6610524755168f87a192a112
-rw-r--r--yql/essentials/tools/yql_highlight/generator_highlight_js.cpp121
-rw-r--r--yql/essentials/tools/yql_highlight/generator_highlight_js.h9
-rw-r--r--yql/essentials/tools/yql_highlight/generator_monarch.cpp22
-rw-r--r--yql/essentials/tools/yql_highlight/highlighting.cpp13
-rw-r--r--yql/essentials/tools/yql_highlight/highlighting.h21
-rw-r--r--yql/essentials/tools/yql_highlight/ya.make2
-rw-r--r--yql/essentials/tools/yql_highlight/yql_highlight.cpp2
7 files changed, 170 insertions, 20 deletions
diff --git a/yql/essentials/tools/yql_highlight/generator_highlight_js.cpp b/yql/essentials/tools/yql_highlight/generator_highlight_js.cpp
new file mode 100644
index 00000000000..cc22b8cda08
--- /dev/null
+++ b/yql/essentials/tools/yql_highlight/generator_highlight_js.cpp
@@ -0,0 +1,121 @@
+#include "generator_highlight_js.h"
+
+#include "json.h"
+#include "highlighting.h"
+
+#include <contrib/libs/re2/re2/re2.h>
+#include <util/string/builder.h>
+
+namespace NSQLHighlight {
+
+ TString ToHighlightJSClass(EUnitKind kind) {
+ switch (kind) {
+ case EUnitKind::Keyword:
+ return "keyword";
+ case EUnitKind::Punctuation:
+ return "punctuation";
+ case EUnitKind::QuotedIdentifier:
+ return "symbol";
+ case EUnitKind::BindParameterIdentifier:
+ return "variable";
+ case EUnitKind::TypeIdentifier:
+ return "type";
+ case EUnitKind::FunctionIdentifier:
+ return "title.function";
+ case EUnitKind::Identifier:
+ return "";
+ case EUnitKind::Literal:
+ return "number";
+ case EUnitKind::StringLiteral:
+ return "string";
+ case EUnitKind::Comment:
+ return "comment";
+ case EUnitKind::Whitespace:
+ return "";
+ case EUnitKind::Error:
+ return "";
+ }
+ }
+
+ // FIXME: copy-pasted from generator_textmate.cpp.
+ TString ToTextMateRegex(const TUnit& unit, const NSQLTranslationV1::TRegexPattern& pattern) {
+ TStringBuilder regex;
+
+ if (unit.IsPlain) {
+ regex << R"re(\b)re";
+ }
+
+ if (!pattern.Before.empty()) {
+ regex << "(?<=" << pattern.Before << ")";
+ }
+
+ regex << "(" << pattern.Body << ")";
+
+ if (!pattern.After.empty()) {
+ regex << "(?=" << pattern.After << ")";
+ }
+
+ if (unit.IsPlain) {
+ regex << R"re(\b)re";
+ }
+
+ return regex;
+ }
+
+ NJson::TJsonValue ToHighlightJSPattern(const TUnit& unit, const NSQLTranslationV1::TRegexPattern& pattern) {
+ NJson::TJsonMap json;
+ json["className"] = ToHighlightJSClass(unit.Kind);
+ json["begin"] = ToTextMateRegex(unit, pattern);
+ return json;
+ }
+
+ NJson::TJsonValue ToHighlightJSPattern(const TUnit& unit, const TRangePattern& pattern) {
+ NJson::TJsonMap json;
+ json["className"] = ToHighlightJSClass(unit.Kind);
+ json["begin"] = RE2::QuoteMeta(pattern.Begin);
+ json["end"] = RE2::QuoteMeta(pattern.End);
+ return json;
+ }
+
+ NJson::TJsonValue ToHighlightJSContains(const THighlighting& highlighting) {
+ NJson::TJsonArray array;
+
+ for (const TUnit& unit : highlighting.Units) {
+ if (unit.IsCodeGenExcluded || unit.Kind == EUnitKind::Identifier) {
+ continue;
+ }
+
+ for (const NSQLTranslationV1::TRegexPattern& pattern : unit.Patterns) {
+ array.AppendValue(ToHighlightJSPattern(unit, pattern));
+ }
+ if (auto range = unit.RangePattern) {
+ array.AppendValue(ToHighlightJSPattern(unit, *range));
+ }
+ }
+
+ return array;
+ }
+
+ NJson::TJsonValue ToHighlightJSON(const THighlighting& highlighting) {
+ NJson::TJsonMap json;
+ json["name"] = highlighting.Name;
+ json["case_insensitive"] = IsCaseInsensitive(highlighting);
+ json["contains"] = NJson::TJsonArray{{NJson::TJsonMap{
+ {"begin", ""},
+ {"end", ";"},
+ {"endsWithParent", true},
+ {"lexemes", R"re(\w+)re"},
+ {"contains", ToHighlightJSContains(highlighting)},
+ }}};
+ return json;
+ }
+
+ void GenerateHighlightJS(IOutputStream& out, const THighlighting& highlighting) {
+ Print(out, ToHighlightJSON(highlighting));
+ }
+
+ IGenerator::TPtr MakeHighlightJSGenerator() {
+ return MakeOnlyFileGenerator(GenerateHighlightJS);
+ }
+
+} // namespace NSQLHighlight
diff --git a/yql/essentials/tools/yql_highlight/generator_highlight_js.h b/yql/essentials/tools/yql_highlight/generator_highlight_js.h
new file mode 100644
index 00000000000..160a4cf708d
--- /dev/null
+++ b/yql/essentials/tools/yql_highlight/generator_highlight_js.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "generator.h"
+
+namespace NSQLHighlight {
+
+ IGenerator::TPtr MakeHighlightJSGenerator();
+
+} // namespace NSQLHighlight
diff --git a/yql/essentials/tools/yql_highlight/generator_monarch.cpp b/yql/essentials/tools/yql_highlight/generator_monarch.cpp
index 28b72e14257..b38416c8caa 100644
--- a/yql/essentials/tools/yql_highlight/generator_monarch.cpp
+++ b/yql/essentials/tools/yql_highlight/generator_monarch.cpp
@@ -1,5 +1,7 @@
#include "generator_monarch.h"
+#include "highlighting.h"
+
#include <contrib/libs/re2/re2/re2.h>
#include <library/cpp/json/json_writer.h>
@@ -8,26 +10,6 @@
namespace NSQLHighlight {
- bool IsCaseInsensitive(const THighlighting& highlighting) {
- return AnyOf(highlighting.Units, [](const TUnit& unit) {
- return AnyOf(unit.Patterns, [](const NSQLTranslationV1::TRegexPattern& p) {
- return p.IsCaseInsensitive;
- });
- });
- }
-
- template <std::invocable<const TUnit&> Action>
- void ForEachMultiLine(const THighlighting& highlighting, Action action) {
- for (const TUnit& unit : highlighting.Units) {
- TMaybe<TRangePattern> range = unit.RangePattern;
- if (!range) {
- continue;
- }
-
- action(unit);
- }
- }
-
TString ToMonarchRegex(const TUnit& unit, const NSQLTranslationV1::TRegexPattern& pattern) {
TStringBuilder regex;
diff --git a/yql/essentials/tools/yql_highlight/highlighting.cpp b/yql/essentials/tools/yql_highlight/highlighting.cpp
new file mode 100644
index 00000000000..238eb1f32b3
--- /dev/null
+++ b/yql/essentials/tools/yql_highlight/highlighting.cpp
@@ -0,0 +1,13 @@
+#include "highlighting.h"
+
+namespace NSQLHighlight {
+
+ bool IsCaseInsensitive(const THighlighting& highlighting) {
+ return AnyOf(highlighting.Units, [](const TUnit& unit) {
+ return AnyOf(unit.Patterns, [](const NSQLTranslationV1::TRegexPattern& p) {
+ return p.IsCaseInsensitive;
+ });
+ });
+ }
+
+} // namespace NSQLHighlight
diff --git a/yql/essentials/tools/yql_highlight/highlighting.h b/yql/essentials/tools/yql_highlight/highlighting.h
new file mode 100644
index 00000000000..6cb4e0dd691
--- /dev/null
+++ b/yql/essentials/tools/yql_highlight/highlighting.h
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <yql/essentials/sql/v1/highlight/sql_highlight.h>
+
+namespace NSQLHighlight {
+
+ bool IsCaseInsensitive(const THighlighting& highlighting);
+
+ template <std::invocable<const TUnit&> Action>
+ void ForEachMultiLine(const THighlighting& highlighting, Action action) {
+ for (const TUnit& unit : highlighting.Units) {
+ TMaybe<TRangePattern> range = unit.RangePattern;
+ if (!range) {
+ continue;
+ }
+
+ action(unit);
+ }
+ }
+
+} // namespace NSQLHighlight
diff --git a/yql/essentials/tools/yql_highlight/ya.make b/yql/essentials/tools/yql_highlight/ya.make
index 08396a77998..15a0fd5ab01 100644
--- a/yql/essentials/tools/yql_highlight/ya.make
+++ b/yql/essentials/tools/yql_highlight/ya.make
@@ -10,11 +10,13 @@ IF (NOT EXPORT_CMAKE OR NOT OPENSOURCE OR OPENSOURCE_PROJECT != "yt")
)
SRCS(
+ generator_highlight_js.cpp
generator_json.cpp
generator_monarch.cpp
generator_textmate.cpp
generator_vim.cpp
generator.cpp
+ highlighting.cpp
json.cpp
yql_highlight.cpp
yqls_highlight.cpp
diff --git a/yql/essentials/tools/yql_highlight/yql_highlight.cpp b/yql/essentials/tools/yql_highlight/yql_highlight.cpp
index ea42c579e88..d871004720e 100644
--- a/yql/essentials/tools/yql_highlight/yql_highlight.cpp
+++ b/yql/essentials/tools/yql_highlight/yql_highlight.cpp
@@ -1,3 +1,4 @@
+#include "generator_highlight_js.h"
#include "generator_json.h"
#include "generator_monarch.h"
#include "generator_textmate.h"
@@ -32,6 +33,7 @@ const TGeneratorMap generators = {
{"tmlanguage", MakeTextMateJsonGenerator},
{"tmbundle", MakeTextMateBundleGenerator},
{"vim", MakeVimGenerator},
+ {"highlightjs", MakeHighlightJSGenerator},
};
template <class TMap>