|
8 | 8 | #include "value.h" |
9 | 9 | #include "instruction.h" |
10 | 10 | #include "fileio.h" |
| 11 | +#include "parsepreprocessor.h" |
11 | 12 | #include <sstream> |
12 | 13 |
|
13 | 14 | namespace { |
@@ -257,6 +258,62 @@ void sqf::debugger::check(virtualmachine * vm) |
257 | 258 | auto data = json["data"]; |
258 | 259 | _server->push_message(variablemsg(vm, vm->stack(), data)); |
259 | 260 | } |
| 261 | + else if (mode == "preprocess") |
| 262 | + { |
| 263 | + auto data = json["data"]; |
| 264 | + auto res = data.find("path"); |
| 265 | + if (res != data.end()) |
| 266 | + { |
| 267 | + std::string path = *res; |
| 268 | + path = vm->get_filesystem().sanitize(path); |
| 269 | + auto phys = vm->get_filesystem().try_get_physical_path(path); |
| 270 | + if (phys.has_value()) |
| 271 | + { |
| 272 | + auto filecontents = load_file(phys.value()); |
| 273 | + bool errflag = false; |
| 274 | + auto ppres = sqf::parse::preprocessor::parse(vm, filecontents, errflag, path); |
| 275 | + if (errflag) |
| 276 | + { |
| 277 | + auto err = vm->err().str(); |
| 278 | + vm->err_clear(); |
| 279 | + _server->push_message(errormsg(err)); |
| 280 | + } |
| 281 | + else |
| 282 | + { |
| 283 | + nlohmann::json json = { |
| 284 | + { "mode", "message" }, |
| 285 | + { "data", ppres } |
| 286 | + }; |
| 287 | + _server->push_message(json.dump()); |
| 288 | + } |
| 289 | + } |
| 290 | + else |
| 291 | + { |
| 292 | + _server->push_message(errormsg("Path not found.")); |
| 293 | + } |
| 294 | + } |
| 295 | + else |
| 296 | + { |
| 297 | + std::string content = data["content"]; |
| 298 | + auto filecontents = load_file(content); |
| 299 | + bool errflag = false; |
| 300 | + auto ppres = sqf::parse::preprocessor::parse(vm, filecontents, errflag, "__debugger.sqf"); |
| 301 | + if (errflag) |
| 302 | + { |
| 303 | + auto err = vm->err().str(); |
| 304 | + vm->err_clear(); |
| 305 | + _server->push_message(errormsg(err)); |
| 306 | + } |
| 307 | + else |
| 308 | + { |
| 309 | + nlohmann::json json = { |
| 310 | + { "mode", "message" }, |
| 311 | + { "data", ppres } |
| 312 | + }; |
| 313 | + _server->push_message(json.dump()); |
| 314 | + } |
| 315 | + } |
| 316 | + } |
260 | 317 | else if (mode == "parse-sqf") |
261 | 318 | { |
262 | 319 | auto data = json["data"]; |
|
0 commit comments