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