#include "Replace.hpp"
#include "String.hpp"
-static CYExpression *ParseExpression(CYUTF8String code) {
+static CYExpression *ParseExpression(CYPool &pool, CYUTF8String code) {
std::stringstream stream;
stream << '(' << code << ')';
- CYDriver driver(stream);
+ CYDriver driver(pool, stream);
cy::parser parser(driver);
if (parser.parse() != 0 || !driver.errors_.empty())
CYLocalPool pool;
std::istringstream stream(line);
- CYDriver driver(stream);
+ CYDriver driver(pool, stream);
driver.auto_ = true;
std::string begin(prefix.str());
- driver.program_ = $ CYProgram($ CYExpress($C3(ParseExpression(
+ driver.program_ = $ CYProgram($ CYExpress($C3(ParseExpression(pool,
" function(object, prefix, word) {\n"
" var names = [];\n"
" var before = prefix.length;\n"
CYUTF8String json(run(pool, code));
// XXX: if this fails we should not try to parse it
- CYExpression *result(ParseExpression(json));
+ CYExpression *result(ParseExpression(pool, json));
if (result == NULL)
return NULL;
driver.strict_ = true;
}
-void Setup(CYPool &pool, CYOutput &out, CYDriver &driver, CYOptions &options, bool lower) {
+void Setup(CYOutput &out, CYDriver &driver, CYOptions &options, bool lower) {
out.pretty_ = pretty_;
if (lower)
- driver.Replace(pool, options);
+ driver.Replace(options);
}
static CYUTF8String Run(CYPool &pool, int client, CYUTF8String code) {
code = command_;
else {
std::istringstream stream(command_);
- CYDriver driver(stream);
- Setup(driver);
CYPool pool;
- bool failed(driver.Parse(pool));
+ CYDriver driver(pool, stream);
+ Setup(driver);
+
+ bool failed(driver.Parse());
if (failed || !driver.errors_.empty()) {
for (CYDriver::Errors::const_iterator error(driver.errors_.begin()); error != driver.errors_.end(); ++error) {
std::stringbuf str;
CYOutput out(str, options);
- Setup(pool, out, driver, options, lower);
+ Setup(out, driver, options, lower);
out << *driver.program_;
code = str.str();
}
_assert(!stream->fail());
}
- CYDriver driver(*stream, script);
+ CYPool pool;
+ CYDriver driver(pool, *stream, script);
Setup(driver);
- CYPool pool;
- bool failed(driver.Parse(pool));
+ bool failed(driver.Parse());
if (failed || !driver.errors_.empty()) {
for (CYDriver::Errors::const_iterator i(driver.errors_.begin()); i != driver.errors_.end(); ++i)
} else if (driver.program_ != NULL) {
std::stringbuf str;
CYOutput out(str, options);
- Setup(pool, out, driver, options, true);
+ Setup(out, driver, options, true);
out << *driver.program_;
std::string code(str.str());
if (compile)
return token; \
} while (false)
-#define A new($pool)
-#define Y $pool.strmemdup(yytext, yyleng)
+#define P yyextra->pool_
+#define A new(P)
+#define Y P.strmemdup(yytext, yyleng)
#define I(type, Type, value, highlight) do { \
yylval->type ## _ = A CY ## Type; \
#include "Driver.hpp"
#include "Parser.hpp"
#include "Stack.hpp"
-#define CYNew new($pool)
+#define CYNew new(driver.pool_)
@begin ObjectiveC
#include "ObjectiveC/Syntax.hpp"
#include "Cycript.tab.hh"
#include "Driver.hpp"
-CYDriver::CYDriver(std::istream &data, const std::string &filename) :
+CYDriver::CYDriver(CYPool &pool, std::istream &data, const std::string &filename) :
+ pool_(pool),
state_(CYClear),
data_(data),
debug_(0),
ScannerDestroy();
}
-bool CYDriver::Parse(CYPool &pool) {
- CYLocal<CYPool> local(&pool);
+bool CYDriver::Parse() {
+ CYLocal<CYPool> local(&pool_);
cy::parser parser(*this);
#ifdef YYDEBUG
parser.set_debug_level(debug_);
return parser.parse() != 0;
}
-void CYDriver::Replace(CYPool &pool, CYOptions &options) {
- CYLocal<CYPool> local(&pool);
+void CYDriver::Replace(CYOptions &options) {
+ CYLocal<CYPool> local(&pool_);
CYContext context(options);
program_->Replace(context);
}
class _visible CYDriver {
public:
+ CYPool &pool_;
void *scanner_;
CYState state_;
void ScannerDestroy();
public:
- CYDriver(std::istream &data, const std::string &filename = "");
+ CYDriver(CYPool &pool, std::istream &data, const std::string &filename = "");
~CYDriver();
- bool Parse(CYPool &pool);
- void Replace(CYPool &pool, CYOptions &options);
+ bool Parse();
+ void Replace(CYOptions &options);
Condition GetCondition();
void SetCondition(Condition condition);
};
_visible void CYLexerHighlight(const char *data, size_t size, std::ostream &output, bool ignore) {
+ CYLocalPool pool;
+
CYStream stream(data, data + size);
- CYDriver driver(stream);
+ CYDriver driver(pool, stream);
driver.commented_ = true;
size_t offset(0);
CYPosition current;
- CYLocalPool pool;
-
YYSTYPE value;
CYLocation location;
CYUTF8String CYPoolCode(CYPool &pool, std::istream &stream) {
CYLocalPool local;
- CYDriver driver(stream);
+ CYDriver driver(local, stream);
cy::parser parser(driver);
_assert(parser.parse() == 0);