28 if (!input.get(ch))
break;
30 if (!input.get(ch))
break;
39 value.push_back(
'\b');
42 value.push_back(
'\f');
45 value.push_back(
'\n');
48 value.push_back(
'\r');
51 value.push_back(
'\t');
54 value.push_back(
'\033');
58 for (int64_t i = 3; input && i >= 0; i--) {
59 if (!input.get(ch))
break;
60 if (
'a' <= ch and ch <=
'z')
61 fuckutf += ((ch -
'a' + 10) * (1 << 4 * i));
62 else if (
'A' <= ch and ch <=
'Z')
63 fuckutf += ((ch -
'A' + 10) * (1 << 4 * i));
65 fuckutf += ((ch -
'0') * (1 << 4 * i));
67 value.push_back(fuckutf);
71 value.push_back(
'\0');
86 for (
auto ch : value) {
88 case L
'\\': result += L
"\\\\";
break;
89 case L
'\"': result += L
"\\\"";
break;
90 case L
'\'': result += L
"\\\'";
break;
91 case L
'\b': result += L
"\\b";
break;
92 case L
'\f': result += L
"\\f";
break;
93 case L
'\n': result += L
"\\n";
break;
94 case L
'\r': result += L
"\\r";
break;
95 case L
'\t': result += L
"\\t";
break;
96 case L
'\033': result += L
"\\e";
break;
97 case L
'\0': result += L
"\\0";
break;
99 if (ch < 32 || ch > 126) {
101 swprintf(buf, 7, L
"\\u%04x", (
unsigned int)ch);
119 if (!fileStream.is_open()) {
124 std::getline(fileStream, lineStr);
127 result += std::wstring(col - 1,
' ') + L
"^";
137 message +=
" near line " + std::to_string(line) +
" col " + std::to_string(col);
140 throw std::runtime_error(message);
148 panic(line, col, msg);
156 message +=
" near line " + std::to_string(line) +
" col " + std::to_string(col);
160 std::cerr <<
"[hoshi-lang warning] " << message << std::endl;
174 panic(line, col, msg);
194 if (
auto res = std::filesystem::absolute(p, ec); ec)
195 throw std::runtime_error(
"Unable to resolve real path: [Errno " + std::to_string(ec.value()) +
"]" +
202 int length, dirnameLength;
204 if (
auto e = getenv(
"HOSHI_HOME"); e !=
nullptr) {
207 length = wai_getExecutablePath(
nullptr, 0, &dirnameLength);
208 path.resize(length + 1);
209 wai_getExecutablePath(path.data(), length, &dirnameLength);
212 path.substr(0, path.rfind(std::filesystem::path::preferred_separator)));
static bool utf8ToUnicode(const std::string &utf8, std::wstring &unicode)
static void unicodeToUtf8(const std::wstring &unicode, std::string &utf8)
std::string wstring2string(const std::wstring &v)
void warning(yoi::indexT line, yoi::indexT col, const std::string &msg, const std::string &label)
void parseString(std::wistream &input, wstr &value)
std::wstring string2wstring(const std::string &v)
yoi::wstr realpath(const std::wstring &path)
std::wstring whereIsHoshiLang()
thread_local yoi::wstr __current_file_path
wstr escapeString(const wstr &value)
void yoi_assert(bool condition, yoi::indexT line, yoi::indexT col, const std::string &msg)
Asserts a condition that would be true and throws a runtime_error if it is false.
std::wstring get_line_hint_for_error(const std::wstring &file, yoi::indexT line, yoi::indexT col)
void set_current_file_path(const std::wstring &path)
std::map< std::string, ExceptionHandleType > exception_categories
void panic(yoi::indexT line, yoi::indexT col, const std::string &msg)