summaryrefslogtreecommitdiffstats
path: root/yql/essentials/tools/yql_highlight/yqls_highlight.cpp
blob: 2894b3f952965a7842b6d5137d841364a818f4bb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "yqls_highlight.h"

namespace NSQLHighlight {

    using TRe = NSQLTranslationV1::TRegexPattern;
    using NSQLTranslationV1::Merged;

    THighlighting MakeYQLsHighlighting() {
        TString id = R"re([A-Za-z_\-0-9]+)re";
        TString lower = R"re([a-z_0-9])re" + SubstGlobalCopy(id, '+', '*');
        TString title = R"re([A-Z])re" + SubstGlobalCopy(id, '+', '*');

        TRe keywords = Merged({
            {"let"},
            {"return"},
            {"quote"},
            {"block"},
            {"lambda"},
            {"declare"},
            {"import"},
            {"export"},
            {"library"},
            {"override_library"},
            {"package"},
            {"set_package_version"},
        });
        keywords.Before = R"re(\()re";

        return {
            .Name = "YQLs",
            .Extension = "yqls",
            .Units = {
                TUnit{
                    .Kind = EUnitKind::Comment,
                    .Patterns = {TRe{R"re(#.*)re"}},
                    .IsPlain = false,
                },
                TUnit{
                    .Kind = EUnitKind::Keyword,
                    .Patterns = {keywords},
                },
                TUnit{
                    .Kind = EUnitKind::BindParameterIdentifier,
                    .Patterns = {TRe{"world"}},
                },
                TUnit{
                    .Kind = EUnitKind::QuotedIdentifier,
                    .Patterns = {
                        TRe{.Body = id + "!", .Before = R"re(\()re"},
                    },
                    .IsPlain = false,
                },
                TUnit{
                    .Kind = EUnitKind::FunctionIdentifier,
                    .Patterns = {
                        TRe{.Body = title, .Before = R"re(\()re"},
                        TRe{.Body = "'" + id + "\\." + id},
                    },
                    .IsPlain = false,
                },
                TUnit{
                    .Kind = EUnitKind::Literal,
                    .Patterns = {TRe{"'" + id}},
                    .IsPlain = false,
                },
                TUnit{
                    .Kind = EUnitKind::Identifier,
                    .Patterns = {TRe{lower}},
                },
                TUnit{
                    .Kind = EUnitKind::StringLiteral,
                    .Patterns = {
                        TRe{R"re(\"[^\"\n]*\")re"},
                        TRe{R"re(\@\@(.|\n)*\@\@)re"},
                    },
                    .RangePattern = TRangePattern{
                        .Begin = "@@",
                        .End = "@@",
                    },
                    .IsPlain = false,
                },
                TUnit{
                    .Kind = EUnitKind::Punctuation,
                    .Patterns = {TRe{R"re(['\(\)])re"}},
                    .IsPlain = false,
                    .IsCodeGenExcluded = true,
                },
                TUnit{
                    .Kind = EUnitKind::Whitespace,
                    .Patterns = {TRe{R"re(\s+)re"}},
                    .IsPlain = false,
                    .IsCodeGenExcluded = true,
                },
            },
        };
    }

} // namespace NSQLHighlight