CYInfix *infix_;
CYLiteral *literal_;
CYMember *member_;
+ CYModule *module_;
CYNull *null_;
CYNumber *number_;
CYProgram *program_;
%type <messageParameter_> MessageParameterListOpt
%type <bool_> MessageScope
%type <typedIdentifier_> ModifiedType
+%type <module_> Module
%type <typedIdentifier_> PrefixedType
%type <expression_> PrimitiveType
%type <argument_> SelectorCall_
;
/* }}} */
/* Cycript (Objective-C): @import Directive {{{ */
-PathName
- : "/" PathName
- | "." PathName
- | Word PathName
- |
- ;
-
-ImportPath
- : "<" PathName ">"
- | StringLiteral
+Module
+ : Module "." Word { $$ = CYNew CYModule($3, $1); }
+ | Word { $$ = CYNew CYModule($1); }
;
-StatementListItem
- : LexSetStatement LexSetRegExp "@import" ImportPath { $$ = CYNew CYImport(); }
+Declaration__
+ : "@import" Module { $$ = CYNew CYImport($2); }
;
/* }}} */
/* Cycript (Objective-C): Boxed Expressions {{{ */
out << code_;
}
+void CYModule::Output(CYOutput &out) const {
+ out << part_;
+ if (next_ != NULL)
+ out << '.' << next_;
+}
+
void CYBox::Output(CYOutput &out, CYFlags flags) const {
out << '@';
value_->Output(out, Precedence(), CYRight(flags));
}
CYStatement *CYImport::Replace(CYContext &context) {
- return this;
+ return $ CYVar($L1($L(module_->part_->Word(), $C1($V("require"), module_->Replace(context, "/")))));
}
CYStatement *CYMessage::Replace(CYContext &context, bool replace) const { $T(NULL)
return MessageType(context, type_, next_);
}
+CYString *CYModule::Replace(CYContext &context, const char *separator) const {
+ if (next_ == NULL)
+ return $ CYString(part_);
+ return $ CYString($pool.strcat(next_->Replace(context, separator)->Value(), separator, part_->Word(), NULL));
+}
+
CYExpression *CYBox::Replace(CYContext &context) {
return $C1($M($V("Instance"), $S("box")), value_);
}
void Output(CYOutput &out) const;
};
+struct CYModule :
+ CYNext<CYModule>,
+ CYThing
+{
+ CYWord *part_;
+
+ CYModule(CYWord *part, CYModule *next = NULL) :
+ CYNext<CYModule>(next),
+ part_(part)
+ {
+ }
+
+ CYString *Replace(CYContext &context, const char *separator) const;
+ void Output(CYOutput &out) const;
+};
+
struct CYImport :
CYStatement
{
+ CYModule *module_;
+
+ CYImport(CYModule *module) :
+ module_(module)
+ {
+ }
+
virtual CYStatement *Replace(CYContext &context);
virtual void Output(CYOutput &out, CYFlags flags) const;
};