]> git.localhorst.tv Git - l2e.git/blob - src/loader/Parser.h
added basic parser (not completely tested)
[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 <iosfwd>
15 #include <stdexcept>
16 #include <string>
17
18 namespace loader {
19
20 class Declaration;
21 class Definition;
22 class Literal;
23 class PropertyList;
24
25 class Parser {
26
27 public:
28         Parser(std::istream &in, ParsedSource &product) : tok(in), product(product) { }
29         ~Parser() { }
30 private:
31         Parser(const Parser &);
32         Parser &operator =(const Parser &);
33
34 public:
35         void Parse();
36
37 public:
38         class ParseError: public std::runtime_error {
39         public:
40                 explicit ParseError(const std::string &msg) : std::runtime_error(msg) { };
41         };
42
43 private:
44         void ParseStatement();
45         void ParseExportDirective();
46         void ParseIncludeDirective();
47
48         Declaration *ProbeDefinition();
49         Definition *ParseDefinition();
50
51         std::string ParseIdentifier();
52         std::string ParseTypeName();
53
54         Value *ParseValue();
55         PropertyList *ParsePropertyList();
56         Literal *ParseLiteral();
57         Literal *ParseArray();
58         Literal *ParseColor();
59         Literal *ParseVector();
60
61 private:
62         void AssertTokenType(Tokenizer::Token::Type actual, Tokenizer::Token::Type expected);
63         void AssertTokenType(Tokenizer::Token::Type actual, Tokenizer::Token::Type expected, const std::string &msg);
64         bool BeginningOfLiteral(const Tokenizer::Token &) const;
65         bool BeginOfPropertyList(const Tokenizer::Token &) const;
66
67 private:
68         Tokenizer tok;
69         ParsedSource &product;
70
71 };
72
73 }
74
75 #endif /* LOADER_PARSER_H_ */