virtual void PropertyName(CYOutput &out) const = 0;
};
+struct CYExpression;
+
+enum CYNeeded {
+ CYNever = -1,
+ CYSometimes = 0,
+ CYAlways = 1,
+};
+
+enum CYFlags {
+ CYNoFlags = 0,
+ CYNoBrace = (1 << 0),
+ CYNoFunction = (1 << 1),
+ CYNoIn = (1 << 2),
+ CYNoCall = (1 << 3),
+ CYNoRightHand = (1 << 4),
+ CYNoDangle = (1 << 5),
+ CYNoBF = (CYNoBrace | CYNoFunction),
+};
+
+struct CYContext {
+ apr_pool_t *pool_;
+
+ CYContext(apr_pool_t *pool) :
+ pool_(pool)
+ {
+ }
+
+ template <typename Type_>
+ void Replace(Type_ *&value) {
+ if (value != NULL)
+ while (Type_ *replace = value->Replace(*this))
+ value = replace;
+ }
+};
+
+struct CYStatement :
+ CYNext<CYStatement>
+{
+ void Single(CYOutput &out, CYFlags flags) const;
+ void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const;
+
+ CYStatement *ReplaceAll(CYContext &context);
+
+ virtual CYStatement *Replace(CYContext &context) = 0;
+
+ private:
+ virtual void Output(CYOutput &out, CYFlags flags) const = 0;
+};
+
+struct CYStatements {
+ CYStatement *first_;
+ CYStatement *last_;
+
+ CYStatements() :
+ first_(NULL),
+ last_(NULL)
+ {
+ }
+
+ operator CYStatement *() const {
+ return first_;
+ }
+
+ CYStatements &operator ->*(CYStatement *next) {
+ if (next != NULL)
+ if (first_ == NULL) {
+ first_ = next;
+ last_ = next;
+ } else for (;; last_ = last_->next_)
+ if (last_->next_ == NULL) {
+ last_->next_ = next;
+ last_ = next;
+ break;
+ }
+ return *this;
+ }
+};
+
struct CYClassName {
+ virtual CYExpression *ClassName(CYContext &context, bool object) = 0;
virtual void ClassName(CYOutput &out, bool object) const = 0;
};
virtual void Output(CYOutput &out) const;
+ virtual CYExpression *ClassName(CYContext &context, bool object);
virtual void ClassName(CYOutput &out, bool object) const;
virtual void PropertyName(CYOutput &out) const;
};
};
struct CYLabel :
- CYNext<CYLabel>
+ CYStatement
{
CYIdentifier *name_;
+ CYStatement *statement_;
- CYLabel(CYIdentifier *name, CYLabel *next) :
- CYNext<CYLabel>(next),
- name_(name)
+ CYLabel(CYIdentifier *name, CYStatement *statement) :
+ name_(name),
+ statement_(statement)
{
}
-};
-
-enum CYNeeded {
- CYNever = -1,
- CYSometimes = 0,
- CYAlways = 1,
-};
-enum CYFlags {
- CYNoFlags = 0,
- CYNoBrace = (1 << 0),
- CYNoFunction = (1 << 1),
- CYNoIn = (1 << 2),
- CYNoCall = (1 << 3),
- CYNoRightHand = (1 << 4),
- CYNoDangle = (1 << 5),
- CYNoBF = (CYNoBrace | CYNoFunction),
+ virtual CYStatement *Replace(CYContext &context);
+ virtual void Output(CYOutput &out, CYFlags flags) const;
};
-struct CYStatement :
- CYNext<CYStatement>
+struct CYProgram :
+ CYThing
{
- CYLabel *labels_;
+ CYStatement *statements_;
- CYStatement() :
- labels_(NULL)
+ CYProgram(CYStatement *statements) :
+ statements_(statements)
{
}
- void AddLabel(CYIdentifier *identifier) {
- labels_ = new CYLabel(identifier, labels_);
- }
-
- bool Single(CYOutput &out, CYFlags flags) const;
- void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const;
+ virtual void Replace(CYContext &context);
- private:
- virtual void Output(CYOutput &out, CYFlags flags) const = 0;
+ virtual void Output(CYOutput &out) const;
};
struct CYBlock :
- CYStatement
+ CYStatement,
+ CYThing
{
CYStatement *statements_;
{
}
+ virtual CYStatement *Replace(CYContext &context);
+
+ virtual void Output(CYOutput &out) const;
virtual void Output(CYOutput &out, CYFlags flags) const;
};
typedef std::vector<Error> Errors;
- CYStatement *program_;
+ CYProgram *program_;
Errors errors_;
private:
virtual void ForIn(CYOutput &out, CYFlags flags) const = 0;
virtual const char *ForEachIn() const = 0;
virtual void ForEachIn(CYOutput &out) const = 0;
+ virtual CYExpression *ForEachIn(CYContext &out) = 0;
};
struct CYExpression :
virtual const char *ForEachIn() const;
virtual void ForEachIn(CYOutput &out) const;
+ virtual CYExpression *ForEachIn(CYContext &out);
virtual void Output(CYOutput &out) const;
virtual void Output(CYOutput &out, CYFlags flags) const = 0;
void Output(CYOutput &out, unsigned precedence, CYFlags flags) const;
+ virtual CYExpression *ClassName(CYContext &context, bool object);
virtual void ClassName(CYOutput &out, bool object) const;
+ CYExpression *ReplaceAll(CYContext &context);
+
+ virtual CYExpression *Replace(CYContext &context) = 0;
+
virtual const char *Word() const {
return NULL;
}
CYPrecedence(17)
+ virtual CYExpression *Replace(CYContext &context);
void Output(CYOutput &out, CYFlags flags) const;
};
+struct CYFunctionParameter :
+ CYNext<CYFunctionParameter>,
+ CYThing
+{
+ CYIdentifier *name_;
+
+ CYFunctionParameter(CYIdentifier *name, CYFunctionParameter *next = NULL) :
+ CYNext<CYFunctionParameter>(next),
+ name_(name)
+ {
+ }
+
+ virtual void Output(CYOutput &out) const;
+};
+
struct CYComprehension :
CYNext<CYComprehension>,
CYThing
virtual void End_(CYOutput &out) const {
}
+
+ virtual CYFunctionParameter *Parameter(CYContext &context) const = 0;
+ CYFunctionParameter *Parameters(CYContext &context) const;
+ virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
};
struct CYForInComprehension :
}
virtual void Begin_(CYOutput &out) const;
+
+ virtual CYFunctionParameter *Parameter(CYContext &context) const;
+ virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
};
struct CYForEachInComprehension :
virtual void Begin_(CYOutput &out) const;
virtual void End_(CYOutput &out) const;
+
+ virtual CYFunctionParameter *Parameter(CYContext &context) const;
+ virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
};
struct CYIfComprehension :
}
virtual void Begin_(CYOutput &out) const;
+
+ virtual CYFunctionParameter *Parameter(CYContext &context) const;
+ virtual CYStatement *Replace(CYContext &context, CYStatement *statement) const;
};
struct CYArrayComprehension :
CYPrecedence(0)
+ virtual CYExpression *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
CYRightHand(false)
};
+struct CYTrivial :
+ CYLiteral
+{
+ virtual CYExpression *Replace(CYContext &context);
+};
+
struct CYMagic :
CYExpression
{
CYRightHand(false)
};
-struct CYSelectorPart :
- CYNext<CYSelectorPart>,
- CYThing
-{
- CYWord *name_;
- bool value_;
-
- CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next) :
- CYNext<CYSelectorPart>(next),
- name_(name),
- value_(value)
- {
- }
-
- virtual void Output(CYOutput &out) const;
-};
-
-struct CYSelector :
- CYLiteral
-{
- CYSelectorPart *name_;
-
- CYSelector(CYSelectorPart *name) :
- name_(name)
- {
- }
-
- CYPrecedence(1)
-
- virtual void Output(CYOutput &out, CYFlags flags) const;
-};
-
struct CYRange {
uint64_t lo_;
uint64_t hi_;
extern CYRange WordEndRange_;
struct CYString :
- CYLiteral,
+ CYTrivial,
CYPropertyName
{
const char *value_;
size_t size_;
+ CYString() :
+ value_(NULL),
+ size_(0)
+ {
+ }
+
+ CYString(const char *value) :
+ value_(value),
+ size_(strlen(value))
+ {
+ }
+
CYString(const char *value, size_t size) :
value_(value),
size_(size)
{
}
- CYString(const CYIdentifier *identifier) :
- value_(identifier->Value()),
+ CYString(const CYWord *word) :
+ value_(word->Value()),
size_(strlen(value_))
{
}
virtual void PropertyName(CYOutput &out) const;
};
+struct CYSelectorPart :
+ CYNext<CYSelectorPart>,
+ CYThing
+{
+ CYWord *name_;
+ bool value_;
+
+ CYSelectorPart(CYWord *name, bool value, CYSelectorPart *next) :
+ CYNext<CYSelectorPart>(next),
+ name_(name),
+ value_(value)
+ {
+ }
+
+ CYString *Replace(CYContext &context);
+ virtual void Output(CYOutput &out) const;
+};
+
+struct CYSelector :
+ CYLiteral
+{
+ CYSelectorPart *name_;
+
+ CYSelector(CYSelectorPart *name) :
+ name_(name)
+ {
+ }
+
+ CYPrecedence(1)
+
+ virtual CYExpression *Replace(CYContext &context);
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
struct CYNumber :
- CYLiteral,
+ CYTrivial,
CYPropertyName
{
double value_;
};
struct CYRegEx :
- CYLiteral
+ CYTrivial
{
const char *value_;
struct CYNull :
CYWord,
- CYLiteral
+ CYTrivial
{
CYNull() :
CYWord("null")
{
}
+ virtual CYExpression *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYBoolean :
- CYLiteral
+ CYTrivial
{
virtual bool Value() const = 0;
virtual void Output(CYOutput &out, CYFlags flags) const;
CYPrecedence(0)
CYRightHand(false)
+ virtual CYExpression *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
virtual bool Alphabetic() const = 0;
virtual const char *Operator() const = 0;
+ CYPrecedence(4)
+
+ virtual CYExpression *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
virtual bool Alphabetic() const = 0;
virtual const char *Operator() const = 0;
+ virtual CYExpression *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
virtual const char *Operator() const = 0;
+ CYPrecedence(3)
+
+ virtual CYExpression *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
virtual const char *Operator() const = 0;
+ virtual CYExpression *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
CYWord *name_;
CYExpression *value_;
+ CYArgument(CYExpression *value, CYArgument *next = NULL) :
+ CYNext<CYArgument>(next),
+ name_(NULL),
+ value_(value)
+ {
+ }
+
CYArgument(CYWord *name, CYExpression *value, CYArgument *next = NULL) :
CYNext<CYArgument>(next),
name_(name),
{
}
+ void Replace(CYContext &context);
void Output(CYOutput &out) const;
};
CYNext<CYClause>
{
CYExpression *case_;
- CYStatement *code_;
+ CYStatement *statements_;
- CYClause(CYExpression *_case, CYStatement *code) :
+ CYClause(CYExpression *_case, CYStatement *statements) :
case_(_case),
- code_(code)
+ statements_(statements)
{
}
+ virtual void Replace(CYContext &context);
virtual void Output(CYOutput &out) const;
};
{
}
+ void Replace(CYContext &context);
void Output(CYOutput &out) const;
};
{
CYElement *elements_;
- CYArray(CYElement *elements) :
+ CYArray(CYElement *elements = NULL) :
elements_(elements)
{
}
+ virtual CYExpression *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
virtual const char *ForEachIn() const;
virtual void ForEachIn(CYOutput &out) const;
+ virtual CYExpression *ForEachIn(CYContext &out);
+
+ void Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
virtual void For(CYOutput &out) const;
+ void Replace(CYContext &context);
+
virtual void Output(CYOutput &out) const;
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
CYStatement
{
CYDeclarations *declarations_;
- CYStatement *statements_;
+ CYBlock code_;
CYLet(CYDeclarations *declarations, CYStatement *statements) :
declarations_(declarations),
- statements_(statements)
+ code_(statements)
{
}
+ virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYField :
CYNext<CYField>
{
- virtual void Output(CYOutput &out) const;
+ CYStatement *Replace(CYContext &context) const;
+ void Output(CYOutput &out) const;
};
struct CYMessageParameter :
name_(name)
{
}
+
+ CYFunctionParameter *Parameters(CYContext &context) const;
+ CYSelector *Selector(CYContext &context) const;
+ CYSelectorPart *SelectorPart(CYContext &context) const;
};
struct CYMessage :
{
bool instance_;
CYExpression *type_;
- CYMessageParameter *parameter_;
- CYStatement *body_;
+ CYMessageParameter *parameters_;
+ CYStatement *statements_;
- CYMessage(bool instance, CYExpression *type, CYMessageParameter *parameter, CYStatement *body) :
+ CYMessage(bool instance, CYExpression *type, CYMessageParameter *parameter, CYStatement *statements) :
instance_(instance),
type_(type),
- parameter_(parameter),
- body_(body)
+ parameters_(parameter),
+ statements_(statements)
{
}
- virtual void Output(CYOutput &out, bool replace) const;
+ CYStatement *Replace(CYContext &context, bool replace) const;
+ void Output(CYOutput &out, bool replace) const;
};
struct CYClass {
{
}
+ CYExpression *Replace_(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
CYPrecedence(0)
+ virtual CYExpression *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
-struct CYFunctionParameter :
- CYNext<CYFunctionParameter>,
- CYThing
-{
- CYIdentifier *name_;
-
- CYFunctionParameter(CYIdentifier *name, CYFunctionParameter *next) :
- CYNext<CYFunctionParameter>(next),
- name_(name)
- {
- }
-
- virtual void Output(CYOutput &out) const;
-};
-
struct CYFor :
CYStatement
{
{
}
+ virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
CYPropertyName *name_;
CYExpression *value_;
- CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next) :
+ CYProperty(CYPropertyName *name, CYExpression *value, CYProperty *next = NULL) :
CYNext<CYProperty>(next),
name_(name),
value_(value)
{
}
+ void Replace(CYContext &context);
virtual void Output(CYOutput &out) const;
};
struct CYObject :
CYLiteral
{
- CYProperty *property_;
+ CYProperty *properties_;
- CYObject(CYProperty *property) :
- property_(property)
+ CYObject(CYProperty *properties) :
+ properties_(properties)
{
}
+ virtual CYExpression *Replace(CYContext &context);
void Output(CYOutput &out, CYFlags flags) const;
};
CYThing
{
CYIdentifier *name_;
- CYStatement *code_;
+ CYBlock code_;
- CYCatch(CYIdentifier *name, CYStatement *code) :
+ CYCatch(CYIdentifier *name, CYStatement *statements) :
name_(name),
- code_(code)
+ code_(statements)
{
}
+ void Replace(CYContext &context);
virtual void Output(CYOutput &out) const;
};
CYPrecedence(0)
+ virtual CYExpression *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
void SetLeft(CYExpression *object) {
object_ = object;
}
+
+ void Replace_(CYContext &context);
};
struct CYDirectMember :
CYPrecedence(1)
CYRightHand(false)
+ virtual CYExpression *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
CYPrecedence(1)
CYRightHand(false)
+ virtual CYExpression *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
CYRightHand(false)
+ virtual CYExpression *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
CYExpression *function_;
CYArgument *arguments_;
- CYCall(CYExpression *function, CYArgument *arguments) :
+ CYCall(CYExpression *function, CYArgument *arguments = NULL) :
function_(function),
arguments_(arguments)
{
CYPrecedence(1)
CYRightHand(false)
+ virtual CYExpression *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
CYStatement *true_;
CYStatement *false_;
- CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false) :
+ CYIf(CYExpression *test, CYStatement *_true, CYStatement *_false = NULL) :
test_(test),
true_(_true),
false_(_false)
{
}
+ virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYFunction {
CYIdentifier *name_;
CYFunctionParameter *parameters_;
- CYStatement *body_;
+ CYBlock code_;
- CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *body) :
+ CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
name_(name),
parameters_(parameters),
- body_(body)
+ code_(statements)
{
}
+ virtual void Replace_(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
CYFunction,
CYExpression
{
- CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *body) :
- CYFunction(name, parameters, body)
+ CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
+ CYFunction(name, parameters, statements)
{
}
CYPrecedence(0)
CYRightHand(false)
+ virtual CYExpression *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
CYFunction,
CYStatement
{
- CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *body) :
- CYFunction(name, parameters, body)
+ CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *statements) :
+ CYFunction(name, parameters, statements)
{
}
+ virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYEmpty :
CYStatement
{
+ virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYFinally :
CYThing
{
- CYStatement *code_;
+ CYBlock code_;
- CYFinally(CYStatement *code) :
- code_(code)
+ CYFinally(CYStatement *statements) :
+ code_(statements)
{
}
+ void Replace(CYContext &context);
virtual void Output(CYOutput &out) const;
};
struct CYTry :
CYStatement
{
- CYStatement *code_;
+ CYBlock code_;
CYCatch *catch_;
CYFinally *finally_;
- CYTry(CYStatement *code, CYCatch *_catch, CYFinally *finally) :
- code_(code),
+ CYTry(CYStatement *statements, CYCatch *_catch, CYFinally *finally) :
+ code_(statements),
catch_(_catch),
finally_(finally)
{
}
+ virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
+ virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
CYPrecedence(15)
+ virtual CYExpression *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};
}
CYAlphabetic(false)
- CYPrecedence(2)
- virtual void Output(CYOutput &out, CYFlags flags) const;
+ virtual CYExpression *Replace(CYContext &context);
};
struct CYIndirect :
}
CYAlphabetic(false)
- CYPrecedence(1)
- virtual void Output(CYOutput &out, CYFlags flags) const;
+ virtual CYExpression *Replace(CYContext &context);
};
#define CYPostfix_(op, name) \
CYPostfix(lhs) \
{ \
} \
- \
- CYPrecedence(3) \
\
virtual const char *Operator() const { \
return op; \
} \
\
CYAlphabetic(alphabetic) \
- CYPrecedence(4) \
\
virtual const char *Operator() const { \
return op; \