X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/457afcc98a03ef56c699cff9f468813567f10182..2b0ddce2b9c3e24fb95f78afaa88e326c61c3085:/Cycript.y?ds=inline diff --git a/Cycript.y b/Cycript.y index 8d5c257..31fd1bc 100644 --- a/Cycript.y +++ b/Cycript.y @@ -29,6 +29,7 @@ typedef struct { CYNumber *number_; CYParameter *parameter_; CYProperty *property_; + CYSelectorPart *selector_; CYSource *source_; CYStatement *statement_; CYString *string_; @@ -118,6 +119,8 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %token OpenBracket "[" %token CloseBracket "]" +%token AtSelector "@selector" + %token Break "break" %token Case "case" %token Catch "catch" @@ -186,8 +189,9 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type DefaultClause %type DoWhileStatement %type Element +%type ElementOpt %type ElementList -%type ElementList_ +%type ElementListOpt %type ElseStatementOpt %type EmptyStatement %type EqualityExpression @@ -253,6 +257,9 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type RelationalExpressionNoBF %type RelationalExpressionNoIn %type ReturnStatement +%type SelectorExpression +%type SelectorExpression_ +%type SelectorExpressionOpt %type ShiftExpression %type ShiftExpressionNoBF %type SourceElement @@ -294,13 +301,13 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); TerminatorOpt : ";" | "\n" - | error { yyerrok; } + | error { yyerrok; driver.errors_.pop_back(); } ; Terminator : ";" | "\n" - | error { if (yychar != 0 && yychar != cy::parser::token::CloseBrace && !yylval.newline_) YYABORT; else yyerrok; } + | error { if (yychar != 0 && yychar != cy::parser::token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } ; CommaOpt @@ -391,26 +398,31 @@ PrimaryExpressionNoBF /* }}} */ /* 11.1.4 Array Initialiser {{{ */ ArrayLiteral - : "[" ElementList "]" { $$ = $2; } + : "[" ElementList "]" { $$ = new(driver.pool_) CYArray($2); } ; Element : AssignmentExpression { $$ = $1; } + ; + +ElementOpt + : Element { $$ = $1; } | { $$ = NULL; } ; -ElementList_ - : "," ElementList { $$ = $2; } +ElementListOpt + : ElementList { $$ = $1; } | { $$ = NULL; } ; ElementList - : Element ElementList_ { $$ = new(driver.pool_) CYElement($1, $2); } + : ElementOpt "," ElementListOpt { $$ = new(driver.pool_) CYElement($1, $3); } + | Element { $$ = new(driver.pool_) CYElement($1, NULL); } ; /* }}} */ /* 11.1.5 Object Initialiser {{{ */ ObjectLiteral - : "{" PropertyNameAndValueListOpt "}" { $$ = new CYObject($2); } + : "{" PropertyNameAndValueListOpt "}" { $$ = new(driver.pool_) CYObject($2); } ; PropertyNameAndValueList_ @@ -828,8 +840,7 @@ Statement ; Block - : "{" "}" { $$ = new(driver.pool_) CYEmpty(); } - | "{" StatementList "}" { $$ = $2; } + : "{" StatementListOpt "}" { $$ = $2 ?: new(driver.pool_) CYEmpty(); } ; StatementList @@ -1022,7 +1033,7 @@ FunctionBody ; Program - : SourceElements { driver.source_.push_back($1); $$ = $1; } + : SourceElements { driver.source_ = $1; } ; SourceElements @@ -1030,10 +1041,6 @@ SourceElements | { $$ = NULL; } ; -/*Command - : SourceElement { driver.source_.push_back($2); if (driver.filename_.empty() && false) YYACCEPT; $2->Show(std::cout); } - ;*/ - SourceElement : Statement { $$ = $1; } | FunctionDeclaration { $$ = $1; } @@ -1063,8 +1070,23 @@ MessageExpression : "[" AssignmentExpression SelectorList "]" { $$ = new(driver.pool_) CYMessage($2, $3); } ; +SelectorExpressionOpt + : SelectorExpression_ { $$ = $1; } + | { $$ = NULL; } + ; + +SelectorExpression_ + : WordOpt ":" SelectorExpressionOpt { $$ = new(driver.pool_) CYSelectorPart($1, true, $3); } + ; + +SelectorExpression + : SelectorExpression_ { $$ = $1; } + | Word { $$ = new(driver.pool_) CYSelectorPart($1, false, NULL); } + ; + PrimaryExpression_ : MessageExpression { $$ = $1; } + | "@selector" "(" SelectorExpression ")" { $$ = new CYSelector($3); } ; /* }}} */