summaryrefslogtreecommitdiff
path: root/src/parsing.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/parsing.h')
-rw-r--r--src/parsing.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/parsing.h b/src/parsing.h
index 2104337a6..6745ad7cd 100644
--- a/src/parsing.h
+++ b/src/parsing.h
@@ -17,12 +17,15 @@
#ifndef wasm_parsing_h
#define wasm_parsing_h
+#include <ostream>
#include <sstream>
+#include <string>
#include "asmjs/shared-constants.h"
#include "mixed_arena.h"
#include "support/utilities.h"
#include "wasm.h"
+#include "wasm-printing.h"
namespace wasm {
@@ -162,6 +165,30 @@ inline Expression* parseConst(cashew::IString s, WasmType type, MixedArena& allo
return ret;
}
+struct ParseException {
+ std::string text;
+ size_t line, col;
+
+ ParseException() : text("unknown parse error"), line(-1), col(-1) {}
+ ParseException(std::string text) : text(text), line(-1), col(-1) {}
+ ParseException(std::string text, size_t line, size_t col) : text(text), line(line), col(col) {}
+
+ void dump(std::ostream& o) {
+ Colors::magenta(o);
+ o << "[";
+ Colors::red(o);
+ o << "parse exception: ";
+ Colors::green(o);
+ o << text;
+ if (line != size_t(-1)) {
+ Colors::normal(o);
+ o << " (at " << line << ":" << col << ")";
+ }
+ Colors::magenta(o);
+ o << "]";
+ Colors::normal(o);
+ }
+};
} // namespace wasm