X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/440424e2bd3babd0bb2c266ba931b3c41ccc0f65..0844a100ac04333aa4975e3ae0236c4ca33bf88a:/Cycript.yy.in
diff --git a/Cycript.yy.in b/Cycript.yy.in
index 7ffc951..e1408da 100644
--- a/Cycript.yy.in
+++ b/Cycript.yy.in
@@ -1,20 +1,20 @@
/* Cycript - Optimizing JavaScript Compiler/Runtime
- * Copyright (C) 2009-2012 Jay Freeman (saurik)
+ * Copyright (C) 2009-2013 Jay Freeman (saurik)
*/
-/* GNU Lesser General Public License, Version 3 {{{ */
+/* GNU General Public License, Version 3 {{{ */
/*
- * Cycript is free software: you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by the
- * Free Software Foundation, either version 3 of the License, or (at your
- * option) any later version.
+ * Cycript is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation, either version 3 of the License,
+ * or (at your option) any later version.
*
- * Cycript is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for more details.
+ * Cycript is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
*
- * You should have received a copy of the GNU Lesser General Public License
+ * You should have received a copy of the GNU General Public License
* along with Cycript. If not, see .
**/
/* }}} */
@@ -28,6 +28,7 @@
@if Bison24 }
@if Bison24 %code requires {
+#include "Driver.hpp"
#include "Parser.hpp"
#define CYNew new($pool)
@@ -71,6 +72,7 @@ typedef struct {
CYInfix *infix_;
CYLiteral *literal_;
CYMember *member_;
+ CYModule *module_;
CYNull *null_;
CYNumber *number_;
CYProgram *program_;
@@ -81,9 +83,6 @@ typedef struct {
CYString *string_;
CYThis *this_;
CYTrue *true_;
- CYTypeModifier *type_;
- CYTypedIdentifier *typedIdentifier_;
- CYTypedParameter *typedParameter_;
CYWord *word_;
@begin ObjectiveC
@@ -93,6 +92,9 @@ typedef struct {
CYMessageParameter *messageParameter_;
CYProtocol *protocol_;
CYSelectorPart *selector_;
+ CYTypeModifier *modifier_;
+ CYTypedIdentifier *typedIdentifier_;
+ CYTypedParameter *typedParameter_;
@end
@begin E4X
@@ -223,10 +225,16 @@ int cylex(YYSTYPE *, cy::location *, void *);
%token OpenBracket "["
%token CloseBracket "]"
+%token AtError "@error"
+
@begin Java
%token AtClass "@class"
@end
+@begin C
+%token Typedef "typedef"
+@end
+
@begin ObjectiveC
%token AtImplementation "@implementation"
%token AtImplementation_ ";@implementation"
@@ -234,6 +242,8 @@ int cylex(YYSTYPE *, cy::location *, void *);
%token AtEncode "@encode"
%token AtEnd "@end"
%token AtSelector "@selector"
+%token Yes "YES"
+%token No "NO"
@end
%token False "false"
@@ -458,6 +468,7 @@ int cylex(YYSTYPE *, cy::location *, void *);
%type Variable
@begin ObjectiveC
+%type ArrayedType
%type BoxableExpression
%type CategoryStatement
%type ClassExpression
@@ -473,16 +484,17 @@ int cylex(YYSTYPE *, cy::location *, void *);
%type ClassProtocols
%type ClassProtocolsOpt
%type EncodedType
+%type FunctionedType
%type MessageExpression
%type MessageParameter
%type MessageParameters
%type MessageParameterList
%type MessageParameterListOpt
%type MessageScope
-%type ModifiedType
+%type ModifiedType
+%type Module
%type PrefixedType
%type PrimitiveType
-%type QualifiedType
%type SelectorCall_
%type SelectorCall
%type SelectorExpression_
@@ -492,6 +504,10 @@ int cylex(YYSTYPE *, cy::location *, void *);
%type SelectorWordOpt
%type SuffixedType
%type TypeOpt
+%type TypeParenthetical
+%type TypeQualifierLeft
+%type TypeQualifierRight
+%type TypeSignifier
%type TypedIdentifier
%type TypedParameterList_
%type TypedParameterList
@@ -557,8 +573,10 @@ LexNoFunction
: { if (yychar == yyempty_) driver.no_.Function = true; else if (yychar == token::Function) yychar = token::Function_; }
;
-LexNoAtImplementation
- : { if (yychar == yyempty_) driver.no_.AtImplementation = true; else if (yychar == token::AtImplementation) yychar = token::AtImplementation_; }
+LexNoAtImplementation :
+@begin ObjectiveC
+ { if (yychar == yyempty_) driver.no_.AtImplementation = true; else if (yychar == token::AtImplementation) yychar = token::AtImplementation_; }
+@end
;
LexSetStatement
@@ -640,6 +658,12 @@ WordOpt
Identifier
: Identifier_ { $$ = $1; }
+@begin C
+ | "typedef" { $$ = $1; }
+ | "YES" { $$ = $1; }
+ | "NO" { $$ = $1; }
+@end
+
| "implements" { $$ = $1; }
| "interface" { $$ = $1; }
| "package" { $$ = $1; }
@@ -741,7 +765,6 @@ PrimaryExpression
| Literal { $$ = $1; }
| ArrayLiteral { $$ = $1; }
| ObjectLiteral { $$ = $1; }
- | FunctionExpression { $$ = $1; }
| Parenthetical { $$ = $1; }
| AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; }
;
@@ -838,6 +861,7 @@ MemberExpression_
MemberExpression
: LexSetRegExp PrimaryExpression { $$ = $2; }
+ | LexSetRegExp FunctionExpression { $$ = $2; }
| MemberExpression_ { driver.context_ = $1; } MemberAccess { $3->SetLeft($1); $$ = $3; }
| LexSetRegExp "new" MemberExpression Arguments { $$ = CYNew cy::Syntax::New($3, $4); }
;
@@ -1346,40 +1370,59 @@ ProgramBodyOpt
@begin ObjectiveC
/* Cycript (Objective-C): Type Encoding {{{ */
+TypeParenthetical
+ : "(" LexPushInOff PrefixedType ")" LexPopIn { $$ = $3; }
+ ;
+
+TypeSignifier
+ : Identifier { $$ = CYNew CYTypedIdentifier($1); }
+ | TypeParenthetical { $$ = $1; }
+ ;
+
+ArrayedType
+ : ArrayedType "[" NumericLiteral "]" { $$ = $1; $$->modifier_ = CYNew CYTypeArrayOf($3, $$->modifier_); }
+ | TypeSignifier { $$ = $1; }
+ | { $$ = CYNew CYTypedIdentifier(); }
+ ;
+
+FunctionedType
+ : "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = CYNew CYTypeFunctionWith($3); }
+ ;
+
SuffixedType
- : IdentifierOpt { $$ = CYNew CYTypedIdentifier($1); }
- | "(" LexPushInOff PrefixedType ")" LexPopIn { $$ = $3; }
- | SuffixedType "[" NumericLiteral "]" { CYSetLast($1->type_) = CYNew CYTypeArrayOf($3->Value()); $$ = $1; }
+ : ArrayedType { $$ = $1; }
+ | "(" LexPushInOff "^" TypeQualifierRight ")" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn { $$ = $4; $$->modifier_ = CYNew CYTypeBlockWith($9, $$->modifier_); }
+ | TypeParenthetical FunctionedType { $$ = $1; CYSetLast($2) = $$->modifier_; $$->modifier_ = $2; }
+ | FunctionedType { $$ = CYNew CYTypedIdentifier(); CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
;
PrefixedType
- : SuffixedType { $$ = $1; }
- | "const" PrefixedType { CYSetLast($2->type_) = CYNew CYTypeConstant(); $$ = $2; }
- | "*" PrefixedType { CYSetLast($2->type_) = CYNew CYTypePointerTo(); $$ = $2; }
+ : "*" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
;
-PrimitiveType
- : Variable { $$ = $1; }
- | "void" { $$ = CYNew cy::Syntax::New(CYNew CYVariable(CYNew CYIdentifier("Type")), CYNew CYArgument(CYNew CYString("v"))); }
+TypeQualifierLeft
+ : "const" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeConstant(); }
+ /* XXX: | "volatile" TypeQualifierLeft { $$ = $2; CYSetLast($$) = CYNew CYTypeVolatile(); } */
+ | { $$ = NULL; }
;
-QualifiedType
- : PrimitiveType { $$ = CYNew CYTypeVariable($1); }
- | "const" QualifiedType { $$ = CYNew CYTypeConstant($2); }
+TypeQualifierRight
+ : "const" TypeQualifierRight { $$ = $2; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); }
+ | PrefixedType { $$ = $1; }
+ | SuffixedType { $$ = $1; }
;
-ModifiedType
- : QualifiedType { $$ = $1; }
- | QualifiedType "*" { $$ = CYNew CYTypePointerTo($1); }
- | QualifiedType "const" { $$ = CYNew CYTypeConstant($1); }
+PrimitiveType
+ : Variable { $$ = $1; }
+ | "void" { $$ = CYNew cy::Syntax::New(CYNew CYVariable(CYNew CYIdentifier("Type")), CYNew CYArgument(CYNew CYString("v"))); }
;
TypedIdentifier
- : QualifiedType PrefixedType { CYSetLast($2->type_) = $1; $$ = $2;}
+ : TypeQualifierLeft PrimitiveType TypeQualifierRight { $$ = $3; $$->type_ = $2; CYSetLast($1) = $$->modifier_; $$->modifier_ = $1; }
;
EncodedType
- : TypedIdentifier { $$ = CYNew CYEncodedType($1->type_); }
+ : TypedIdentifier { $$ = CYNew CYEncodedType($1); }
;
PrimaryExpression
@@ -1540,20 +1583,13 @@ PrimaryExpression
;
/* }}} */
/* Cycript (Objective-C): @import Directive {{{ */
-PathName
- : "/" PathName
- | "." PathName
- | Word PathName
- |
+Module
+ : Module "." Word { $$ = CYNew CYModule($3, $1); }
+ | Word { $$ = CYNew CYModule($1); }
;
-ImportPath
- : "<" PathName ">"
- | StringLiteral
- ;
-
-StatementListItem
- : LexSetStatement LexSetRegExp "@import" ImportPath { $$ = CYNew CYImport(); }
+Declaration__
+ : "@import" Module { $$ = CYNew CYImport($2); }
;
/* }}} */
/* Cycript (Objective-C): Boxed Expressions {{{ */
@@ -1565,6 +1601,8 @@ BoxableExpression
| ArrayLiteral { $$ = $1; }
| ObjectLiteral { $$ = $1; }
| Parenthetical { $$ = $1; }
+ | "YES" { $$ = CYNew CYTrue(); }
+ | "NO" { $$ = CYNew CYFalse(); }
;
PrimaryExpression
@@ -1572,18 +1610,9 @@ PrimaryExpression
;
/* }}} */
/* Cycript (Objective-C): Block Expressions {{{ */
-TypedParameterList_
- : "," TypedParameterList { $$ = $2; }
- | { $$ = NULL; }
- ;
-
-TypedParameterList
- : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
- ;
-
-TypedParameterListOpt
- : TypedParameterList { $$ = $1; }
- | { $$ = NULL; }
+ModifiedType
+ : TypeQualifierLeft PrimitiveType { $$ = CYNew CYTypedIdentifier(); $$->type_ = $2; $$->modifier_ = $1; }
+ | ModifiedType "*" { $$ = $1; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); }
;
PrimaryExpression
@@ -1613,6 +1642,30 @@ Var_
: "auto"
;
/* }}} */
+/* Cycript (C): Lambda Expressions {{{ */
+TypedParameterList_
+ : "," TypedParameterList { $$ = $2; }
+ | { $$ = NULL; }
+ ;
+
+TypedParameterList
+ : TypedIdentifier TypedParameterList_ { $$ = CYNew CYTypedParameter($1, $2); }
+ ;
+
+TypedParameterListOpt
+ : TypedParameterList { $$ = $1; }
+ | { $$ = NULL; }
+ ;
+
+PrimaryExpression
+ : "[" LexPushInOff LexSetRegExp "&" LexSetRegExp "]" LexPopIn "(" LexPushInOff TypedParameterListOpt ")" LexPopIn "->" TypedIdentifier BRACE LexPushInOff FunctionBody "}" LexPopIn { $$ = CYNew CYLambda($14, $10, $17); }
+ ;
+/* }}} */
+/* Cycript (C): Type Definitions {{{ */
+Statement__
+ : "typedef" TypedIdentifier Terminator { $$ = CYNew CYTypeDefinition($2); }
+ ;
+/* }}} */
@end
/* YUI: Documentation Comments {{{ */