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