X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/b10bd496b85e6ef23d311e5caec6cf1c954a63ce..1e7ce5572cfc83d260cbe73d66814f54e5760c37:/Cycript.y?ds=sidebyside diff --git a/Cycript.y b/Cycript.y index 42402f3..7fdc172 100644 --- a/Cycript.y +++ b/Cycript.y @@ -59,7 +59,6 @@ typedef struct { CYBoolean *boolean_; CYClause *clause_; CYCatch *catch_; - CYClass *class_; CYClassName *className_; CYComprehension *comprehension_; CYCompound *compound_; @@ -81,6 +80,7 @@ typedef struct { CYMessageParameter *messageParameter_; CYNull *null_; CYNumber *number_; + CYProgram *program_; CYProperty *property_; CYPropertyName *propertyName_; CYSelectorPart *selector_; @@ -117,6 +117,8 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %parse-param { CYDriver &driver } %lex-param { void *scanner } +%token At "@" + %token Ampersand "&" %token AmpersandAmpersand "&&" %token AmpersandEqual "&=" @@ -296,11 +298,12 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type CaseClausesOpt %type CatchOpt %type CategoryStatement -%type ClassDefinition +%type ClassExpression %type ClassMessageDeclaration %type ClassMessageDeclarationListOpt %type ClassName %type ClassNameOpt +%type ClassStatement %type ClassSuperOpt %type ClassFieldList %type ComprehensionList @@ -755,7 +758,7 @@ UnaryExpression_ | "\n++" UnaryExpression { $$ = new(driver.pool_) CYPreIncrement($2); } | "--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); } | "\n--" UnaryExpression { $$ = new(driver.pool_) CYPreDecrement($2); } - | "+" UnaryExpression { $$ = $2; } + | "+" UnaryExpression { $$ = new(driver.pool_) CYAffirm($2); } | "-" UnaryExpression { $$ = new(driver.pool_) CYNegate($2); } | "~" UnaryExpression { $$ = new(driver.pool_) CYBitwiseNot($2); } | "!" UnaryExpression { $$ = new(driver.pool_) CYLogicalNot($2); } @@ -1242,7 +1245,7 @@ DefaultClause /* }}} */ /* 12.12 Labelled Statements {{{ */ LabelledStatement - : Identifier ":" Statement { $3->AddLabel($1); $$ = $3; } + : Identifier ":" Statement { $$ = new(driver.pool_) CYLabel($1, $3); } ; /* }}} */ /* 12.13 The throw Statement {{{ */ @@ -1268,11 +1271,11 @@ FinallyOpt /* 13 Function Definition {{{ */ FunctionDeclaration - : "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunction($2, $4, $7); } + : "function" Identifier "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionStatement($2, $4, $7); } ; FunctionExpression - : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYLambda($2, $4, $7); } + : "function" IdentifierOpt "(" FormalParameterList ")" "{" FunctionBody "}" { $$ = new(driver.pool_) CYFunctionExpression($2, $4, $7); } ; FormalParameterList_ @@ -1291,7 +1294,7 @@ FunctionBody /* }}} */ /* 14 Program {{{ */ Program - : SourceElements { driver.program_ = $1; } + : SourceElements { driver.program_ = new(driver.pool_) CYProgram($1); } ; SourceElements @@ -1362,8 +1365,12 @@ ClassNameOpt | { $$ = NULL; } ; -ClassDefinition - : "@class" ClassNameOpt ClassSuperOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYClass($2, $3, $4, $5); } +ClassExpression + : "@class" ClassNameOpt ClassSuperOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYClassExpression($2, $3, $4, $5); } + ; + +ClassStatement + : "@class" ClassName ClassSuperOpt ClassFieldList ClassMessageDeclarationListOpt "@end" { $$ = new(driver.pool_) CYClassStatement($2, $3, $4, $5); } ; CategoryStatement @@ -1371,11 +1378,11 @@ CategoryStatement ; PrimaryExpression - : ClassDefinition { $$ = $1; } + : ClassExpression { $$ = $1; } ; Statement_ - : ClassDefinition { $$ = $1; } + : ClassStatement { $$ = $1; } | CategoryStatement { $$ = $1; } ; /* }}} */ @@ -1432,7 +1439,8 @@ UnaryExpression_ ; MemberAccess - : "->" Identifier { $$ = new(driver.pool_) CYIndirectMember(NULL, new(driver.pool_) CYString($2)); } + : "->" "[" Expression "]" { $$ = new(driver.pool_) CYIndirectMember(NULL, $3); } + | "->" Identifier { $$ = new(driver.pool_) CYIndirectMember(NULL, new(driver.pool_) CYString($2)); } ; /* }}} */ /* ECMAScript5: Object Literal Trailing Comma {{{ */