]> git.localhorst.tv Git - l2e.git/blob - src/loader/Parser.h
resolve inclusion path name 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 std::string &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 std::string &file, int line, const std::string &msg)
42                 : std::runtime_error(msg), file(file), line(line) { };
43                 ~Error() throw() { }
44                 const std::string &File() const { return file; }
45                 int Line() const { return line; }
46         private:
47                 std::string file;
48                 int line;
49         };
50
51 private:
52         Tokenizer::Token GetToken();
53         void ParseStatement();
54         void ParseExportDirective();
55         void ParseIncludeDirective();
56
57         Declaration *ProbeDefinition();
58         Definition *ParseDefinition();
59
60         std::string ParseIdentifier();
61         std::string ParseTypeName();
62
63         Value *ParseValue();
64         PropertyList *ParsePropertyList();
65         Literal *ParseLiteral();
66         Literal *ParseArray();
67         Literal *ParseColor();
68         Literal *ParseVector();
69
70 private:
71         void AssertTokenType(Tokenizer::Token::Type actual, Tokenizer::Token::Type expected);
72         void AssertTokenType(Tokenizer::Token::Type actual, Tokenizer::Token::Type expected, const std::string &msg);
73         bool BeginningOfLiteral(const Tokenizer::Token &) const;
74         bool BeginOfPropertyList(const Tokenizer::Token &) const;
75
76 private:
77         std::string file;
78         std::string dirname;
79         std::ifstream in;
80         Tokenizer tok;
81         ParsedSource &product;
82
83 };
84
85 }
86
87 #endif /* LOADER_PARSER_H_ */