CYMember *member_;
CYNull *null_;
CYNumber *number_;
+ CYEncodedPart *part_;
CYProgram *program_;
CYProperty *property_;
CYPropertyName *propertyName_;
CYString *string_;
CYThis *this_;
CYTrue *true_;
+ CYEncodedType *type_;
CYWord *word_;
@begin ObjectiveC
%token AtImplementation "@implementation"
%token AtImplementation_ ";@implementation"
%token AtImport "@import"
+%token AtEncode "@encode"
%token AtEnd "@end"
%token AtSelector "@selector"
@end
%type <statement_> WithStatement
%type <word_> Word
%type <word_> WordOpt
+%type <expression_> Variable
@begin ObjectiveC
%type <expression_> BoxableExpression
%type <messageParameter_> MessageParameterList
%type <messageParameter_> MessageParameterListOpt
%type <bool_> MessageScope
+%type <type_> ModifiedType
+%type <part_> PrefixedType
%type <argument_> SelectorCall_
%type <argument_> SelectorCall
%type <selector_> SelectorExpression_
%type <selector_> SelectorExpressionOpt
%type <argument_> SelectorList
%type <word_> SelectorWordOpt
+%type <part_> SuffixedType
%type <expression_> TypeOpt
+%type <type_> TypedIdentifier
%type <argument_> VariadicCall
@end
| { $$ = NULL; }
;
+Variable
+ : Identifier { $$ = CYNew CYVariable($1); }
+ ;
+
PrimaryExpression
: "this" { $$ = $1; }
- | Identifier { $$ = CYNew CYVariable($1); }
+ | Variable { $$ = $1; }
| Literal { $$ = $1; }
| ArrayLiteral { $$ = $1; }
| ObjectLiteral { $$ = $1; }
/* }}} */
@begin ObjectiveC
+/* Cycript (Objective-C): Type Encoding {{{ */
+SuffixedType
+ : { $$ = NULL; }
+ | "(" PrefixedType ")" { $$ = $2; }
+ | SuffixedType "[" NumericLiteral "]" { $$ = CYNew CYEncodedPart($1, "arrayOf", CYNew CYArgument($3)); }
+ ;
+
+PrefixedType
+ : SuffixedType { $$ = $1; }
+ | "*" PrefixedType { $$ = CYNew CYEncodedPart($2, "pointerTo"); }
+ ;
+
+ModifiedType
+ : Variable { $$ = CYNew CYEncodedType($1); }
+ | "const" ModifiedType { $2->base_ = CYNew CYCall(CYNew CYDirectMember($2->base_, CYNew CYString("constant"))); $$ = $2; }
+ ;
+
+TypedIdentifier
+ : ModifiedType PrefixedType { $1->parts_ = $2; $$ = $1;}
+ ;
+
+PrimaryExpression
+ : AtEncode "(" TypedIdentifier ")" { $$ = $3; }
+ ;
+/* }}} */
/* Cycript (Objective-C): @class Declaration {{{ */
ClassSuperOpt
/* XXX: why the hell did I choose MemberExpression? */
;
TypeOpt
- : "(" Expression ")" { $$ = $2; }
+ : "(" TypedIdentifier ")" { $$ = $2; }
| "(" LexSetRegExp "void" ")" { $$ = CYNew CYString("v"); }
| { $$ = NULL; }
;
return $E(Replace_(context));
}
+CYExpression *CYEncodedPart::Replace(CYContext &context, CYExpression *base) { $T(base)
+ return next_->Replace(context, $ CYCall($ CYDirectMember(base, $ CYString(name_)), arguments_));
+}
+
+CYExpression *CYEncodedType::Replace(CYContext &context) {
+ return parts_->Replace(context, base_);
+}
+
CYStatement *CYField::Replace(CYContext &context) const { $T(NULL)
CYVariable *cyn($V("$cyn"));
CYVariable *cyt($V("$cyt"));
#include "Parser.hpp"
+struct CYEncodedPart :
+ CYNext<CYEncodedPart>
+{
+ const char *name_;
+ CYArgument *arguments_;
+
+ CYEncodedPart(CYEncodedPart *next, const char *name, CYArgument *arguments = NULL) :
+ CYNext<CYEncodedPart>(next),
+ name_(name),
+ arguments_(arguments)
+ {
+ }
+
+ CYExpression *Replace(CYContext &context, CYExpression *base);
+};
+
+struct CYEncodedType :
+ CYExpression
+{
+ CYExpression *base_;
+ CYEncodedPart *parts_;
+
+ CYEncodedType(CYExpression *base, CYEncodedPart *parts = NULL) :
+ base_(base),
+ parts_(parts)
+ {
+ }
+
+ CYPrecedence(1)
+
+ virtual CYExpression *Replace(CYContext &context);
+ virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
struct CYBox :
CYExpression
{