diff options
author | vitya-smirnov <[email protected]> | 2025-08-01 13:53:31 +0300 |
---|---|---|
committer | vitya-smirnov <[email protected]> | 2025-08-01 14:16:56 +0300 |
commit | 3b47f6e69ae8534f4595086c40faf14fb3a2661a (patch) | |
tree | 60414a19794fcfd2f168ffe44e5278c1d03dd671 /yql/essentials/tools/yql_highlight/generator_textmate.cpp | |
parent | 0e455c45d67077af33f521df4382c3ca80be4e1b (diff) |
YQL-19616: Generate YQLs syntax highlighting
- Support `Before` at core `TRegexPattern` and `IGenericLexer`.
- Added `Name` and `Extension` to core `THighlighting`.
- Added `Tighlighting` for `YQLs` factory method.
- Added `--language` option to `yql_highlight`.
- Added `artifact` targets for `YQLs`.
Yes, using the `NSQLTranslation::THighlighting` for
`YQLs` is not correct, but much simplier than generalize
this infrastructure just for a `YQLs`. So here is a
trade-off between development time and a clean code.
Results:
- JetBrains: https://nda.ya.ru/t/PXkZVE8m7H5wHS.
- Vim: https://nda.ya.ru/t/Am-6ZHQa7H5wJi.
- TextMate: https://nda.ya.ru/t/wH0YggAf7H5wKw.
- yql_highlight: https://nda.ya.ru/t/3FaCm57q7H7QSF.
commit_hash:f0e1abb8e7f1b083df531d761b357330bd514cb0
Diffstat (limited to 'yql/essentials/tools/yql_highlight/generator_textmate.cpp')
-rw-r--r-- | yql/essentials/tools/yql_highlight/generator_textmate.cpp | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/yql/essentials/tools/yql_highlight/generator_textmate.cpp b/yql/essentials/tools/yql_highlight/generator_textmate.cpp index 7a0a66c0e3d..2c90cde77b9 100644 --- a/yql/essentials/tools/yql_highlight/generator_textmate.cpp +++ b/yql/essentials/tools/yql_highlight/generator_textmate.cpp @@ -49,6 +49,10 @@ namespace NSQLHighlight { regex << R"re(\b)re"; } + if (!pattern.Before.empty()) { + regex << "(?<=" << pattern.Before << ")"; + } + regex << "(" << pattern.Body << ")"; if (!pattern.After.empty()) { @@ -123,9 +127,9 @@ namespace NSQLHighlight { NTextMate::TLanguage ToTextMateLanguage(const THighlighting& highlighting) { NTextMate::TLanguage language = { - .Name = "YQL", - .ScopeName = "source.yql", - .FileTypes = {"yql"}, + .Name = highlighting.Name, + .ScopeName = "source." + highlighting.Extension, + .FileTypes = {highlighting.Extension}, }; for (const TUnit& unit : highlighting.Units) { @@ -166,6 +170,7 @@ namespace NSQLHighlight { root["$schema"] = "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json"; root["name"] = language.Name; root["scopeName"] = language.ScopeName; + root["scope"] = language.ScopeName; for (const TString& type : language.FileTypes) { root["fileTypes"].AppendValue(type); @@ -219,14 +224,15 @@ namespace NSQLHighlight { Print(out, ToJson(ToTextMateLanguage(highlighting))); } + static const THashMap<TString, TString> UUID = { + {"InfoYQL", "059de4a7-ff49-4dbd-8a9d-a8114b77c4b9"}, + {"SyntaxYQL", "bb7a80e5-733c-4ea6-9654-40db0675950c"}, + {"InfoYQLs", "7f536d44-2667-430e-b145-540992400cb3"}, + {"SyntaxYQLs", "6e62e13a-487b-4333-bbb2-9453d0783f8f"}, + }; + class TTextMateBundleGenerator: public IGenerator { private: - static constexpr TStringBuf InfoUUID = "9BB0DBAF-E65C-4E14-A6A7-467D4AA535E0"; - static constexpr TStringBuf SyntaxUUID = "1C3868E4-F96B-4E55-B204-1DCB5A20748B"; - static constexpr TStringBuf BundleDir = "YQL.tmbundle"; - static constexpr TStringBuf InfoFile = "info.plist"; - static constexpr TStringBuf SyntaxFile = "Syntaxes/YQL.tmLanguage"; - template <class TWriter> void Write( NTar::TArchiveWriter& acrhive, @@ -242,28 +248,40 @@ namespace NSQLHighlight { public: void Write(IOutputStream& out, const THighlighting& highlighting) final { - out << "File " << BundleDir << "/" << InfoFile << ":" << '\n'; + const auto [bundle, info, syntax] = Paths(highlighting); + + out << "File " << bundle << "/" << info << ":" << '\n'; WriteInfo(out, ToTextMateLanguage(highlighting)); - out << "File " << BundleDir << "/" << SyntaxFile << ":" << '\n'; + out << "File " << bundle << "/" << syntax << ":" << '\n'; WriteSyntax(out, ToTextMateLanguage(highlighting)); } void Write(const TFsPath& path, const THighlighting& highlighting) final { - if (TString name = path.GetName(); !name.StartsWith(BundleDir)) { + const auto [bundle, info, syntax] = Paths(highlighting); + + if (TString name = path.GetName(); !name.StartsWith(bundle)) { ythrow yexception() << "Invalid path '" << name - << "', expected '" << BundleDir << "' " + << "', expected '" << bundle << "' " << "as an archive name"; } NTextMate::TLanguage language = ToTextMateLanguage(highlighting); NTar::TArchiveWriter archive(path); - Write(archive, InfoFile, WriteInfo, language); - Write(archive, SyntaxFile, WriteSyntax, language); + Write(archive, info, WriteInfo, language); + Write(archive, syntax, WriteSyntax, language); } private: + static std::tuple<TString, TString, TString> Paths(const THighlighting& h) { + return { + TStringBuilder() << h.Name << ".tmbundle", + TStringBuilder() << "info.plist", + TStringBuilder() << "Syntaxes/" << h.Name << ".tmLanguage", + }; + } + static void WriteInfo(IOutputStream& out, const NTextMate::TLanguage& language) { out << R"(<?xml version="1.0" encoding="UTF-8"?>)" << '\n'; out << R"(<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">)" << '\n'; @@ -272,7 +290,7 @@ namespace NSQLHighlight { out << R"( <key>name</key>)" << '\n'; out << R"( <string>)" << language.Name << R"(</string>)" << '\n'; out << R"( <key>uuid</key>)" << '\n'; - out << R"( <string>)" << InfoUUID << R"(</string>)" << '\n'; + out << R"( <string>)" << UUID.at("Info" + language.Name) << R"(</string>)" << '\n'; out << R"(</dict>)" << '\n'; out << R"(</plist>)" << '\n'; } @@ -280,7 +298,7 @@ namespace NSQLHighlight { static void WriteSyntax(IOutputStream& out, const NTextMate::TLanguage& language) { NJson::TJsonValue json = ToJson(language); json.EraseValue("$schema"); - json["uuid"] = SyntaxUUID; + json["uuid"] = UUID.at("Syntax" + language.Name); out << R"(<?xml version="1.0" encoding="UTF-8"?>)" << '\n'; out << R"(<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">)" << '\n'; |