;
/* }}} */
/* Cycript (Objective-C): Block Expressions {{{ */
-TypedParameterList_
- : "," TypedParameterList { $$ = $2; }
- | { $$ = NULL; }
- ;
-
-TypedParameterList
- : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
- ;
-
-TypedParameterListOpt
- : TypedParameterList { $$ = $1; }
- | { $$ = NULL; }
- ;
-
PrimaryExpression
: "^" ModifiedType "(" LexPushInOff TypedParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYObjCBlock($2, $5, $10); }
;
: "auto"
;
/* }}} */
+/* Cycript (C): Lambda Expressions {{{ */
+TypedParameterList_
+ : "," TypedParameterList { $$ = $2; }
+ | { $$ = NULL; }
+ ;
+
+TypedParameterList
+ : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
+ ;
+
+TypedParameterListOpt
+ : TypedParameterList { $$ = $1; }
+ | { $$ = NULL; }
+ ;
+
+PrimaryExpression
+ : "[" LexPushInOff LexSetRegExp "=" "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" ModifiedType BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($13, $9, $16); }
+ ;
+/* }}} */
@end
/* YUI: Documentation Comments {{{ */
return $E(Replace_(context));
}
-CYExpression *CYTypeArrayOf::Replace(CYContext &context) {
- return $ CYCall($ CYDirectMember(next_->Replace(context), $ CYString("arrayOf")), $ CYArgument(size_));
-}
-
-CYExpression *CYTypeConstant::Replace(CYContext &context) {
- return $ CYCall($ CYDirectMember(next_->Replace(context), $ CYString("constant")));
-}
-
-CYExpression *CYTypePointerTo::Replace(CYContext &context) {
- return $ CYCall($ CYDirectMember(next_->Replace(context), $ CYString("pointerTo")));
-}
-
-CYExpression *CYTypeVariable::Replace(CYContext &context) {
- return expression_;
-}
-
CYExpression *CYEncodedType::Replace(CYContext &context) {
return type_->Replace(context);
}
CYExpression *CYSendSuper::Replace(CYContext &context) {
return $ CYSendDirect($V("$cyr"), arguments_);
}
-
-CYFunctionParameter *CYTypedParameter::Parameters(CYContext &context) { $T(NULL)
- return $ CYFunctionParameter($ CYDeclaration(typed_->identifier_ ?: context.Unique()), next_->Parameters(context));
-}
-
-CYExpression *CYTypedParameter::TypeSignature(CYContext &context, CYExpression *prefix) { $T(prefix)
- return next_->TypeSignature(context, $ CYAdd(prefix, typed_->type_->Replace(context)));
-}
#include "Parser.hpp"
-struct CYTypeModifier :
- CYNext<CYTypeModifier>
-{
- CYTypeModifier(CYTypeModifier *next) :
- CYNext<CYTypeModifier>(next)
- {
- }
-
- virtual CYExpression *Replace(CYContext &context) = 0;
-};
-
-struct CYTypeArrayOf :
- CYTypeModifier
-{
- CYExpression *size_;
-
- CYTypeArrayOf(CYExpression *size, CYTypeModifier *next = NULL) :
- CYTypeModifier(next),
- size_(size)
- {
- }
-
- CYPrecedence(2)
-
- virtual CYExpression *Replace(CYContext &context);
-};
-
-struct CYTypeConstant :
- CYTypeModifier
-{
- CYTypeConstant(CYTypeModifier *next = NULL) :
- CYTypeModifier(next)
- {
- }
-
- CYPrecedence(3)
-
- virtual CYExpression *Replace(CYContext &context);
-};
-
-struct CYTypePointerTo :
- CYTypeModifier
-{
- CYTypePointerTo(CYTypeModifier *next = NULL) :
- CYTypeModifier(next)
- {
- }
-
- CYPrecedence(3)
-
- virtual CYExpression *Replace(CYContext &context);
-};
-
-struct CYTypeVariable :
- CYTypeModifier
-{
- CYExpression *expression_;
-
- CYTypeVariable(CYExpression *expression) :
- CYTypeModifier(NULL),
- expression_(expression)
- {
- }
-
- CYPrecedence(1)
-
- virtual CYExpression *Replace(CYContext &context);
-};
-
-struct CYTypedIdentifier :
- CYNext<CYTypedIdentifier>
-{
- CYIdentifier *identifier_;
- CYTypeModifier *type_;
-
- CYTypedIdentifier(CYIdentifier *identifier) :
- identifier_(identifier),
- type_(NULL)
- {
- }
-};
-
-struct CYTypedParameter :
- CYNext<CYTypedParameter>
-{
- CYTypedIdentifier *typed_;
-
- CYTypedParameter(CYTypedIdentifier *typed, CYTypedParameter *next) :
- CYNext<CYTypedParameter>(next),
- typed_(typed)
- {
- }
-
- CYFunctionParameter *Parameters(CYContext &context);
- CYExpression *TypeSignature(CYContext &context, CYExpression *prefix);
-};
-
struct CYObjCBlock :
CYExpression
{
statement_->Single(out, CYRight(flags));
}
+void CYLambda::Output(CYOutput &out, CYFlags flags) const {
+ // XXX: this is seriously wrong
+ out << "[](";
+ out << ")->";
+ out << "{";
+ out << "}";
+}
+
void CYLetStatement::Output(CYOutput &out, CYFlags flags) const {
out << "let" << ' ' << '(' << *declarations_ << ')';
code_->Single(out, CYRight(flags));
virtual void Output(CYOutput &out) const;
};
+struct CYTypeModifier :
+ CYNext<CYTypeModifier>
+{
+ CYTypeModifier(CYTypeModifier *next) :
+ CYNext<CYTypeModifier>(next)
+ {
+ }
+
+ virtual CYExpression *Replace(CYContext &context) = 0;
+};
+
+struct CYTypeArrayOf :
+ CYTypeModifier
+{
+ CYExpression *size_;
+
+ CYTypeArrayOf(CYExpression *size, CYTypeModifier *next = NULL) :
+ CYTypeModifier(next),
+ size_(size)
+ {
+ }
+
+ CYPrecedence(2)
+
+ virtual CYExpression *Replace(CYContext &context);
+};
+
+struct CYTypeConstant :
+ CYTypeModifier
+{
+ CYTypeConstant(CYTypeModifier *next = NULL) :
+ CYTypeModifier(next)
+ {
+ }
+
+ CYPrecedence(3)
+
+ virtual CYExpression *Replace(CYContext &context);
+};
+
+struct CYTypePointerTo :
+ CYTypeModifier
+{
+ CYTypePointerTo(CYTypeModifier *next = NULL) :
+ CYTypeModifier(next)
+ {
+ }
+
+ CYPrecedence(3)
+
+ virtual CYExpression *Replace(CYContext &context);
+};
+
+struct CYTypeVariable :
+ CYTypeModifier
+{
+ CYExpression *expression_;
+
+ CYTypeVariable(CYExpression *expression) :
+ CYTypeModifier(NULL),
+ expression_(expression)
+ {
+ }
+
+ CYPrecedence(1)
+
+ virtual CYExpression *Replace(CYContext &context);
+};
+
+struct CYTypedIdentifier :
+ CYNext<CYTypedIdentifier>
+{
+ CYIdentifier *identifier_;
+ CYTypeModifier *type_;
+
+ CYTypedIdentifier(CYIdentifier *identifier) :
+ identifier_(identifier),
+ type_(NULL)
+ {
+ }
+};
+
+struct CYTypedParameter :
+ CYNext<CYTypedParameter>
+{
+ CYTypedIdentifier *typed_;
+
+ CYTypedParameter(CYTypedIdentifier *typed, CYTypedParameter *next) :
+ CYNext<CYTypedParameter>(next),
+ typed_(typed)
+ {
+ }
+
+ CYFunctionParameter *Parameters(CYContext &context);
+ CYExpression *TypeSignature(CYContext &context, CYExpression *prefix);
+};
+
+struct CYLambda :
+ CYExpression
+{
+ CYTypeModifier *type_;
+ CYTypedParameter *parameters_;
+ CYStatement *statements_;
+
+ CYLambda(CYTypeModifier *type, CYTypedParameter *parameters, CYStatement *statements) :
+ type_(type),
+ parameters_(parameters),
+ statements_(statements)
+ {
+ }
+
+ CYPrecedence(1)
+
+ virtual CYExpression *Replace(CYContext &context);
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
namespace cy {
namespace Syntax {
return this;
}
+CYExpression *CYLambda::Replace(CYContext &context) {
+ return $N2($V("Functor"), $ CYFunctionExpression(NULL, parameters_->Parameters(context), statements_), parameters_->TypeSignature(context, type_->Replace(context)));
+}
+
CYStatement *CYLetStatement::Replace(CYContext &context) {
return $E($ CYCall(CYNonLocalize(context, $ CYFunctionExpression(NULL, declarations_->Parameter(context), code_)), declarations_->Argument(context)));
}
} }
+CYExpression *CYTypeArrayOf::Replace(CYContext &context) {
+ return $ CYCall($ CYDirectMember(next_->Replace(context), $ CYString("arrayOf")), $ CYArgument(size_));
+}
+
+CYExpression *CYTypeConstant::Replace(CYContext &context) {
+ return $ CYCall($ CYDirectMember(next_->Replace(context), $ CYString("constant")));
+}
+
+CYExpression *CYTypePointerTo::Replace(CYContext &context) {
+ return $ CYCall($ CYDirectMember(next_->Replace(context), $ CYString("pointerTo")));
+}
+
+CYExpression *CYTypeVariable::Replace(CYContext &context) {
+ return expression_;
+}
+
+CYFunctionParameter *CYTypedParameter::Parameters(CYContext &context) { $T(NULL)
+ return $ CYFunctionParameter($ CYDeclaration(typed_->identifier_ ?: context.Unique()), next_->Parameters(context));
+}
+
+CYExpression *CYTypedParameter::TypeSignature(CYContext &context, CYExpression *prefix) { $T(prefix)
+ return next_->TypeSignature(context, $ CYAdd(prefix, typed_->type_->Replace(context)));
+}
+
CYStatement *CYVar::Replace(CYContext &context) {
declarations_->Replace(context);
return $E(declarations_->Compound(context));