struct CYOutput {
std::ostream &out_;
+ bool pretty_;
+ unsigned indent_;
+
+ enum {
+ NoMode,
+ NoLetter,
+ NoPlus,
+ NoHyphen,
+ Terminated
+ } mode_;
CYOutput(std::ostream &out) :
- out_(out)
+ out_(out),
+ pretty_(false),
+ indent_(0),
+ mode_(NoMode)
{
}
- _finline CYOutput &operator <<(char rhs) {
- out_ << rhs;
- return *this;
- }
+ void Check(char value);
+ void Terminate();
- _finline CYOutput &operator <<(const char *rhs) {
- out_ << rhs;
+ CYOutput &operator <<(char rhs);
+ CYOutput &operator <<(const char *rhs);
+
+ _finline CYOutput &operator <<(const CYThing *rhs) {
+ if (rhs != NULL)
+ rhs->Output(*this);
return *this;
}
}
};
-struct CYSource :
- CYNext<CYSource>
-{
- virtual bool IsBlock() const {
- return next_ != NULL;
- }
-
- virtual void Show(CYOutput &out) const;
- virtual void Output(CYOutput &out) const = 0;
- virtual void Output(CYOutput &out, bool block) const;
- virtual void Output_(CYOutput &out) const;
-};
-
struct CYPropertyName {
virtual void PropertyName(CYOutput &out) const = 0;
};
}
};
+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 CYStatement :
- CYSource
+ CYNext<CYStatement>
{
CYLabel *labels_;
labels_ = new CYLabel(identifier, labels_);
}
- virtual void Output_(CYOutput &out) const;
+ bool Single(CYOutput &out, CYFlags flags) const;
+ void Multiple(CYOutput &out, CYFlags flags = CYNoFlags) const;
+
+ private:
+ virtual void Output(CYOutput &out, CYFlags flags) const = 0;
};
struct CYBlock :
{
}
- virtual bool IsBlock() const {
- return true;
- }
-
- virtual void Output(CYOutput &out) const;
+ virtual void Output(CYOutput &out, CYFlags flags) const;
};
enum CYState {
size_t size_;
FILE *file_;
+ bool strict_;
+
+ enum Condition {
+ RegExStart,
+ RegExRest
+ };
+
std::string filename_;
struct Error {
+ bool warning_;
cy::location location_;
std::string message_;
};
typedef std::vector<Error> Errors;
- CYSource *source_;
+ CYStatement *program_;
Errors errors_;
private:
public:
CYDriver(const std::string &filename);
~CYDriver();
-};
-enum CYFlags {
- CYNoFlags = 0,
- CYNoBrace = (1 << 0),
- CYNoFunction = (1 << 1),
- CYNoLeader = (1 << 2),
- CYNoTrailer = (1 << 3),
- CYNoIn = (1 << 4),
- CYNoHyphen = (1 << 5),
- CYNoBF = (CYNoBrace | CYNoFunction),
+ void SetCondition(Condition condition);
+
+ void Warning(const cy::location &location, const char *message);
};
struct CYForInitialiser {
CYNext<CYExpression>,
CYForInitialiser,
CYForInInitialiser,
- CYClassName
+ CYClassName,
+ CYThing
{
virtual unsigned Precedence() const = 0;
+ virtual bool RightHand() const {
+ return true;
+ }
+
virtual void For(CYOutput &out) const;
virtual void ForIn(CYOutput &out, CYFlags flags) const;
virtual const char *ForEachIn() const;
virtual void ForEachIn(CYOutput &out) const;
+ virtual void Output(CYOutput &out) const;
virtual void Output(CYOutput &out, CYFlags flags) const = 0;
void Output(CYOutput &out, unsigned precedence, CYFlags flags) const;
return value; \
}
+#define CYRightHand(value) \
+ virtual bool RightHand() const { \
+ return value; \
+ }
+
struct CYCompound :
CYExpression
{
};
struct CYComprehension :
- CYNext<CYComprehension>
+ CYNext<CYComprehension>,
+ CYThing
{
void Output(CYOutput &out) const;
virtual const char *Name() const = 0;
CYExpression
{
CYPrecedence(0)
+ CYRightHand(false)
};
struct CYMagic :
CYExpression
{
CYPrecedence(0)
+ CYRightHand(false)
};
struct CYSelectorPart :
- CYNext<CYSelectorPart>
+ CYNext<CYSelectorPart>,
+ CYThing
{
CYWord *name_;
bool value_;
return value_;
}
- virtual const char *Word() const {
- if (size_ == 0 || !WordStartRange_[value_[0]])
- return NULL;
- for (size_t i(1); i != size_; ++i)
- if (!WordEndRange_[value_[i]])
- return NULL;
- return Value();
- }
-
- virtual void Output(CYOutput &out) const {
- return Output(out, CYNoFlags);
- }
+ virtual const char *Word() const;
virtual void Output(CYOutput &out, CYFlags flags) const;
virtual void PropertyName(CYOutput &out) const;
return value_;
}
- virtual void Output(CYOutput &out) const {
- return Output(out, CYNoFlags);
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+ virtual void PropertyName(CYOutput &out) const;
+};
+
+struct CYRegEx :
+ CYLiteral
+{
+ const char *value_;
+
+ CYRegEx(const char *value) :
+ value_(value)
+ {
+ }
+
+ const char *Value() const {
+ return value_;
}
virtual void Output(CYOutput &out, CYFlags flags) const;
- virtual void PropertyName(CYOutput &out) const;
};
struct CYNull :
{
}
- virtual bool Value() const;
+ virtual bool Value() const {
+ return false;
+ }
};
struct CYTrue :
{
}
- virtual bool Value() const;
+ virtual bool Value() const {
+ return true;
+ }
};
struct CYVariable :
}
CYPrecedence(0)
+ CYRightHand(false)
virtual void Output(CYOutput &out, CYFlags flags) const;
};
};
struct CYArgument :
- CYNext<CYArgument>
+ CYNext<CYArgument>,
+ CYThing
{
CYWord *name_;
CYExpression *value_;
};
struct CYElement :
- CYNext<CYElement>
+ CYNext<CYElement>,
+ CYThing
{
CYExpression *value_;
struct CYDeclarations :
CYNext<CYDeclarations>,
- CYForInitialiser
+ CYForInitialiser,
+ CYThing
{
CYDeclaration *declaration_;
}
virtual void For(CYOutput &out) const;
+
+ virtual void Output(CYOutput &out) const;
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
- virtual void Output(CYOutput &out) const;
+ virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYLet :
{
}
- virtual void Output(CYOutput &out) const;
+ virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYField :
bool instance_;
CYExpression *type_;
CYMessageParameter *parameter_;
- CYSource *body_;
+ CYStatement *body_;
- CYMessage(bool instance, CYExpression *type, CYMessageParameter *parameter, CYSource *body) :
+ CYMessage(bool instance, CYExpression *type, CYMessageParameter *parameter, CYStatement *body) :
instance_(instance),
type_(type),
parameter_(parameter),
virtual void Output(CYOutput &out, bool replace) const;
};
-struct CYClass :
- CYExpression,
- CYStatement
-{
+struct CYClass {
CYClassName *name_;
CYExpression *super_;
CYField *fields_;
{
}
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
+struct CYClassExpression :
+ CYClass,
+ CYExpression
+{
+ CYClassExpression(CYClassName *name, CYExpression *super, CYField *fields, CYMessage *messages) :
+ CYClass(name, super, fields, messages)
+ {
+ }
+
CYPrecedence(0)
- virtual void Output(CYOutput &out) const;
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
+struct CYClassStatement :
+ CYClass,
+ CYStatement
+{
+ CYClassStatement(CYClassName *name, CYExpression *super, CYField *fields, CYMessage *messages) :
+ CYClass(name, super, fields, messages)
+ {
+ }
+
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
- virtual void Output(CYOutput &out) const;
+ virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYFunctionParameter :
{
}
- virtual void Output(CYOutput &out) const;
+ virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYForIn :
{
}
- virtual void Output(CYOutput &out) const;
+ virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYForEachIn :
{
}
- virtual void Output(CYOutput &out) const;
+ virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYProperty :
- CYNext<CYProperty>
+ CYNext<CYProperty>,
+ CYThing
{
CYPropertyName *name_;
CYExpression *value_;
}
CYPrecedence(1)
+ CYRightHand(false)
virtual void Output(CYOutput &out, CYFlags flags) const;
};
}
CYPrecedence(1)
+ CYRightHand(false)
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
- CYPrecedence(1)
+ virtual unsigned Precedence() const {
+ return arguments_ == NULL ? 2 : 1;
+ }
+
+ CYRightHand(false)
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
- CYPrecedence(2)
+ CYPrecedence(1)
+ CYRightHand(false)
virtual void Output(CYOutput &out, CYFlags flags) const;
};
{
}
- virtual void Output(CYOutput &out) const;
+ virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYDoWhile :
{
}
- virtual void Output(CYOutput &out) const;
+ virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYWhile :
{
}
- virtual void Output(CYOutput &out) const;
+ virtual void Output(CYOutput &out, CYFlags flags) const;
};
-struct CYLambda :
- CYExpression
-{
+struct CYFunction {
CYIdentifier *name_;
CYFunctionParameter *parameters_;
- CYSource *body_;
+ CYStatement *body_;
- CYLambda(CYIdentifier *name, CYFunctionParameter *parameters, CYSource *body) :
+ CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *body) :
name_(name),
parameters_(parameters),
body_(body)
{
}
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
+struct CYFunctionExpression :
+ CYFunction,
+ CYExpression
+{
+ CYFunctionExpression(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *body) :
+ CYFunction(name, parameters, body)
+ {
+ }
+
CYPrecedence(0)
+ CYRightHand(false)
virtual void Output(CYOutput &out, CYFlags flags) const;
};
-struct CYFunction :
- CYLambda,
- CYSource
+struct CYFunctionStatement :
+ CYFunction,
+ CYStatement
{
- CYFunction(CYIdentifier *name, CYFunctionParameter *parameters, CYSource *body) :
- CYLambda(name, parameters, body)
+ CYFunctionStatement(CYIdentifier *name, CYFunctionParameter *parameters, CYStatement *body) :
+ CYFunction(name, parameters, body)
{
}
- virtual void Output(CYOutput &out) const;
+ virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYExpress :
{
}
- virtual void Output(CYOutput &out) const;
+ virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYContinue :
{
}
- virtual void Output(CYOutput &out) const;
+ virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYBreak :
{
}
- virtual void Output(CYOutput &out) const;
+ virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYReturn :
{
}
- virtual void Output(CYOutput &out) const;
+ virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYEmpty :
CYStatement
{
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
+struct CYFinally :
+ CYThing
+{
+ CYStatement *code_;
+
+ CYFinally(CYStatement *code) :
+ code_(code)
+ {
+ }
+
virtual void Output(CYOutput &out) const;
- virtual void Output(CYOutput &out, bool block) const;
};
struct CYTry :
CYStatement
{
- CYStatement *try_;
+ CYStatement *code_;
CYCatch *catch_;
- CYStatement *finally_;
+ CYFinally *finally_;
- CYTry(CYStatement *_try, CYCatch *_catch, CYStatement *finally) :
- try_(_try),
+ CYTry(CYStatement *code, CYCatch *_catch, CYFinally *finally) :
+ code_(code),
catch_(_catch),
finally_(finally)
{
}
- virtual void Output(CYOutput &out) const;
+ virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYThrow :
{
}
- virtual void Output(CYOutput &out) const;
+ virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYWith :
{
}
- virtual void Output(CYOutput &out) const;
+ virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYSwitch :
{
}
- virtual void Output(CYOutput &out) const;
+ virtual void Output(CYOutput &out, CYFlags flags) const;
};
struct CYCondition :
CYPrefix_(true, "typeof", TypeOf)
CYPrefix_(false, "++", PreIncrement)
CYPrefix_(false, "--", PreDecrement)
+CYPrefix_(false, "+", Affirm)
CYPrefix_(false, "-", Negate)
CYPrefix_(false, "~", BitwiseNot)
CYPrefix_(false, "!", LogicalNot)