From 1ba6903ecce638fac26bc5e15e66905c9d06675e Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 5 Jul 2010 20:50:22 +0000 Subject: [PATCH] Let's at least parse Objective-J. --- Cycript.l.in | 11 +++++++--- Cycript.yy.in | 49 ++++++++++++++++++++++++++++++++++++++----- ObjectiveC/Output.mm | 4 ++++ ObjectiveC/Replace.mm | 4 ++++ ObjectiveC/Syntax.hpp | 7 +++++++ 5 files changed, 67 insertions(+), 8 deletions(-) diff --git a/Cycript.l.in b/Cycript.l.in index 7358be7..352763a 100644 --- a/Cycript.l.in +++ b/Cycript.l.in @@ -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; diff --git a/Cycript.yy.in b/Cycript.yy.in index 53a6336..7646e04 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -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" %token 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 diff --git a/ObjectiveC/Output.mm b/ObjectiveC/Output.mm index d8f8345..542a0fb 100644 --- a/ObjectiveC/Output.mm +++ b/ObjectiveC/Output.mm @@ -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_ ? '-' : '+'); diff --git a/ObjectiveC/Replace.mm b/ObjectiveC/Replace.mm index fbd9934..3428186 100644 --- a/ObjectiveC/Replace.mm +++ b/ObjectiveC/Replace.mm @@ -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")); diff --git a/ObjectiveC/Syntax.hpp b/ObjectiveC/Syntax.hpp index d8f57ec..9896c3e 100644 --- a/ObjectiveC/Syntax.hpp +++ b/ObjectiveC/Syntax.hpp @@ -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_; -- 2.49.0