ArkScript
A small, fast, functional and scripting language for video games
Import.hpp
Go to the documentation of this file.
1#ifndef ARK_COMPILER_AST_IMPORT_HPP
2#define ARK_COMPILER_AST_IMPORT_HPP
3
4#include <vector>
5#include <string>
6#include <numeric>
7
8#include <Ark/Platform.hpp>
9
10namespace Ark::internal
11{
13 {
14 std::size_t line, col; ///< Position in the source file
15
16 /**
17 * @brief The filename without the extension
18 * @details Example: `(import foo.bar)` => `bar`
19 * `(import foo.bar.egg:*)` => `egg`
20 * `(import foo :a :b :c)` => `foo`
21 *
22 */
23 std::string prefix;
24
25 /**
26 * @brief Package with all the segments
27 * @details Example: `(import foo.bar)` => `{foo, bar}`
28 * `(import foo.bar.egg:*)` => `{foo, bar, egg}`
29 * `(import foo :a :b :c)` => `{foo}`
30 */
31 std::vector<std::string> package;
32
33 /**
34 * @brief Import with prefix (import package)
35 *
36 */
37 bool with_prefix = true;
38
39 /**
40 * @brief Import as glob (import package:*)
41 */
42 bool is_glob = false;
43
44 /**
45 * @brief List of symbols to import, can be empty if none provided. (import package :a :b)
46 *
47 */
48 std::vector<std::string> symbols;
49
50 /**
51 *
52 * @return a package string, eg a.b.c
53 */
54 [[nodiscard]] std::string toPackageString() const
55 {
56 return std::accumulate(package.begin() + 1, package.end(), package.front(), [](const std::string& left, const std::string& right) {
57 return left + "." + right;
58 });
59 }
60
61 /**
62 *
63 * @return a package as a path, eg a/b/c
64 */
65 [[nodiscard]] std::string packageToPath() const
66 {
67 return std::accumulate(
68 std::next(package.begin()),
69 package.end(),
70 package[0],
71 [](const std::string& a, const std::string& b) {
72 return a + "/" + b;
73 });
74 }
75
76 /**
77 * @brief Check if we should import everything with a prefix, given a `(import foo.bar.egg)`
78 *
79 * @return true
80 * @return false
81 */
82 [[nodiscard]] bool isBasic() const
83 {
84 return with_prefix && symbols.empty();
85 }
86 };
87}
88
89#endif
#define ARK_API
Definition Module.hpp:28
ArkScript configuration macros.
bool isBasic() const
Check if we should import everything with a prefix, given a (import foo.bar.egg)
Definition Import.hpp:82
std::vector< std::string > symbols
List of symbols to import, can be empty if none provided. (import package :a :b)
Definition Import.hpp:48
std::size_t col
Position in the source file.
Definition Import.hpp:14
std::string prefix
The filename without the extension.
Definition Import.hpp:23
std::string packageToPath() const
Definition Import.hpp:65
std::string toPackageString() const
Definition Import.hpp:54
std::vector< std::string > package
Package with all the segments.
Definition Import.hpp:31