]> git.localhorst.tv Git - l2e.git/blob - src/loader/Parser.h
added error message for unreadable files in Parser
[l2e.git] / src / loader / Parser.h
1 /*
2  * Parser.h
3  *
4  *  Created on: Aug 26, 2012
5  *      Author: holy
6  */
7
8 #ifndef LOADER_PARSER_H_
9 #define LOADER_PARSER_H_
10
11 #include "ParsedSource.h"
12 #include "Tokenizer.h"
13
14 #include <fstream>
15 #include <iosfwd>
16 #include <stdexcept>
17 #include <string>
18
19 namespace loader {
20
21 class Declaration;
22 class Definition;
23 class Literal;
24 class PropertyList;
25
26 class Parser {
27
28 public:
29         Parser(const char *file, ParsedSource &product);
30         ~Parser() { }
31 private:
32         Parser(const Parser &);
33         Parser &operator =(const Parser &);
34
35 public:
36         void Parse();
37
38 public:
39         class Error: public std::runtime_error {
40         public:
41                 Error(const char *file, int line, const std::string &msg)
42                 : std::runtime_error(msg), file(file), line(line) { };
43                 const char *File() const { return file; }
44                 int Line() const { return line; }
45         private:
46                 const char *file;
47                 int line;
48         };
49
50 private:
51         Tokenizer::Token GetToken();
52         void ParseStatement();
53         void ParseExportDirective();
54         void ParseIncludeDirective();
55
56         Declaration *ProbeDefinition();
57         Definition *ParseDefinition();
58
59         std::string ParseIdentifier();
60         std::string ParseTypeName();
61
62         Value *ParseValue();
63         PropertyList *ParsePropertyList();
64         Literal *ParseLiteral();
65         Literal *ParseArray();
66         Literal *ParseColor();
67         Literal *ParseVector();
68
69 private:
70         void AssertTokenType(Tokenizer::Token::Type actual, Tokenizer::Token::Type expected);
71         void AssertTokenType(Tokenizer::Token::Type actual, Tokenizer::Token::Type expected, const std::string &msg);
72         bool BeginningOfLiteral(const Tokenizer::Token &) const;
73         bool BeginOfPropertyList(const Tokenizer::Token &) const;
74
75 private:
76         const char *file;
77         std::ifstream in;
78         Tokenizer tok;
79         ParsedSource &product;
80
81 };
82
83 }
84
85 #endif /* LOADER_PARSER_H_ */