]> git.saurik.com Git - cycript.git/blame - Driver.hpp
Massive changes to lexer to get template literals.
[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"
b12a9965
JF
32#include "Parser.hpp"
33
d9c91152 34class _visible CYDriver {
b12a9965 35 public:
2c1d569a 36 CYPool &pool_;
b12a9965
JF
37 void *scanner_;
38
b900e1a4
JF
39 std::vector<char> buffer_;
40 bool tail_;
41
b12a9965 42 std::stack<bool> in_;
b900e1a4 43 std::stack<bool> template_;
b12a9965 44
a5662a53
JF
45 bool newline_;
46 bool last_;
47
b12a9965
JF
48 struct {
49 bool AtImplementation;
a7d8b413 50 bool Class;
b12a9965
JF
51 bool Function;
52 bool OpenBrace;
a5662a53 53 bool NewLine;
b12a9965
JF
54 } no_;
55
56 std::istream &data_;
57
d9c91152 58 int debug_;
b12a9965 59 bool strict_;
b900e1a4 60 bool highlight_;
b12a9965
JF
61
62 enum Condition {
63 RegExpCondition,
64 XMLContentCondition,
65 XMLTagCondition,
66 };
67
68 std::string filename_;
69
70 struct Error {
71 bool warning_;
58afc6aa 72 CYLocation location_;
b12a9965
JF
73 std::string message_;
74 };
75
76 typedef std::vector<Error> Errors;
77
a7d8b413 78 CYScript *script_;
b12a9965
JF
79 Errors errors_;
80
81 bool auto_;
82
83 struct Context {
84 CYExpression *context_;
85
86 Context(CYExpression *context) :
87 context_(context)
88 {
89 }
90
91 typedef std::vector<CYWord *> Words;
92 Words words_;
93 };
94
95 typedef std::vector<Context> Contexts;
96 Contexts contexts_;
97
98 CYExpression *context_;
99
100 enum Mode {
101 AutoNone,
102 AutoPrimary,
103 AutoDirect,
104 AutoIndirect,
105 AutoMessage
106 } mode_;
107
108 private:
109 void ScannerInit();
110 void ScannerDestroy();
111
112 public:
2c1d569a 113 CYDriver(CYPool &pool, std::istream &data, const std::string &filename = "");
b12a9965
JF
114 ~CYDriver();
115
2c1d569a
JF
116 bool Parse();
117 void Replace(CYOptions &options);
d9c91152 118
b12a9965
JF
119 void SetCondition(Condition condition);
120
121 void PushCondition(Condition condition);
122 void PopCondition();
123
58afc6aa 124 void Warning(const CYLocation &location, const char *message);
b12a9965
JF
125};
126
127#endif/*CYCRIPT_DRIVER_HPP*/