]> git.saurik.com Git - cycript.git/commitdiff
Let's at least parse Objective-J.
authorJay Freeman (saurik) <saurik@saurik.com>
Mon, 5 Jul 2010 20:50:22 +0000 (20:50 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Mon, 5 Jul 2010 20:50:22 +0000 (20:50 +0000)
Cycript.l.in
Cycript.yy.in
ObjectiveC/Output.mm
ObjectiveC/Replace.mm
ObjectiveC/Syntax.hpp

index 7358be7f5a839f36426cbab6199f9ecb1716d728..352763a34a40ca82845b962b03e4aa4cec47da1a 100644 (file)
@@ -256,10 +256,15 @@ XMLName {XMLNameStart}{XMLNamePart}*
 "["    L C return tk::OpenBracket;
 "]"    L C return tk::CloseBracket;
 
+@begin Java
+"@class"          L C return tk::AtClass;
+@end
+
 @begin ObjectiveC
-"@class"       L C return tk::AtClass;
-"@end"         L C return tk::AtEnd;
-"@selector"    L C return tk::AtSelector;
+"@end"            L C return tk::AtEnd;
+"@implementation" L C return tk::AtImplementation;
+"@import"         L C return tk::AtImport;
+"@selector"       L C return tk::AtSelector;
 @end
 
 "false"        L C yylval->false_ = new(yyextra->pool_) CYFalse(); return tk::False;
index 53a6336467debbc178d5c580e589ca95439a7c14..7646e04e1690fb2ffdf4317906cc8912b9644b95 100644 (file)
@@ -230,9 +230,16 @@ int cylex(YYSTYPE *, cy::location *, void *);
 %token OpenBracket "["
 %token CloseBracket "]"
 
+@begin Java
 %token AtClass "@class"
-%token AtSelector "@selector"
+@end
+
+@begin ObjectiveC
+%token AtImplementation "@implementation"
+%token AtImport "@import"
 %token AtEnd "@end"
+%token AtSelector "@selector"
+@end
 
 %token <false_> False "false"
 %token <null_> Null "null"
@@ -1516,8 +1523,17 @@ ClassSuperOpt
     | { $$ = NULL; }
     ;
 
+ClassField
+    : Expression Identifier ";"
+    ;
+
+ClassFieldListOpt
+    : ClassFieldListOpt ClassField
+    |
+    ;
+
 ClassFieldList
-    : Brace "}" { $$ = NULL; }
+    : Brace ClassFieldListOpt "}" { $$ = NULL; }
     ;
 
 MessageScope
@@ -1527,6 +1543,7 @@ MessageScope
 
 TypeOpt
     : "(" Expression ")" { $$ = $2; }
+    | "(" LexSetRegExp "void" ")" { $$ = NULL; }
     | { $$ = NULL; }
     ;
 
@@ -1554,6 +1571,7 @@ ClassMessageDeclaration
 
 ClassMessageDeclarationListOpt
     : ClassMessageDeclarationListOpt ClassMessageDeclaration { $2->SetNext($1); $$ = $2; }
+    | ClassMessageDeclarationListOpt Comment { $$ = $1; }
     | { $$ = NULL; }
     ;
 
@@ -1583,15 +1601,19 @@ ClassProtocolListOpt
     ;
 
 ClassExpression
-    : "@class" ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYClassExpression($2, $3, $4, $5, $6); }
+    : "@implementation" ClassNameOpt ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYClassExpression($2, $3, $4, $5, $6); }
     ;
 
 ClassStatement
-    : "@class" ClassName ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYClassStatement($2, $3, $4, $5, $6); }
+    : "@implementation" ClassName ClassSuperOpt ClassProtocolListOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYClassStatement($2, $3, $4, $5, $6); }
+    ;
+
+CategoryName
+    : "(" Word ")"
     ;
 
 CategoryStatement
-    : "@class" ClassName ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYCategory($2, $3); }
+    : "@implementation" ClassName CategoryName ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYCategory($2, $4); }
     ;
 
 PrimaryExpressionBF
@@ -1652,6 +1674,23 @@ PrimaryExpressionNo
     | "@selector" "(" SelectorExpression ")" { $$ = new(driver.pool_) CYSelector($3); }
     ;
 /* }}} */
+/* Cycript (Objective-C): @import Directive {{{ */
+PathName
+    : "/" PathName
+    | "." PathName
+    | Word PathName
+    |
+    ;
+
+ImportPath
+    : "<" PathName ">"
+    | StringLiteral
+    ;
+
+SourceElement_
+    : "@import" ImportPath { $$ = new(driver.pool_) CYImport(); }
+    ;
+/* }}} */
 @end
 
 @begin C
index d8f8345d1b822bbb8c064a09ffe9b52e38e812fa..542a0fb0a5f9acf6f746ec92d1de9d04623a7bf9 100644 (file)
@@ -96,6 +96,10 @@ void CYClassStatement::Output(CYOutput &out, CYFlags flags) const {
 void CYField::Output(CYOutput &out) const {
 }
 
+void CYImport::Output(CYOutput &out, CYFlags flags) const {
+    out << "@import";
+}
+
 void CYMessage::Output(CYOutput &out, bool replace) const {
     out << (instance_ ? '-' : '+');
 
index fbd99343065c170b4786c271cf1d481e4d5d5bd4..34281868e11f467ab1ba8e2808075cb0b852ca00 100644 (file)
@@ -83,6 +83,10 @@ CYStatement *CYField::Replace(CYContext &context) const {
     return NULL;
 }
 
+CYStatement *CYImport::Replace(CYContext &context) {
+    return this;
+}
+
 CYStatement *CYMessage::Replace(CYContext &context, bool replace) const { $T(NULL)
     CYVariable *cyn($V("$cyn"));
     CYVariable *cyt($V("$cyt"));
index d8f57ec88cc6810dc65e89673a009e24f5bda800..9896c3e1cc527e9774118edcb8fc232da251800b 100644 (file)
@@ -138,6 +138,13 @@ struct CYProtocol :
     void Output(CYOutput &out) const;
 };
 
+struct CYImport :
+    CYStatement
+{
+    virtual CYStatement *Replace(CYContext &context);
+    virtual void Output(CYOutput &out, CYFlags flags) const;
+};
+
 struct CYClass {
     CYClassName *name_;
     CYExpression *super_;