]> git.saurik.com Git - cycript.git/blob - Driver.hpp
Move non-RegEx lexer hacks from Scanner to Parser.
[cycript.git] / Driver.hpp
1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2015 Jay Freeman (saurik)
3 */
4
5 /* GNU Affero General Public License, Version 3 {{{ */
6 /*
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20 /* }}} */
21
22 #ifndef CYCRIPT_DRIVER_HPP
23 #define CYCRIPT_DRIVER_HPP
24
25 #include <iostream>
26
27 #include <stack>
28 #include <string>
29 #include <vector>
30
31 #include "Location.hpp"
32 #include "Options.hpp"
33 #include "Pooling.hpp"
34 #include "Standard.hpp"
35
36 struct CYClassTail;
37 struct CYExpression;
38 struct CYScript;
39 struct CYWord;
40
41 enum CYMark {
42 CYMarkIgnore,
43 CYMarkScript,
44 CYMarkModule,
45 };
46
47 class _visible CYDriver {
48 public:
49 CYPool &pool_;
50 void *scanner_;
51
52 std::vector<char> buffer_;
53 bool tail_;
54
55 std::stack<bool> in_;
56 std::stack<bool> return_;
57 std::stack<bool> super_;
58 std::stack<bool> template_;
59 std::stack<bool> yield_;
60
61 std::stack<CYClassTail *> class_;
62
63 enum {
64 NewLineNone,
65 NewLineLast,
66 NewLineHere,
67 } newline_;
68
69 bool last_;
70 bool next_;
71
72 std::istream &data_;
73 CYMark mark_;
74
75 int debug_;
76 bool strict_;
77 bool highlight_;
78
79 enum Condition {
80 XMLContentCondition,
81 XMLTagCondition,
82 };
83
84 std::string filename_;
85
86 struct Error {
87 bool warning_;
88 CYLocation location_;
89 std::string message_;
90 };
91
92 typedef std::vector<Error> Errors;
93
94 CYScript *script_;
95 Errors errors_;
96
97 bool auto_;
98
99 struct Context {
100 CYExpression *context_;
101
102 Context(CYExpression *context) :
103 context_(context)
104 {
105 }
106
107 typedef std::vector<CYWord *> Words;
108 Words words_;
109 };
110
111 typedef std::vector<Context> Contexts;
112 Contexts contexts_;
113
114 CYExpression *context_;
115
116 enum Mode {
117 AutoNone,
118 AutoPrimary,
119 AutoDirect,
120 AutoIndirect,
121 AutoMessage
122 } mode_;
123
124 private:
125 void ScannerInit();
126 void ScannerDestroy();
127
128 public:
129 CYDriver(CYPool &pool, std::istream &data, const std::string &filename = "");
130 ~CYDriver();
131
132 bool Parse(CYMark mark = CYMarkScript);
133 void Replace(CYOptions &options);
134
135 void SetRegEx(bool equal);
136 void SetCondition(Condition condition);
137
138 void PushCondition(Condition condition);
139 void PopCondition();
140
141 void Warning(const CYLocation &location, const char *message);
142 };
143
144 #endif/*CYCRIPT_DRIVER_HPP*/