#ifndef CYCRIPT_PARSER_HPP
#define CYCRIPT_PARSER_HPP
-#include <iostream>
-
+#include <streambuf>
#include <string>
#include <vector>
#include <map>
struct CYContext;
struct CYThing {
- virtual ~CYThing() {
- }
-
virtual void Output(struct CYOutput &out) const = 0;
};
struct CYOutput {
- std::ostream &out_;
+ std::streambuf &out_;
+ CYPosition position_;
+
CYOptions &options_;
bool pretty_;
unsigned indent_;
+ unsigned recent_;
bool right_;
enum {
Terminated
} mode_;
- CYOutput(std::ostream &out, CYOptions &options) :
+ CYOutput(std::streambuf &out, CYOptions &options) :
out_(out),
options_(options),
pretty_(false),
indent_(0),
+ recent_(0),
right_(false),
mode_(NoMode)
{
void Check(char value);
void Terminate();
+ _finline void operator ()(char value) {
+ _assert(out_.sputc(value) != EOF);
+ recent_ = indent_;
+ if (value == '\n')
+ position_.lines(1);
+ else
+ position_.columns(1);
+ }
+
+ _finline void operator ()(const char *data, std::streamsize size) {
+ _assert(out_.sputn(data, size) == size);
+ recent_ = indent_;
+ position_.columns(size);
+ }
+
+ _finline void operator ()(const char *data) {
+ return operator ()(data, strlen(data));
+ }
+
CYOutput &operator <<(char rhs);
CYOutput &operator <<(const char *rhs);
struct CYPropertyName {
virtual void PropertyName(CYOutput &out) const = 0;
-
- virtual ~CYPropertyName() {
- }
};
struct CYExpression;
return CYLeft(CYRight(flags));
}
+enum CYCompactType {
+ CYCompactNone,
+ CYCompactLong,
+ CYCompactShort,
+};
+
+#define CYCompact(type) \
+ virtual CYCompactType Compact() const { \
+ return CYCompact ## type; \
+ }
+
struct CYStatement :
CYNext<CYStatement>,
CYThing
{
- virtual ~CYStatement() {
- }
-
- void Single(CYOutput &out, CYFlags flags) const;
+ void Single(CYOutput &out, CYFlags flags, CYCompactType request) const;
void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const;
virtual void Output(CYOutput &out) const;
virtual CYStatement *Replace(CYContext &context) = 0;
+ virtual CYCompactType Compact() const = 0;
+ virtual CYStatement *Return();
+
private:
virtual void Output(CYOutput &out, CYFlags flags) const = 0;
};
};
struct CYClassName {
- virtual ~CYClassName() {
- }
-
virtual CYExpression *ClassName(CYContext &context, bool object) = 0;
virtual void ClassName(CYOutput &out, bool object) const = 0;
};
{
}
+ CYCompact(None)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ CYCompact(Short)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
- virtual ~CYContext() {
- }
-
void ReplaceAll(CYStatement *&statement) {
if (statement == NULL)
return;
{
}
+ CYCompact(Short)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
+
+ virtual CYStatement *Return();
};
struct CYForInitialiser {
- virtual ~CYForInitialiser() {
- }
-
virtual CYExpression *Replace(CYContext &context) = 0;
virtual void Output(CYOutput &out, CYFlags flags) const = 0;
};
struct CYForInInitialiser {
- virtual ~CYForInInitialiser() {
- }
-
virtual void ForIn(CYOutput &out, CYFlags flags) const = 0;
virtual CYStatement *ForEachIn(CYContext &out, CYExpression *value) = 0;
};
struct CYNull :
- CYWord,
CYTrivial
{
- CYNull() :
- CYWord("null")
- {
- }
-
virtual CYNumber *Number(CYContext &context);
virtual CYString *String(CYContext &context);
};
struct CYThis :
- CYWord,
CYMagic
{
- CYThis() :
- CYWord("this")
- {
- }
-
virtual CYExpression *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
};
struct CYFalse :
- CYWord,
CYBoolean
{
- CYFalse() :
- CYWord("false")
- {
- }
-
virtual bool Value() const {
return false;
}
};
struct CYTrue :
- CYWord,
CYBoolean
{
- CYTrue() :
- CYWord("true")
- {
- }
-
virtual bool Value() const {
return true;
}
void Output(CYOutput &out) const;
};
-struct CYBlank :
- public CYWord
-{
- CYBlank() :
- CYWord("")
- {
- }
-};
-
struct CYClause :
CYThing,
CYNext<CYClause>
{
}
+ CYCompact(None)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ CYCompact(Long)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ CYCompact(Long)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ CYCompact(Long)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ CYCompact(Long)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ CYCompact(Long)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
+
+ virtual CYStatement *Return();
};
struct CYDoWhile :
{
}
+ CYCompact(None)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ CYCompact(Long)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
CYStatement *code_;
CYNonLocal *nonlocal_;
+ bool implicit_;
CYThisScope this_;
CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *code) :
name_(name),
parameters_(parameters),
code_(code),
- nonlocal_(NULL)
+ nonlocal_(NULL),
+ implicit_(false)
{
}
- virtual ~CYFunction() {
- }
-
void Inject(CYContext &context);
virtual void Replace_(CYContext &context, bool outer);
virtual void Output(CYOutput &out, CYFlags flags) const;
{
}
+ CYCompact(None)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
throw;
}
+ CYCompact(None)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
+
+ virtual CYStatement *Return();
};
struct CYContinue :
{
}
+ CYCompact(Short)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ CYCompact(Short)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ CYCompact(None)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYEmpty :
CYStatement
{
+ CYCompact(Short)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ CYCompact(None)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ CYCompact(None)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ CYCompact(None)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ CYCompact(Short)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ CYCompact(None)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ CYCompact(Long)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ CYCompact(Long)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ CYCompact(None)
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};