ArkScript
A small, fast, functional and scripting language for video games
Utils.hpp
Go to the documentation of this file.
1/**
2 * @file Utils.hpp
3 * @author Alexandre Plateau ([email protected])
4 * @brief replxx utilities
5 * @date 2020-10-27
6 *
7 * @copyright Copyright (c) 2020-2025
8 *
9 */
10
11#ifndef REPL_REPLXX_UTIL_HPP
12#define REPL_REPLXX_UTIL_HPP
13
14#include <vector>
15#include <string>
16
17#include <replxx.hxx>
18
19namespace Ark::internal
20{
21 /**
22 * @brief Count the open enclosure and its counterpart: (), {}, []
23 * @param line data to operate on
24 * @param open the open char: (, { or [
25 * @param close the closing char: ), } or ]
26 * @return positive if there are more open enclosures than closed. 0 when both are equal, negative otherwise
27 */
28 long countOpenEnclosures(const std::string& line, char open, char close);
29
30 /**
31 * @brief Remove whitespaces at the start and end of a string
32 * @param line string modified in place
33 */
34 void trimWhitespace(std::string& line);
35
36 /**
37 * @brief Compute a list of all the language keywords and builtins
38 *
39 * @return std::vector<std::string>
40 */
41 std::vector<std::string> getAllKeywords();
42
43 /**
44 * @brief Compute a list of pairs (word -> color) to be used for coloration by the REPL
45 * @return std::vector<std::pair<std::string, replxx::Replxx::Color>>
46 */
47 std::vector<std::pair<std::string, replxx::Replxx::Color>> getColorPerKeyword();
48
49 replxx::Replxx::completions_t hookCompletion(const std::vector<std::string>& words, const std::string& context, int& length);
50
51 void hookColor(const std::vector<std::pair<std::string, replxx::Replxx::Color>>& words_colors, const std::string& context, replxx::Replxx::colors_t& colors);
52
53 replxx::Replxx::hints_t hookHint(const std::vector<std::string>& words, const std::string& context, int& length, replxx::Replxx::Color& color);
54}
55
56#endif
std::vector< std::string > getAllKeywords()
Compute a list of all the language keywords and builtins.
long countOpenEnclosures(const std::string &line, char open, char close)
Count the open enclosure and its counterpart: (), {}, [].
void hookColor(const std::vector< std::pair< std::string, replxx::Replxx::Color > > &words_colors, const std::string &context, replxx::Replxx::colors_t &colors)
constexpr std::array colors
Definition Logger.cpp:8
replxx::Replxx::completions_t hookCompletion(const std::vector< std::string > &words, const std::string &context, int &length)
std::vector< std::pair< std::string, replxx::Replxx::Color > > getColorPerKeyword()
Compute a list of pairs (word -> color) to be used for coloration by the REPL.
replxx::Replxx::hints_t hookHint(const std::vector< std::string > &words, const std::string &context, int &length, replxx::Replxx::Color &color)
void trimWhitespace(std::string &line)
Remove whitespaces at the start and end of a string.