*/
/* }}} */
+#include "cycript.hpp"
#include "Parser.hpp"
-#include <iomanip>
#include <sstream>
_finline CYFlags operator ~(CYFlags rhs) {
out << ')';
}
-void CYCatch::Output(CYOutput &out) const {
+namespace cy {
+namespace Syntax {
+
+void Catch::Output(CYOutput &out) const {
out << ' ' << "catch" << ' ' << '(' << *name_ << ')' << ' ' << code_;
}
+} }
+
void CYCompound::Output(CYOutput &out, CYFlags flags) const {
if (CYExpression *expression = expressions_)
if (CYExpression *next = expression->next_) {
}
void CYNumber::Output(CYOutput &out, CYFlags flags) const {
- char value[32];
- // XXX: I want this to print 1e3 rather than 1000
- sprintf(value, "%.17g", Value());
- out << value;
+ std::ostringstream str;
+ CYNumerify(str, Value());
+ out << str.str().c_str();
}
void CYNumber::PropertyName(CYOutput &out) const {
}
void CYString::Output(CYOutput &out, CYFlags flags) const {
- unsigned quot(0), apos(0);
- for (const char *value(value_), *end(value_ + size_); value != end; ++value)
- if (*value == '"')
- ++quot;
- else if (*value == '\'')
- ++apos;
-
- bool single(quot > apos);
-
std::ostringstream str;
-
- str << (single ? '\'' : '"');
- for (const char *value(value_), *end(value_ + size_); value != end; ++value)
- switch (*value) {
- case '\\': str << "\\\\"; break;
- case '\b': str << "\\b"; break;
- case '\f': str << "\\f"; break;
- case '\n': str << "\\n"; break;
- case '\r': str << "\\r"; break;
- case '\t': str << "\\t"; break;
- case '\v': str << "\\v"; break;
-
- case '"':
- if (!single)
- str << "\\\"";
- else goto simple;
- break;
-
- case '\'':
- if (single)
- str << "\\'";
- else goto simple;
- break;
-
- default:
- if (*value < 0x20 || *value >= 0x7f)
- str << "\\x" << std::setbase(16) << std::setw(2) << std::setfill('0') << unsigned(*value);
- else simple:
- str << *value;
- }
- str << (single ? '\'' : '"');
-
+ CYStringify(str, value_, size_);
out << str.str().c_str();
}
CYWord::Output(out);
}
-void CYThrow::Output(CYOutput &out, CYFlags flags) const {
+namespace cy {
+namespace Syntax {
+
+void Throw::Output(CYOutput &out, CYFlags flags) const {
out << "throw";
if (value_ != NULL)
out << ' ' << *value_;
out << ';';
}
-void CYTry::Output(CYOutput &out, CYFlags flags) const {
+void Try::Output(CYOutput &out, CYFlags flags) const {
out << "try" << ' ' << code_ << catch_ << finally_;
}
+} }
+
void CYVar::Output(CYOutput &out, CYFlags flags) const {
out << "var";
declarations_->Output(out, flags);