]> git.localhorst.tv Git - l2e.git/blobdiff - src/loader/Parser.h
use stable_sort for sorting inventory
[l2e.git] / src / loader / Parser.h
index 923a42439bdb828b99bb57bee2a7d19077708880..75cd5fec48740fe0bbf59638572dc7f3c852ee19 100644 (file)
@@ -1,31 +1,21 @@
-/*
- * Parser.h
- *
- *  Created on: Aug 26, 2012
- *      Author: holy
- */
-
 #ifndef LOADER_PARSER_H_
 #define LOADER_PARSER_H_
 
+#include "fwd.h"
 #include "ParsedSource.h"
 #include "Tokenizer.h"
 
+#include <fstream>
 #include <iosfwd>
 #include <stdexcept>
 #include <string>
 
 namespace loader {
 
-class Declaration;
-class Definition;
-class Literal;
-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 +25,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();
@@ -57,14 +55,20 @@ private:
        Literal *ParseArray();
        Literal *ParseColor();
        Literal *ParseVector();
+       Literal *ParseScript();
 
 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;
+       bool BeginningOfScriptLiteral(const Tokenizer::Token &) const;
 
 private:
+       std::string file;
+       std::string dirname;
+       std::ifstream in;
        Tokenizer tok;
        ParsedSource &product;