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

ArkScript-lang / Ark / 14823373998

04 May 2025 05:03PM UTC coverage: 86.442% (+0.03%) from 86.409%
14823373998

push

github

SuperFola
fix: change the color of the function name inside runtime typechecking errors from blue to cyan to be easier to read inside dark terminals

0 of 1 new or added line in 1 file covered. (0.0%)

195 existing lines in 22 files now uncovered.

6835 of 7907 relevant lines covered (86.44%)

79668.53 hits per line

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

8.87
/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
    long countOpenEnclosures(const std::string& line, const char open, const char close)
6✔
14
    {
6✔
15
        return std::ranges::count(line, open) - std::ranges::count(line, close);
6✔
16
    }
17

18
    void trimWhitespace(std::string& line)
4✔
19
    {
4✔
20
        const std::size_t string_begin = line.find_first_not_of(" \t");
4✔
21
        if (std::string::npos != string_begin)
4✔
22
        {
23
            const std::size_t string_end = line.find_last_not_of(" \t");
4✔
24
            line = line.substr(string_begin, string_end - string_begin + 1);
4✔
25
        }
4✔
26
    }
4✔
27

28
    std::vector<std::string> getAllKeywords()
×
29
    {
×
30
        std::vector<std::string> output;
×
31
        output.reserve(keywords.size() + Language::listInstructions.size() + Language::operators.size() + Builtins::builtins.size() + 2);
×
32

33
        std::ranges::transform(keywords, std::back_inserter(output), [](const auto& string_view) {
×
34
            return std::string(string_view);
×
35
        });
×
36
        std::ranges::transform(Language::listInstructions, std::back_inserter(output), [](const auto& string_view) {
×
37
            return std::string(string_view);
×
38
        });
×
39
        std::ranges::transform(Language::operators, std::back_inserter(output), [](const auto& string_view) {
×
40
            return std::string(string_view);
×
41
        });
×
UNCOV
42
        std::ranges::transform(std::ranges::views::keys(Builtins::builtins), std::back_inserter(output), [](const auto& string) {
×
43
            return string;
×
44
        });
45

46
        output.emplace_back("and");
×
47
        output.emplace_back("or");
×
48

UNCOV
49
        return output;
×
50
    }
×
51

52
    std::vector<std::pair<std::string, replxx::Replxx::Color>> getColorPerKeyword()
×
53
    {
×
54
        using namespace replxx;
55
        using K = std::string;
56
        using V = Replxx::Color;
57

58
        std::vector<std::pair<K, V>> output;
×
59
        output.reserve(keywords.size() + Language::listInstructions.size() + Language::operators.size() + Builtins::builtins.size() + 4);
×
60

61
        std::ranges::transform(keywords, std::back_inserter(output), [](const auto& string_view) {
×
62
            return std::make_pair(std::string(string_view), Replxx::Color::BRIGHTRED);
×
63
        });
×
64
        std::ranges::transform(Language::listInstructions, std::back_inserter(output), [](const auto& string_view) {
×
UNCOV
65
            return std::make_pair(std::string(string_view), Replxx::Color::GREEN);
×
66
        });
×
67
        std::ranges::transform(Language::operators, std::back_inserter(output), [](const auto& string_view) {
×
68
            auto safe_op = std::string(string_view);
×
69
            if (const auto it = safe_op.find_first_of(R"(-+=/*<>[]()?")"); it != std::string::npos)
×
UNCOV
70
                safe_op.insert(it, "\\");
×
71
            return std::make_pair(safe_op, Replxx::Color::BRIGHTBLUE);
×
72
        });
×
UNCOV
73
        std::ranges::transform(std::ranges::views::keys(Builtins::builtins), std::back_inserter(output), [](const auto& string) {
×
74
            return std::make_pair(string, Replxx::Color::GREEN);
×
75
        });
76

77
        output.emplace_back("and", Replxx::Color::BRIGHTBLUE);
×
78
        output.emplace_back("or", Replxx::Color::BRIGHTBLUE);
×
UNCOV
79
        output.emplace_back("[\\-|+]?[0-9]+(\\.[0-9]+)?", Replxx::Color::YELLOW);
×
80
        output.emplace_back("\".*\"", Replxx::Color::MAGENTA);
×
81

UNCOV
82
        return output;
×
UNCOV
83
    }
×
84

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

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

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

108
        return count;
×
109
    }
×
110

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

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

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

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

UNCOV
132
        return completions;
×
133
    }
×
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)
×
136
    {
×
137
        // highlight matching regex sequences
UNCOV
138
        for (const auto& [regex, color] : words_colors)
×
139
        {
140
            std::size_t pos = 0;
×
141
            std::string str = context;
×
UNCOV
142
            std::smatch match;
×
143

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

150
                pos += codepointLength(prefix);
×
151
                for (std::size_t i = 0; i < len; ++i)
×
UNCOV
152
                    colors.at(pos + i) = color;
×
153

154
                pos += len;
×
155
                str = match.suffix();
×
156
            }
×
157
        }
×
UNCOV
158
    }
×
159

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

UNCOV
170
        if (prefix.size() >= 2 || (!prefix.empty() && prefix.at(0) == '.'))
×
171
        {
172
            for (const auto& e : words)
×
173
            {
UNCOV
174
                if (e.compare(0, prefix.size(), prefix) == 0)
×
UNCOV
175
                    hints.emplace_back(e.c_str());
×
UNCOV
176
            }
×
UNCOV
177
        }
×
178

UNCOV
179
        if (hints.size() == 1)
×
UNCOV
180
            color = replxx::Replxx::Color::GREEN;
×
181

UNCOV
182
        return hints;
×
UNCOV
183
    }
×
184
}
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