#include "String.hpp"
class CYStream :
- public std::istream
+ public std::streambuf
{
- private:
- class CYBuffer :
- public std::streambuf
- {
- public:
- CYBuffer(const char *start, const char *end) {
- setg(const_cast<char *>(start), const_cast<char *>(start), const_cast<char *>(end));
- }
- } buffer_;
-
public:
- CYStream(const char *start, const char *end) :
- std::istream(&buffer_),
- buffer_(start, end)
- {
+ CYStream(const char *start, const char *end) {
+ setg(const_cast<char *>(start), const_cast<char *>(start), const_cast<char *>(end));
}
};
-CYUTF8String CYPoolCode(CYPool &pool, std::istream &stream);
+CYUTF8String CYPoolCode(CYPool &pool, std::streambuf &stream);
#endif//CODE_HPP
static CYExpression *ParseExpression(CYPool &pool, CYUTF8String code) {
std::stringstream stream;
stream << '(' << code << ')';
- CYDriver driver(pool, stream);
+ CYDriver driver(pool, *stream.rdbuf());
if (driver.Parse() || !driver.errors_.empty())
return NULL;
_visible char **CYComplete(const char *word, const std::string &line, CYUTF8String (*run)(CYPool &pool, const std::string &)) {
CYLocalPool pool;
- std::istringstream stream(line);
+ std::stringbuf stream(line);
CYDriver driver(pool, stream);
driver.auto_ = true;
else {
std::string command(rl_line_buffer, rl_end);
command += '\n';
- std::istringstream stream(command);
+ std::stringbuf stream(command);
size_t last(std::string::npos);
for (size_t i(0); i != std::string::npos; i = command.find('\n', i + 1))
if (bypass)
code = command;
else try {
- std::istringstream stream(command);
+ std::stringbuf stream(command);
CYPool pool;
CYDriver driver(pool, stream);
stream = new std::istringstream(buffer.str());
CYPool pool;
- CYDriver driver(pool, *stream, script);
+ CYDriver driver(pool, *stream->rdbuf(), script);
Setup(driver);
uint64_t begin(CYGetTime());
}
CYPool pool;
- CYDriver driver(pool, *stream, script);
+ CYDriver driver(pool, *stream->rdbuf(), script);
Setup(driver);
bool failed(driver.Parse());
bool CYParser(CYPool &pool, bool debug);
-CYDriver::CYDriver(CYPool &pool, std::istream &data, const std::string &filename) :
+CYDriver::CYDriver(CYPool &pool, std::streambuf &data, const std::string &filename) :
pool_(pool),
newline_(false),
last_(false),
bool newline_;
bool last_;
- std::istream &data_;
+ std::streambuf &data_;
int debug_;
bool strict_;
void ScannerDestroy();
public:
- CYDriver(CYPool &pool, std::istream &data, const std::string &filename = "");
+ CYDriver(CYPool &pool, std::streambuf &data, const std::string &filename = "");
~CYDriver();
bool Parse(CYMark mark = CYMarkScript);
static JSValueRef Cycript_compile_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) { CYTry {
CYPool pool;
CYUTF8String before(CYPoolUTF8String(pool, context, CYJSString(context, arguments[0])));
- std::stringstream value(std::string(before.data, before.size));
+ std::stringbuf value(std::string(before.data, before.size));
CYUTF8String after(CYPoolCode(pool, value));
return CYCastJSValue(context, CYJSString(after));
} CYCatch_(NULL, "SyntaxError") }
std::stringstream wrap;
wrap << "(function (exports, require, module) { " << code << "\n});";
- code = CYPoolCode(pool, wrap);
+ code = CYPoolCode(pool, *wrap.rdbuf());
JSValueRef value(_jsccall(JSEvaluateScript, context, CYJSString(code), NULL, NULL, 0));
JSObjectRef function(CYCastJSObject(context, value));
return haystack.size >= needle.size && strncmp(haystack.data, needle.data, needle.size) == 0;
}
-CYUTF8String CYPoolCode(CYPool &pool, std::istream &stream) {
+CYUTF8String CYPoolCode(CYPool &pool, std::streambuf &stream) {
CYLocalPool local;
CYDriver driver(local, stream);
_assert(!driver.Parse());
I(type, Type(P.strmemdup(yyextra->buffer_.data(), yyextra->buffer_.size()), yyextra->buffer_.size()), value, highlight); \
} while (false)
-#define YY_INPUT(data, value, size) { \
- if (yyextra->data_.eof()) \
- value = YY_NULL; \
- else { \
- yyextra->data_.read(data, size); \
- size_t copy(yyextra->data_.gcount()); \
- value = copy == 0 ? YY_NULL : copy; \
- } \
-}
+#define YY_INPUT(data, value, size) do { \
+ value = yyextra->data_.sgetn(data, size) ?: YY_NULL; \
+} while (false)
%}