From 61769f4feca6b79c44accca7f8bd9b74bf6a5ce9 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 20 Jan 2014 08:53:24 -0800 Subject: [PATCH] Add actual syntax that desugars to new Instance(). --- Cycript.yy.in | 5 +++++ ObjectiveC/Output.cpp | 5 +++++ ObjectiveC/Replace.cpp | 4 ++++ ObjectiveC/Syntax.hpp | 16 ++++++++++++++++ 4 files changed, 30 insertions(+) diff --git a/Cycript.yy.in b/Cycript.yy.in index 57b1ac6..5a35dd7 100644 --- a/Cycript.yy.in +++ b/Cycript.yy.in @@ -1634,6 +1634,11 @@ PrimaryExpression : "^" ModifiedType "(" LexPushInOff TypedParameterListOpt ")" LexPopIn BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYObjCBlock($2, $5, $10); } ; /* }}} */ +/* Cycript (Objective-C): Instance Literals {{{ */ +PrimaryExpression + : "#" NumericLiteral { $$ = CYNew CYInstanceLiteral($2); } + ; +/* }}} */ @end @begin C diff --git a/ObjectiveC/Output.cpp b/ObjectiveC/Output.cpp index 6fd2229..d67971f 100644 --- a/ObjectiveC/Output.cpp +++ b/ObjectiveC/Output.cpp @@ -81,6 +81,11 @@ void CYImport::Output(CYOutput &out, CYFlags flags) const { out << "@import"; } +void CYInstanceLiteral::Output(CYOutput &out, CYFlags flags) const { + out << '#'; + number_->Output(out, CYRight(flags)); +} + void CYMessage::Output(CYOutput &out, bool replace) const { out << (instance_ ? '-' : '+'); diff --git a/ObjectiveC/Replace.cpp b/ObjectiveC/Replace.cpp index a2a4c11..ae3b20e 100644 --- a/ObjectiveC/Replace.cpp +++ b/ObjectiveC/Replace.cpp @@ -96,6 +96,10 @@ CYStatement *CYImport::Replace(CYContext &context) { return $ CYVar($L1($L(module_->part_->Word(), $C1($V("require"), module_->Replace(context, "/"))))); } +CYExpression *CYInstanceLiteral::Replace(CYContext &context) { + return $N1($V("Instance"), number_); +} + 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 8fa10ee..4c15344 100644 --- a/ObjectiveC/Syntax.hpp +++ b/ObjectiveC/Syntax.hpp @@ -24,6 +24,22 @@ #include "Parser.hpp" +struct CYInstanceLiteral : + CYExpression +{ + CYNumber *number_; + + CYInstanceLiteral(CYNumber *number) : + number_(number) + { + } + + CYPrecedence(1) + + virtual CYExpression *Replace(CYContext &context); + virtual void Output(CYOutput &out, CYFlags flags) const; +}; + struct CYObjCBlock : CYExpression { -- 2.47.2