diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-05-12 17:18:55 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-05-12 17:18:55 -0700 |
commit | f518f097c80c0659fbacf11fe12f89955093282b (patch) | |
tree | d26db91c5767989b3f824a0bbcf30a02259fb656 /src/parsing.h | |
parent | d84fd5be60d4ead6bc9fbb3f27a710bef0c688c8 (diff) | |
parent | c8293a3f9112ad486f6f3639fc5680d73e7559ca (diff) | |
download | binaryen-f518f097c80c0659fbacf11fe12f89955093282b.tar.gz binaryen-f518f097c80c0659fbacf11fe12f89955093282b.tar.bz2 binaryen-f518f097c80c0659fbacf11fe12f89955093282b.zip |
Merge pull request #488 from WebAssembly/error_reporting
Better error reporting
Diffstat (limited to 'src/parsing.h')
-rw-r--r-- | src/parsing.h | 27 |
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 |