]> git.saurik.com Git - cycript.git/blob - Driver.hpp
The grammar and lexer should not share a filename.
[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 CYExpression;
37 struct CYScript;
38 struct CYWord;
39
40 enum CYMark {
41 CYMarkIgnore,
42 CYMarkScript,
43 CYMarkModule,
44 };
45
46 class _visible CYDriver {
47 public:
48 CYPool &pool_;
49 void *scanner_;
50
51 std::vector<char> buffer_;
52 bool tail_;
53
54 std::stack<bool> in_;
55 std::stack<bool> return_;
56 std::stack<bool> template_;
57 std::stack<bool> yield_;
58
59 bool newline_;
60 bool last_;
61 bool next_;
62
63 std::istream &data_;
64 CYMark mark_;
65
66 int debug_;
67 bool strict_;
68 bool highlight_;
69
70 enum Condition {
71 RegExpCondition,
72 XMLContentCondition,
73 XMLTagCondition,
74 };
75
76 std::string filename_;
77
78 struct Error {
79 bool warning_;
80 CYLocation location_;
81 std::string message_;
82 };
83
84 typedef std::vector<Error> Errors;
85
86 CYScript *script_;
87 Errors errors_;
88
89 bool auto_;
90
91 struct Context {
92 CYExpression *context_;
93
94 Context(CYExpression *context) :
95 context_(context)
96 {
97 }
98
99 typedef std::vector<CYWord *> Words;
100 Words words_;
101 };
102
103 typedef std::vector<Context> Contexts;
104 Contexts contexts_;
105
106 CYExpression *context_;
107
108 enum Mode {
109 AutoNone,
110 AutoPrimary,
111 AutoDirect,
112 AutoIndirect,
113 AutoMessage
114 } mode_;
115
116 private:
117 void ScannerInit();
118 void ScannerDestroy();
119
120 public:
121 CYDriver(CYPool &pool, std::istream &data, const std::string &filename = "");
122 ~CYDriver();
123
124 bool Parse(CYMark mark = CYMarkScript);
125 void Replace(CYOptions &options);
126
127 void SetCondition(Condition condition);
128
129 void PushCondition(Condition condition);
130 void PopCondition();
131
132 void Warning(const CYLocation &location, const char *message);
133 };
134
135 #endif/*CYCRIPT_DRIVER_HPP*/