]>
Commit | Line | Data |
---|---|---|
b12a9965 | 1 | /* Cycript - Optimizing JavaScript Compiler/Runtime |
c1d3e52e | 2 | * Copyright (C) 2009-2015 Jay Freeman (saurik) |
b12a9965 JF |
3 | */ |
4 | ||
f95d2598 | 5 | /* GNU Affero General Public License, Version 3 {{{ */ |
b12a9965 | 6 | /* |
f95d2598 JF |
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 | |
b12a9965 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f95d2598 JF |
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/>. | |
b12a9965 JF |
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 | ||
58afc6aa | 31 | #include "Location.hpp" |
b12a9965 JF |
32 | #include "Parser.hpp" |
33 | ||
9d2b125d JF |
34 | enum CYMark { |
35 | CYMarkIgnore, | |
36 | CYMarkScript, | |
37 | CYMarkModule, | |
38 | }; | |
39 | ||
d9c91152 | 40 | class _visible CYDriver { |
b12a9965 | 41 | public: |
2c1d569a | 42 | CYPool &pool_; |
b12a9965 JF |
43 | void *scanner_; |
44 | ||
b900e1a4 JF |
45 | std::vector<char> buffer_; |
46 | bool tail_; | |
47 | ||
b12a9965 | 48 | std::stack<bool> in_; |
9d2b125d | 49 | std::stack<bool> return_; |
b900e1a4 | 50 | std::stack<bool> template_; |
9d2b125d | 51 | std::stack<bool> yield_; |
b12a9965 | 52 | |
a5662a53 JF |
53 | bool newline_; |
54 | bool last_; | |
442609f7 | 55 | bool next_; |
b12a9965 JF |
56 | |
57 | std::istream &data_; | |
9d2b125d | 58 | CYMark mark_; |
b12a9965 | 59 | |
d9c91152 | 60 | int debug_; |
b12a9965 | 61 | bool strict_; |
b900e1a4 | 62 | bool highlight_; |
b12a9965 JF |
63 | |
64 | enum Condition { | |
65 | RegExpCondition, | |
66 | XMLContentCondition, | |
67 | XMLTagCondition, | |
68 | }; | |
69 | ||
70 | std::string filename_; | |
71 | ||
72 | struct Error { | |
73 | bool warning_; | |
58afc6aa | 74 | CYLocation location_; |
b12a9965 JF |
75 | std::string message_; |
76 | }; | |
77 | ||
78 | typedef std::vector<Error> Errors; | |
79 | ||
a7d8b413 | 80 | CYScript *script_; |
b12a9965 JF |
81 | Errors errors_; |
82 | ||
83 | bool auto_; | |
84 | ||
85 | struct Context { | |
86 | CYExpression *context_; | |
87 | ||
88 | Context(CYExpression *context) : | |
89 | context_(context) | |
90 | { | |
91 | } | |
92 | ||
93 | typedef std::vector<CYWord *> Words; | |
94 | Words words_; | |
95 | }; | |
96 | ||
97 | typedef std::vector<Context> Contexts; | |
98 | Contexts contexts_; | |
99 | ||
100 | CYExpression *context_; | |
101 | ||
102 | enum Mode { | |
103 | AutoNone, | |
104 | AutoPrimary, | |
105 | AutoDirect, | |
106 | AutoIndirect, | |
107 | AutoMessage | |
108 | } mode_; | |
109 | ||
110 | private: | |
111 | void ScannerInit(); | |
112 | void ScannerDestroy(); | |
113 | ||
114 | public: | |
2c1d569a | 115 | CYDriver(CYPool &pool, std::istream &data, const std::string &filename = ""); |
b12a9965 JF |
116 | ~CYDriver(); |
117 | ||
9d2b125d | 118 | bool Parse(CYMark mark = CYMarkScript); |
2c1d569a | 119 | void Replace(CYOptions &options); |
d9c91152 | 120 | |
b12a9965 JF |
121 | void SetCondition(Condition condition); |
122 | ||
123 | void PushCondition(Condition condition); | |
124 | void PopCondition(); | |
125 | ||
58afc6aa | 126 | void Warning(const CYLocation &location, const char *message); |
b12a9965 JF |
127 | }; |
128 | ||
129 | #endif/*CYCRIPT_DRIVER_HPP*/ |