X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Floader%2FParser.h;h=fd8f2cfad52fd3d536fc1b013268d60e72de4f1d;hb=bcbb72013091db29a085d044f200c10d66b7c47a;hp=923a42439bdb828b99bb57bee2a7d19077708880;hpb=af9e0b57dac45dc5591f16fb34236b1356cda8a2;p=l2e.git diff --git a/src/loader/Parser.h b/src/loader/Parser.h index 923a424..fd8f2cf 100644 --- a/src/loader/Parser.h +++ b/src/loader/Parser.h @@ -11,6 +11,7 @@ #include "ParsedSource.h" #include "Tokenizer.h" +#include #include #include #include @@ -25,7 +26,7 @@ class PropertyList; class Parser { public: - Parser(std::istream &in, ParsedSource &product) : tok(in), product(product) { } + Parser(const std::string &file, ParsedSource &product); ~Parser() { } private: Parser(const Parser &); @@ -35,12 +36,20 @@ public: void Parse(); public: - class ParseError: public std::runtime_error { + class Error: public std::runtime_error { public: - explicit ParseError(const std::string &msg) : std::runtime_error(msg) { }; + Error(const std::string &file, int line, const std::string &msg) + : std::runtime_error(msg), file(file), line(line) { }; + ~Error() throw() { } + const std::string &File() const { return file; } + int Line() const { return line; } + private: + std::string file; + int line; }; private: + Tokenizer::Token GetToken(); void ParseStatement(); void ParseExportDirective(); void ParseIncludeDirective(); @@ -62,9 +71,13 @@ private: void AssertTokenType(Tokenizer::Token::Type actual, Tokenizer::Token::Type expected); void AssertTokenType(Tokenizer::Token::Type actual, Tokenizer::Token::Type expected, const std::string &msg); bool BeginningOfLiteral(const Tokenizer::Token &) const; + bool BeginningOfPrimitiveLiteral(const Tokenizer::Token &) const; bool BeginOfPropertyList(const Tokenizer::Token &) const; private: + std::string file; + std::string dirname; + std::ifstream in; Tokenizer tok; ParsedSource &product;