• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ArkScript-lang / Ark / 21916619485

11 Feb 2026 05:55PM UTC coverage: 93.464% (+0.05%) from 93.413%
21916619485

push

github

SuperFola
docs: adding arkdoc docstrings for append and friends, as well as assert

9195 of 9838 relevant lines covered (93.46%)

267918.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.02
/src/arkscript/REPL/Utils.cpp
1
#include <CLI/REPL/Utils.hpp>
2

3
#include <regex>
4
#include <algorithm>
5
#include <numeric>
6
#include <ranges>
7

8
#include <Ark/Builtins/Builtins.hpp>
9
#include <Ark/Compiler/Common.hpp>
10

11
namespace Ark::internal
12
{
13
    std::vector<std::string> getAllKeywords()
1✔
14
    {
1✔
15
        std::vector<std::string> output;
1✔
16
        output.reserve(keywords.size() + Language::listInstructions.size() + Language::operators.size() + Builtins::builtins.size() + 2);
1✔
17

18
        std::ranges::transform(keywords, std::back_inserter(output), [](const auto& string_view) {
10✔
19
            return std::string(string_view);
9✔
20
        });
×
21
        std::ranges::transform(Language::listInstructions, std::back_inserter(output), [](const auto& string_view) {
10✔
22
            return std::string(string_view);
9✔
23
        });
×
24
        std::ranges::transform(Language::operators, std::back_inserter(output), [](const auto& string_view) {
25✔
25
            return std::string(string_view);
24✔
26
        });
×
27
        std::ranges::transform(
1✔
28
            std::ranges::views::keys(Builtins::builtins) | std::ranges::views::filter([&output](const auto& val) -> bool {
91✔
29
                return std::ranges::find(output, val) == output.end();
90✔
30
            }),
31
            std::back_inserter(output), [](const auto& string) {
69✔
32
                return string;
68✔
33
            });
34

35
        output.emplace_back(Language::And);
1✔
36
        output.emplace_back(Language::Or);
1✔
37
        output.emplace_back(Language::Apply);
1✔
38

39
        return output;
1✔
40
    }
1✔
41

42
    std::vector<std::pair<std::string, replxx::Replxx::Color>> getColorPerKeyword()
1✔
43
    {
1✔
44
        using namespace replxx;
45
        using K = std::string;
46
        using V = Replxx::Color;
47

48
        std::vector<std::pair<K, V>> output;
1✔
49
        output.reserve(keywords.size() + Language::listInstructions.size() + Language::operators.size() + Builtins::builtins.size() + 4);
1✔
50

51
        std::ranges::transform(keywords, std::back_inserter(output), [](const auto& string_view) {
10✔
52
            return std::make_pair(std::string(string_view), Replxx::Color::BRIGHTRED);
9✔
53
        });
×
54
        std::ranges::transform(Language::listInstructions, std::back_inserter(output), [](const auto& string_view) {
10✔
55
            return std::make_pair(std::string(string_view), Replxx::Color::GREEN);
9✔
56
        });
×
57
        std::ranges::transform(Language::operators, std::back_inserter(output), [](const auto& string_view) {
25✔
58
            auto safe_op = std::string(string_view);
24✔
59
            if (const auto it = safe_op.find_first_of(R"(-+=/*<>[]()?")"); it != std::string::npos)
36✔
60
                safe_op.insert(it, "\\");
12✔
61
            return std::make_pair(safe_op, Replxx::Color::BRIGHTBLUE);
24✔
62
        });
24✔
63
        std::ranges::transform(
1✔
64
            std::ranges::views::keys(Builtins::builtins) | std::ranges::views::filter([&output](const auto& val) -> bool {
91✔
65
                return std::ranges::find_if(output, [&val](const std::pair<K, V>& pair) -> bool {
6,972✔
66
                           return pair.first == val;
6,882✔
67
                       }) == output.end();
90✔
68
            }),
69
            std::back_inserter(output), [](const auto& string) {
81✔
70
                auto safe_op = string;
80✔
71
                if (const auto it = safe_op.find_first_of(R"(-+=/*<>[]()?")"); it != std::string::npos)
96✔
72
                    safe_op.insert(it, "\\");
16✔
73
                return std::make_pair(safe_op, Replxx::Color::GREEN);
80✔
74
            });
80✔
75

76
        output.emplace_back(Language::And, Replxx::Color::BRIGHTBLUE);
1✔
77
        output.emplace_back(Language::Or, Replxx::Color::BRIGHTBLUE);
1✔
78
        output.emplace_back(Language::Apply, Replxx::Color::BRIGHTBLUE);
1✔
79
        output.emplace_back("[\\-|+]?[0-9]+(\\.[0-9]+)?", Replxx::Color::YELLOW);
1✔
80
        output.emplace_back("\".*\"", Replxx::Color::MAGENTA);
1✔
81

82
        return output;
1✔
83
    }
1✔
84

85
    std::size_t codepointLength(const std::string& str)
4✔
86
    {
4✔
87
        return std::accumulate(
4✔
88
            str.begin(),
4✔
89
            str.end(),
4✔
90
            std::size_t { 0 },
91
            [](const std::size_t acc, const char c) {
16✔
92
                return acc + ((c & 0xc0) != 0x80);
16✔
93
            });
94
    }
95

96
    std::size_t contextLen(const std::string& prefix)
2✔
97
    {
2✔
98
        const std::string word_break = " \t\n\r\v\f=+*&^%$#@!,./?<>;`~'\"[]{}()\\|";
2✔
99
        std::size_t count = 0;
2✔
100

101
        for (const auto c : std::ranges::views::reverse(prefix))
12✔
102
        {
103
            if (word_break.find(c) != std::string::npos)
10✔
104
                break;
×
105
            ++count;
10✔
106
        }
10✔
107

108
        return count;
2✔
109
    }
2✔
110

111
    replxx::Replxx::completions_t hookCompletion(const std::vector<std::string>& words, const std::string& context, int& length)
1✔
112
    {
1✔
113
        replxx::Replxx::completions_t completions;
1✔
114
        std::size_t utf8_context_len = contextLen(context);
1✔
115
        std::size_t prefix_len = context.size() - utf8_context_len;
1✔
116

117
        if (prefix_len > 0 && context[prefix_len - 1] == '\\')
1✔
118
        {
119
            --prefix_len;
×
120
            ++utf8_context_len;
×
121
        }
×
122

123
        length = static_cast<int>(codepointLength(context.substr(prefix_len, utf8_context_len)));
1✔
124

125
        const std::string prefix = context.substr(prefix_len);
1✔
126
        for (const auto& e : words)
114✔
127
        {
128
            if (e.starts_with(prefix))
113✔
129
                completions.emplace_back(e.c_str());
2✔
130
        }
113✔
131

132
        return completions;
1✔
133
    }
1✔
134

135
    void hookColor(const std::vector<std::pair<std::string, replxx::Replxx::Color>>& words_colors, const std::string& context, replxx::Replxx::colors_t& colors)
1✔
136
    {
1✔
137
        // highlight matching regex sequences
138
        for (const auto& [regex, color] : words_colors)
262✔
139
        {
140
            std::size_t pos = 0;
127✔
141
            std::string str = context;
127✔
142
            std::smatch match;
127✔
143

144
            while (std::regex_search(str, match, std::regex(regex)))
128✔
145
            {
146
                std::string c = match[0];
1✔
147
                std::string prefix = match.prefix().str();
1✔
148
                const std::size_t len = codepointLength(c);
1✔
149

150
                pos += codepointLength(prefix);
1✔
151
                for (std::size_t i = 0; i < len; ++i)
7✔
152
                {
153
                    if (colors.at(pos + i) == replxx::Replxx::Color::DEFAULT)
6✔
154
                        colors.at(pos + i) = color;
6✔
155
                }
6✔
156

157
                pos += len;
1✔
158
                str = match.suffix();
1✔
159
            }
1✔
160
        }
127✔
161
    }
1✔
162

163
    replxx::Replxx::hints_t hookHint(const std::vector<std::string>& words, const std::string& context, int& length, replxx::Replxx::Color& color)
1✔
164
    {
1✔
165
        replxx::Replxx::hints_t hints;
1✔
166
        // only show hint if prefix is at least 'n' chars long
167
        // or if prefix begins with a specific character
168
        const std::size_t utf8_context_len = contextLen(context);
1✔
169
        const std::size_t prefix_len = context.size() - utf8_context_len;
1✔
170
        length = static_cast<int>(codepointLength(context.substr(prefix_len, utf8_context_len)));
1✔
171
        const std::string prefix = context.substr(prefix_len);
1✔
172

173
        if (prefix.size() >= 2 || (!prefix.empty() && prefix.at(0) == '.'))
1✔
174
        {
175
            for (const auto& e : words)
114✔
176
            {
177
                if (e.compare(0, prefix.size(), prefix) == 0)
113✔
178
                    hints.emplace_back(e.c_str());
1✔
179
            }
113✔
180
        }
1✔
181

182
        if (hints.size() == 1)
1✔
183
            color = replxx::Replxx::Color::GREEN;
1✔
184

185
        return hints;
1✔
186
    }
1✔
187
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc