]> git.saurik.com Git - cycript.git/blame - Driver.hpp
Avoid crashing when the user types a mismatched }.
[cycript.git] / Driver.hpp
CommitLineData
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"
8a392978
JF
32#include "Options.hpp"
33#include "Pooling.hpp"
34#include "Standard.hpp"
35
36struct CYExpression;
37struct CYScript;
38struct CYWord;
b12a9965 39
9d2b125d
JF
40enum CYMark {
41 CYMarkIgnore,
42 CYMarkScript,
43 CYMarkModule,
44};
45
d9c91152 46class _visible CYDriver {
b12a9965 47 public:
2c1d569a 48 CYPool &pool_;
b12a9965
JF
49 void *scanner_;
50
b900e1a4
JF
51 std::vector<char> buffer_;
52 bool tail_;
53
b12a9965 54 std::stack<bool> in_;
9d2b125d 55 std::stack<bool> return_;
b900e1a4 56 std::stack<bool> template_;
9d2b125d 57 std::stack<bool> yield_;
b12a9965 58
a5662a53
JF
59 bool newline_;
60 bool last_;
442609f7 61 bool next_;
b12a9965
JF
62
63 std::istream &data_;
9d2b125d 64 CYMark mark_;
b12a9965 65
d9c91152 66 int debug_;
b12a9965 67 bool strict_;
b900e1a4 68 bool highlight_;
b12a9965
JF
69
70 enum Condition {
71 RegExpCondition,
72 XMLContentCondition,
73 XMLTagCondition,
74 };
75
76 std::string filename_;
77
78 struct Error {
79 bool warning_;
58afc6aa 80 CYLocation location_;
b12a9965
JF
81 std::string message_;
82 };
83
84 typedef std::vector<Error> Errors;
85
a7d8b413 86 CYScript *script_;
b12a9965
JF
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:
2c1d569a 121 CYDriver(CYPool &pool, std::istream &data, const std::string &filename = "");
b12a9965
JF
122 ~CYDriver();
123
9d2b125d 124 bool Parse(CYMark mark = CYMarkScript);
2c1d569a 125 void Replace(CYOptions &options);
d9c91152 126
b12a9965
JF
127 void SetCondition(Condition condition);
128
129 void PushCondition(Condition condition);
130 void PopCondition();
131
58afc6aa 132 void Warning(const CYLocation &location, const char *message);
b12a9965
JF
133};
134
135#endif/*CYCRIPT_DRIVER_HPP*/