X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/63cd45c9666cbfb5b720e64148e0d5b7dbb60cbf..1e7ce5572cfc83d260cbe73d66814f54e5760c37:/Cycript.y diff --git a/Cycript.y b/Cycript.y index c83562c..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_; @@ -69,6 +68,7 @@ typedef struct { CYExpression *expression_; CYFalse *false_; CYField *field_; + CYFinally *finally_; CYForInitialiser *for_; CYForInInitialiser *forin_; CYFunctionParameter *functionParameter_; @@ -80,10 +80,10 @@ typedef struct { CYMessageParameter *messageParameter_; CYNull *null_; CYNumber *number_; + CYProgram *program_; CYProperty *property_; CYPropertyName *propertyName_; CYSelectorPart *selector_; - CYSource *source_; CYStatement *statement_; CYString *string_; CYThis *this_; @@ -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 @@ -328,7 +331,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type ExpressionNoIn_ %type ExpressionNoInOpt %type ExpressionStatement -%type FinallyOpt +%type FinallyOpt %type ForComprehension %type ForStatement %type ForStatementInitialiser @@ -336,8 +339,8 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type ForInStatementInitialiser %type FormalParameterList %type FormalParameterList_ -%type FunctionBody -%type FunctionDeclaration +%type FunctionBody +%type FunctionDeclaration %type FunctionExpression %type Identifier %type IdentifierOpt @@ -380,7 +383,7 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type PrimaryExpression %type PrimaryExpression_ %type PrimaryExpressionNoBF -%type Program +%type Program %type PropertyName %type PropertyNameAndValueList %type PropertyNameAndValueList_ @@ -398,9 +401,10 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %type SelectorExpressionOpt %type ShiftExpression %type ShiftExpressionNoBF -%type SourceElement -%type SourceElements +%type SourceElement +%type SourceElements %type Statement +%type Statement_ %type StatementList %type StatementListOpt %type SwitchStatement @@ -448,16 +452,23 @@ int cylex(YYSTYPE *lvalp, cy::location *llocp, void *scanner); %% -TerminatorOpt +StrictSemi + : { driver.Warning(yylloc, "warning, automatic semi-colon insertion required"); } + ; + +Terminator_ : ";" - | "\n" - | error { yyerrok; driver.errors_.pop_back(); } + | "\n" StrictSemi + ; + +TerminatorOpt + : Terminator_ + | error { yyerrok; driver.errors_.pop_back(); } StrictSemi ; Terminator - : ";" - | "\n" - | error { if (yychar != 0 && yychar != cy::parser::token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } + : Terminator_ + | error { if (yychar != 0 && yychar != cy::parser::token::CloseBrace && !yylval.newline_) YYABORT; else { yyerrok; driver.errors_.pop_back(); } } StrictSemi ; /*CommaOpt @@ -747,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); } @@ -1040,7 +1051,7 @@ ExpressionNoBF /* }}} */ /* 12 Statements {{{ */ -Statement +Statement_ : Block { $$ = $1; } | VariableStatement { $$ = $1; } | EmptyStatement { $$ = $1; } @@ -1056,6 +1067,10 @@ Statement | ThrowStatement { $$ = $1; } | TryStatement { $$ = $1; } ; + +Statement + : Statement_ { $$ = $1; } + ; /* }}} */ /* 12.1 Block {{{ */ Block_ @@ -1230,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 {{{ */ @@ -1249,18 +1264,18 @@ CatchOpt ; FinallyOpt - : "finally" Block_ { $$ = $2; } + : "finally" Block_ { $$ = new(driver.pool_) CYFinally($2); } | { $$ = NULL; } ; /* }}} */ /* 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_ @@ -1279,7 +1294,7 @@ FunctionBody /* }}} */ /* 14 Program {{{ */ Program - : SourceElements { driver.source_ = $1; } + : SourceElements { driver.program_ = new(driver.pool_) CYProgram($1); } ; SourceElements @@ -1288,7 +1303,7 @@ SourceElements ; SourceElement - : Statement { $$ = $1; } + : Statement_ { $$ = $1; } | FunctionDeclaration { $$ = $1; } ; /* }}} */ @@ -1350,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 @@ -1359,11 +1378,11 @@ CategoryStatement ; PrimaryExpression - : ClassDefinition { $$ = $1; } + : ClassExpression { $$ = $1; } ; -Statement - : ClassDefinition { $$ = $1; } +Statement_ + : ClassStatement { $$ = $1; } | CategoryStatement { $$ = $1; } ; /* }}} */ @@ -1420,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 {{{ */ @@ -1457,7 +1477,7 @@ ForInStatement : "for" "each" "(" ForInStatementInitialiser "in" Expression ")" Statement { $$ = new(driver.pool_) CYForEachIn($4, $6, $8); } ; /* }}} */ -/* JavaScript 1.7: Let Statements {{{ *//* +/* JavaScript 1.7: let Statements {{{ *//* LetStatement : "let" "(" VariableDeclarationList ")" Block_ { $$ = new(driver.pool_) CYLet($3, $5); } ; @@ -1466,5 +1486,10 @@ Statement : LetStatement ; *//* }}} */ +/* JavaScript FTW: Function Statements {{{ */ +Statement + : FunctionDeclaration { driver.Warning(yylloc, "warning, FunctionDeclaration is a SourceElement, not a Statement"); } { $$ = $1; } + ; +/* }}} */ %%