38 if (!input.get(ch))
break;
40 if (!input.get(ch))
break;
49 value.push_back(
'\b');
52 value.push_back(
'\f');
55 value.push_back(
'\n');
58 value.push_back(
'\r');
61 value.push_back(
'\t');
64 value.push_back(
'\033');
68 for (int64_t i = 3; input && i >= 0; i--) {
69 if (!input.get(ch))
break;
70 if (
'a' <= ch and ch <=
'z')
71 fuckutf += ((ch -
'a' + 10) * (1 << 4 * i));
72 else if (
'A' <= ch and ch <=
'Z')
73 fuckutf += ((ch -
'A' + 10) * (1 << 4 * i));
75 fuckutf += ((ch -
'0') * (1 << 4 * i));
77 value.push_back(fuckutf);
81 value.push_back(
'\0');
96 for (
auto ch : value) {
98 case L
'\\': result += L
"\\\\";
break;
99 case L
'\"': result += L
"\\\"";
break;
100 case L
'\'': result += L
"\\\'";
break;
101 case L
'\b': result += L
"\\b";
break;
102 case L
'\f': result += L
"\\f";
break;
103 case L
'\n': result += L
"\\n";
break;
104 case L
'\r': result += L
"\\r";
break;
105 case L
'\t': result += L
"\\t";
break;
106 case L
'\033': result += L
"\\e";
break;
107 case L
'\0': result += L
"\\0";
break;
109 if (ch < 32 || ch > 126) {
111 swprintf(buf, 7, L
"\\u%04x", (
unsigned int)ch);
129 if (!fileStream.is_open()) {
134 std::getline(fileStream, lineStr);
137 result += std::wstring(col - 1,
' ') + L
"^";
158 message +=
" near line " + std::to_string(line) +
" col " + std::to_string(col);
161 throw std::runtime_error(message);
171 panic(line, col, msg);
178 if (label ==
"NULLABLE_VALUE_SUPPLY_TO_RAW") {
180 }
else if (label ==
"UCRT_NOT_FOUND") {
182 }
else if (label ==
"ELYSIA_RUNTIME_NOT_FOUND") {
184 }
else if (label ==
"MODULE_NOT_MODIFIED") {
186 }
else if (label ==
"INTERNAL") {
202 message +=
" near line " + std::to_string(line) +
" col " + std::to_string(col);
206 std::cerr <<
"[hoshi-lang warning] " << message << std::endl;
220 panic(line, col, msg);
240 if (
auto res = std::filesystem::absolute(p, ec); ec)
241 throw std::runtime_error(
"Unable to resolve real path: [Errno " + std::to_string(ec.value()) +
"]" +
248 int length, dirnameLength;
250 if (
auto e = getenv(
"HOSHI_HOME"); e !=
nullptr) {
253 length = wai_getExecutablePath(
nullptr, 0, &dirnameLength);
254 path.resize(length + 1);
255 wai_getExecutablePath(path.data(), length, &dirnameLength);
258 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)
void report(const Diagnostic &diag)
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)
thread_local DiagnosticEngine * __current_diagnostic_engine
std::wstring whereIsHoshiLang()
DiagnosticEngine * get_diagnostic_engine()
Get the current thread-local diagnostic engine pointer (may be nullptr).
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_diagnostic_engine(DiagnosticEngine *engine)
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)