| 1 | /* Cycript - The Truly Universal Scripting Language |
| 2 | * Copyright (C) 2009-2016 Jay Freeman (saurik) |
| 3 | */ |
| 4 | |
| 5 | /* GNU Affero General Public License, Version 3 {{{ */ |
| 6 | /* |
| 7 | * This program is free software: you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation, either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU Affero General Public License for more details. |
| 16 | |
| 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | **/ |
| 20 | /* }}} */ |
| 21 | |
| 22 | %code top { |
| 23 | #define YYSTACKEXPANDABLE 1 |
| 24 | } |
| 25 | |
| 26 | %code requires { |
| 27 | #include "Driver.hpp" |
| 28 | #include "Parser.hpp" |
| 29 | #include "Stack.hpp" |
| 30 | #include "Syntax.hpp" |
| 31 | #define CYNew new(driver.pool_) |
| 32 | |
| 33 | @begin ObjectiveC |
| 34 | #include "ObjectiveC/Syntax.hpp" |
| 35 | @end |
| 36 | |
| 37 | @begin E4X |
| 38 | #include "E4X/Syntax.hpp" |
| 39 | @end |
| 40 | |
| 41 | #include "Highlight.hpp" |
| 42 | } |
| 43 | |
| 44 | %union { bool bool_; } |
| 45 | |
| 46 | %union { CYMember *access_; } |
| 47 | %union { CYArgument *argument_; } |
| 48 | %union { CYAssignment *assignment_; } |
| 49 | %union { CYBinding *binding_; } |
| 50 | %union { CYBindings *bindings_; } |
| 51 | %union { CYBoolean *boolean_; } |
| 52 | %union { CYBraced *braced_; } |
| 53 | %union { CYClause *clause_; } |
| 54 | %union { cy::Syntax::Catch *catch_; } |
| 55 | %union { CYClassTail *classTail_; } |
| 56 | %union { CYComprehension *comprehension_; } |
| 57 | %union { CYElement *element_; } |
| 58 | %union { CYEnumConstant *constant_; } |
| 59 | %union { CYExpression *expression_; } |
| 60 | %union { CYFalse *false_; } |
| 61 | %union { CYVariable *variable_; } |
| 62 | %union { CYFinally *finally_; } |
| 63 | %union { CYForInitializer *for_; } |
| 64 | %union { CYForInInitializer *forin_; } |
| 65 | %union { CYFunctionParameter *functionParameter_; } |
| 66 | %union { CYIdentifier *identifier_; } |
| 67 | %union { CYImportSpecifier *import_; } |
| 68 | %union { CYInfix *infix_; } |
| 69 | %union { CYLiteral *literal_; } |
| 70 | %union { CYMethod *method_; } |
| 71 | %union { CYModule *module_; } |
| 72 | %union { CYNull *null_; } |
| 73 | %union { CYNumber *number_; } |
| 74 | %union { CYParenthetical *parenthetical_; } |
| 75 | %union { CYProperty *property_; } |
| 76 | %union { CYPropertyName *propertyName_; } |
| 77 | %union { CYTypeSigning signing_; } |
| 78 | %union { CYSpan *span_; } |
| 79 | %union { CYStatement *statement_; } |
| 80 | %union { CYString *string_; } |
| 81 | %union { CYTarget *target_; } |
| 82 | %union { CYThis *this_; } |
| 83 | %union { CYTrue *true_; } |
| 84 | %union { CYWord *word_; } |
| 85 | |
| 86 | @begin C |
| 87 | %union { CYTypeIntegral *integral_; } |
| 88 | %union { CYTypeStructField *structField_; } |
| 89 | %union { CYTypeModifier *modifier_; } |
| 90 | %union { CYTypeSpecifier *specifier_; } |
| 91 | %union { CYTypedFormal *typedFormal_; } |
| 92 | %union { CYTypedLocation *typedLocation_; } |
| 93 | %union { CYTypedName *typedName_; } |
| 94 | %union { CYTypedParameter *typedParameter_; } |
| 95 | %union { CYType *typedThing_; } |
| 96 | @end |
| 97 | |
| 98 | @begin ObjectiveC |
| 99 | %union { CYObjCKeyValue *keyValue_; } |
| 100 | %union { CYImplementationField *implementationField_; } |
| 101 | %union { CYMessage *message_; } |
| 102 | %union { CYMessageParameter *messageParameter_; } |
| 103 | %union { CYProtocol *protocol_; } |
| 104 | %union { CYSelectorPart *selector_; } |
| 105 | @end |
| 106 | |
| 107 | @begin E4X |
| 108 | %union { CYAttribute *attribute_; } |
| 109 | %union { CYPropertyIdentifier *propertyIdentifier_; } |
| 110 | %union { CYSelector *selector_; } |
| 111 | @end |
| 112 | |
| 113 | %code provides { |
| 114 | |
| 115 | struct YYSTYPE { |
| 116 | cy::parser::semantic_type semantic_; |
| 117 | hi::Value highlight_; |
| 118 | }; |
| 119 | |
| 120 | int cylex(YYSTYPE *, CYLocation *, void *); |
| 121 | |
| 122 | } |
| 123 | |
| 124 | %code { |
| 125 | |
| 126 | #undef yylex |
| 127 | |
| 128 | typedef cy::parser::token tk; |
| 129 | |
| 130 | _finline int cylex_(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) { |
| 131 | driver.newline_ = false; |
| 132 | lex: |
| 133 | YYSTYPE data; |
| 134 | int token(cylex(&data, location, driver.scanner_)); |
| 135 | *semantic = data.semantic_; |
| 136 | |
| 137 | switch (token) { |
| 138 | case tk::OpenBrace: |
| 139 | case tk::OpenBracket: |
| 140 | case tk::OpenParen: |
| 141 | driver.in_.push(false); |
| 142 | break; |
| 143 | |
| 144 | case tk::_in_: |
| 145 | if (driver.in_.top()) |
| 146 | token = tk::_in__; |
| 147 | break; |
| 148 | |
| 149 | case tk::CloseBrace: |
| 150 | case tk::CloseBracket: |
| 151 | case tk::CloseParen: |
| 152 | driver.in_.pop(); |
| 153 | break; |
| 154 | |
| 155 | |
| 156 | case tk::_yield_: |
| 157 | if (driver.yield_.top()) |
| 158 | token = tk::_yield__; |
| 159 | break; |
| 160 | |
| 161 | case tk::NewLine: |
| 162 | driver.newline_ = true; |
| 163 | goto lex; |
| 164 | break; |
| 165 | } |
| 166 | |
| 167 | return token; |
| 168 | } |
| 169 | |
| 170 | #define yylex_(semantic, location, driver) ({ \ |
| 171 | int type; \ |
| 172 | if (driver.hold_ == cy::parser::empty_symbol) \ |
| 173 | type = yytranslate_(cylex_(semantic, location, driver)); \ |
| 174 | else { \ |
| 175 | type = driver.hold_; \ |
| 176 | driver.hold_ = cy::parser::empty_symbol; \ |
| 177 | } \ |
| 178 | type; }) |
| 179 | |
| 180 | #define CYLEX() do if (yyla.empty()) { \ |
| 181 | YYCDEBUG << "Mapping a token: "; \ |
| 182 | yyla.type = yylex_(&yyla.value, &yyla.location, driver); \ |
| 183 | YY_SYMBOL_PRINT("Next token is", yyla); \ |
| 184 | } while (false) |
| 185 | |
| 186 | #define CYMAP(to, from) do { \ |
| 187 | CYLEX(); \ |
| 188 | if (yyla.type == yytranslate_(token::from)) \ |
| 189 | yyla.type = yytranslate_(token::to); \ |
| 190 | } while (false) |
| 191 | |
| 192 | #define CYHLD(location, token) do { \ |
| 193 | if (driver.hold_ != empty_symbol) \ |
| 194 | CYERR(location, "unexpected hold"); \ |
| 195 | driver.hold_ = yyla.type; \ |
| 196 | yyla.type = yytranslate_(token); \ |
| 197 | } while (false) |
| 198 | |
| 199 | #define CYERR(location, message) do { \ |
| 200 | error(location, message); \ |
| 201 | YYABORT; \ |
| 202 | } while (false) |
| 203 | |
| 204 | #define CYEOK() do { \ |
| 205 | yyerrok; \ |
| 206 | driver.errors_.pop_back(); \ |
| 207 | } while (false) |
| 208 | |
| 209 | #define CYNOT(location) \ |
| 210 | CYERR(location, "unimplemented feature") |
| 211 | |
| 212 | #define CYMPT(location) do { \ |
| 213 | if (!yyla.empty() && yyla.type_get() != yyeof_) \ |
| 214 | CYERR(location, "unexpected lookahead"); \ |
| 215 | } while (false) |
| 216 | |
| 217 | } |
| 218 | |
| 219 | %name-prefix "cy" |
| 220 | |
| 221 | %language "C++" |
| 222 | |
| 223 | %initial-action { |
| 224 | @$.begin.filename = @$.end.filename = &driver.filename_; |
| 225 | |
| 226 | switch (driver.mark_) { |
| 227 | case CYMarkScript: |
| 228 | driver.hold_ = yytranslate_(token::MarkScript); |
| 229 | break; |
| 230 | case CYMarkModule: |
| 231 | driver.hold_ = yytranslate_(token::MarkModule); |
| 232 | break; |
| 233 | case CYMarkExpression: |
| 234 | driver.hold_ = yytranslate_(token::MarkExpression); |
| 235 | break; |
| 236 | } |
| 237 | }; |
| 238 | |
| 239 | %locations |
| 240 | %defines |
| 241 | |
| 242 | %define api.location.type { CYLocation } |
| 243 | |
| 244 | //%glr-parser |
| 245 | //%expect 1 |
| 246 | |
| 247 | %error-verbose |
| 248 | |
| 249 | %param { CYDriver &driver } |
| 250 | |
| 251 | /* Token Declarations {{{ */ |
| 252 | @begin E4X |
| 253 | %token XMLCDATA |
| 254 | %token XMLComment |
| 255 | %token XMLPI |
| 256 | |
| 257 | %token XMLAttributeValue |
| 258 | %token XMLName |
| 259 | %token XMLTagCharacters |
| 260 | %token XMLText |
| 261 | %token XMLWhitespace |
| 262 | @end |
| 263 | |
| 264 | @begin E4X |
| 265 | %token LeftRight "<>" |
| 266 | %token LeftSlashRight "</>" |
| 267 | |
| 268 | %token SlashRight "/>" |
| 269 | %token LeftSlash "</" |
| 270 | |
| 271 | %token PeriodPeriod ".." |
| 272 | @end |
| 273 | |
| 274 | @begin E4X ObjectiveC |
| 275 | %token At "@" |
| 276 | @end |
| 277 | |
| 278 | %token Ampersand "&" |
| 279 | %token AmpersandAmpersand "&&" |
| 280 | %token AmpersandEqual "&=" |
| 281 | %token Carrot "^" |
| 282 | %token CarrotEqual "^=" |
| 283 | %token Equal "=" |
| 284 | %token EqualEqual "==" |
| 285 | %token EqualEqualEqual "===" |
| 286 | %token EqualRight "=>" |
| 287 | %token Exclamation "!" |
| 288 | %token ExclamationEqual "!=" |
| 289 | %token ExclamationEqualEqual "!==" |
| 290 | %token Hyphen "-" |
| 291 | %token HyphenEqual "-=" |
| 292 | %token HyphenHyphen "--" |
| 293 | %token HyphenRight "->" |
| 294 | %token Left "<" |
| 295 | %token LeftEqual "<=" |
| 296 | %token LeftLeft "<<" |
| 297 | %token LeftLeftEqual "<<=" |
| 298 | %token Percent "%" |
| 299 | %token PercentEqual "%=" |
| 300 | %token Period "." |
| 301 | %token PeriodPeriodPeriod "..." |
| 302 | %token Pipe "|" |
| 303 | %token PipeEqual "|=" |
| 304 | %token PipePipe "||" |
| 305 | %token Plus "+" |
| 306 | %token PlusEqual "+=" |
| 307 | %token PlusPlus "++" |
| 308 | %token QuestionPeriod "?." |
| 309 | %token Right ">" |
| 310 | %token RightEqual ">=" |
| 311 | %token RightRight ">>" |
| 312 | %token RightRightEqual ">>=" |
| 313 | %token RightRightRight ">>>" |
| 314 | %token RightRightRightEqual ">>>=" |
| 315 | %token Slash "/" |
| 316 | %token SlashEqual "/=" |
| 317 | %token Star "*" |
| 318 | %token StarEqual "*=" |
| 319 | %token Tilde "~" |
| 320 | |
| 321 | %token Colon ":" |
| 322 | %token ColonColon "::" |
| 323 | %token Comma "," |
| 324 | %token Question "?" |
| 325 | %token SemiColon ";" |
| 326 | %token Pound "#" |
| 327 | %token NewLine "\n" |
| 328 | %token __ "" |
| 329 | |
| 330 | %token Comment |
| 331 | |
| 332 | %token OpenParen "(" |
| 333 | %token CloseParen ")" |
| 334 | |
| 335 | %token OpenBrace "{" |
| 336 | %token OpenBrace_ ";{" |
| 337 | %token OpenBrace_let "let {" |
| 338 | %token CloseBrace "}" |
| 339 | |
| 340 | %token OpenBracket "[" |
| 341 | %token OpenBracket_let "let [" |
| 342 | %token CloseBracket "]" |
| 343 | |
| 344 | %token At_error_ "@error" |
| 345 | |
| 346 | @begin Java |
| 347 | %token At_class_ "@class" |
| 348 | @end |
| 349 | |
| 350 | @begin C |
| 351 | %token _typedef_ "typedef" |
| 352 | %token _unsigned_ "unsigned" |
| 353 | %token _signed_ "signed" |
| 354 | %token _struct_ "struct" |
| 355 | %token _extern_ "extern" |
| 356 | @end |
| 357 | |
| 358 | @begin C |
| 359 | %token At_encode_ "@encode" |
| 360 | @end |
| 361 | |
| 362 | @begin ObjectiveC |
| 363 | %token At_implementation_ "@implementation" |
| 364 | %token At_import_ "@import" |
| 365 | %token At_end_ "@end" |
| 366 | %token At_selector_ "@selector" |
| 367 | %token At_null_ "@null" |
| 368 | %token At_YES_ "@YES" |
| 369 | %token At_NO_ "@NO" |
| 370 | %token At_true_ "@true" |
| 371 | %token At_false_ "@false" |
| 372 | %token _YES_ "YES" |
| 373 | %token _NO_ "NO" |
| 374 | @end |
| 375 | |
| 376 | %token _false_ "false" |
| 377 | %token _null_ "null" |
| 378 | %token _true_ "true" |
| 379 | |
| 380 | %token _as_ "as" |
| 381 | %token _break_ "break" |
| 382 | %token _case_ "case" |
| 383 | %token _catch_ "catch" |
| 384 | %token _class_ "class" |
| 385 | %token _class__ ";class" |
| 386 | %token _const_ "const" |
| 387 | %token _continue_ "continue" |
| 388 | %token _debugger_ "debugger" |
| 389 | %token _default_ "default" |
| 390 | %token _delete_ "delete" |
| 391 | %token _do_ "do" |
| 392 | %token _else_ "else" |
| 393 | %token _enum_ "enum" |
| 394 | %token _export_ "export" |
| 395 | %token _extends_ "extends" |
| 396 | %token _finally_ "finally" |
| 397 | %token _for_ "for" |
| 398 | %token _function_ "function" |
| 399 | %token _function__ ";function" |
| 400 | %token _if_ "if" |
| 401 | %token _import_ "import" |
| 402 | %token _in_ "in" |
| 403 | %token _in__ "!in" |
| 404 | %token _Infinity_ "Infinity" |
| 405 | %token _instanceof_ "instanceof" |
| 406 | %token _new_ "new" |
| 407 | %token _return_ "return" |
| 408 | %token _super_ "super" |
| 409 | %token _switch_ "switch" |
| 410 | %token _target_ "target" |
| 411 | %token _this_ "this" |
| 412 | %token _throw_ "throw" |
| 413 | %token _try_ "try" |
| 414 | %token _typeof_ "typeof" |
| 415 | %token _var_ "var" |
| 416 | %token _void_ "void" |
| 417 | %token _while_ "while" |
| 418 | %token _with_ "with" |
| 419 | |
| 420 | %token _abstract_ "abstract" |
| 421 | %token _await_ "await" |
| 422 | %token _boolean_ "boolean" |
| 423 | %token _byte_ "byte" |
| 424 | %token _char_ "char" |
| 425 | %token _constructor_ "constructor" |
| 426 | %token _double_ "double" |
| 427 | %token _eval_ "eval" |
| 428 | %token _final_ "final" |
| 429 | %token _float_ "float" |
| 430 | %token _from_ "from" |
| 431 | %token _get_ "get" |
| 432 | %token _goto_ "goto" |
| 433 | %token _implements_ "implements" |
| 434 | %token _int_ "int" |
| 435 | %token ___int128_ "__int128" |
| 436 | %token _interface_ "interface" |
| 437 | %token _let_ "let" |
| 438 | %token _let__ "!let" |
| 439 | %token _long_ "long" |
| 440 | %token _native_ "native" |
| 441 | %token _package_ "package" |
| 442 | %token _private_ "private" |
| 443 | %token _protected_ "protected" |
| 444 | %token ___proto___ "__proto__" |
| 445 | %token _prototype_ "prototype" |
| 446 | %token _public_ "public" |
| 447 | %token _set_ "set" |
| 448 | %token _short_ "short" |
| 449 | %token _static_ "static" |
| 450 | %token _synchronized_ "synchronized" |
| 451 | %token _throws_ "throws" |
| 452 | %token _transient_ "transient" |
| 453 | %token _typeid_ "typeid" |
| 454 | %token _volatile_ "volatile" |
| 455 | %token _yield_ "yield" |
| 456 | %token _yield__ "!yield" |
| 457 | |
| 458 | %token _undefined_ "undefined" |
| 459 | |
| 460 | @begin ObjectiveC |
| 461 | %token _bool_ "bool" |
| 462 | %token _BOOL_ "BOOL" |
| 463 | %token _id_ "id" |
| 464 | %token _nil_ "nil" |
| 465 | %token _NULL_ "NULL" |
| 466 | %token _SEL_ "SEL" |
| 467 | @end |
| 468 | |
| 469 | %token _each_ "each" |
| 470 | %token _of_ "of" |
| 471 | %token _of__ "!of" |
| 472 | |
| 473 | @begin E4X |
| 474 | %token _namespace_ "namespace" |
| 475 | %token _xml_ "xml" |
| 476 | @end |
| 477 | |
| 478 | %token AutoComplete |
| 479 | %token YieldStar "yield *" |
| 480 | |
| 481 | %token <identifier_> Identifier_ |
| 482 | %token <number_> NumericLiteral |
| 483 | %token <string_> StringLiteral |
| 484 | %token <literal_> RegularExpressionLiteral_ |
| 485 | |
| 486 | %token <string_> NoSubstitutionTemplate |
| 487 | %token <string_> TemplateHead |
| 488 | %token <string_> TemplateMiddle |
| 489 | %token <string_> TemplateTail |
| 490 | |
| 491 | %type <target_> AccessExpression |
| 492 | %type <expression_> AdditiveExpression |
| 493 | %type <argument_> ArgumentList_ |
| 494 | %type <argument_> ArgumentList |
| 495 | %type <argument_> ArgumentListOpt |
| 496 | %type <argument_> Arguments |
| 497 | %type <target_> ArrayComprehension |
| 498 | %type <element_> ArrayElement |
| 499 | %type <literal_> ArrayLiteral |
| 500 | %type <expression_> ArrowFunction |
| 501 | %type <functionParameter_> ArrowParameters |
| 502 | %type <expression_> AssignmentExpression |
| 503 | %type <identifier_> BindingIdentifier |
| 504 | %type <identifier_> BindingIdentifierOpt |
| 505 | %type <bindings_> BindingList_ |
| 506 | %type <bindings_> BindingList |
| 507 | %type <expression_> BitwiseANDExpression |
| 508 | %type <statement_> Block |
| 509 | %type <statement_> BlockStatement |
| 510 | %type <boolean_> BooleanLiteral |
| 511 | %type <binding_> BindingElement |
| 512 | %type <expression_> BitwiseORExpression |
| 513 | %type <expression_> BitwiseXORExpression |
| 514 | %type <target_> BracedExpression_ |
| 515 | %type <target_> BracedExpression |
| 516 | %type <statement_> BreakStatement |
| 517 | %type <statement_> BreakableStatement |
| 518 | %type <expression_> CallExpression_ |
| 519 | %type <target_> CallExpression |
| 520 | %type <clause_> CaseBlock |
| 521 | %type <clause_> CaseClause |
| 522 | %type <clause_> CaseClausesOpt |
| 523 | %type <catch_> Catch |
| 524 | %type <identifier_> CatchParameter |
| 525 | %type <statement_> ClassDeclaration |
| 526 | %type <target_> ClassExpression |
| 527 | %type <classTail_> ClassHeritage |
| 528 | %type <classTail_> ClassHeritageOpt |
| 529 | %type <classTail_> ClassTail |
| 530 | %type <target_> Comprehension |
| 531 | %type <comprehension_> ComprehensionFor |
| 532 | %type <comprehension_> ComprehensionIf |
| 533 | %type <comprehension_> ComprehensionTail |
| 534 | %type <propertyName_> ComputedPropertyName |
| 535 | %type <expression_> ConditionalExpression |
| 536 | %type <statement_> ContinueStatement |
| 537 | %type <statement_> ConciseBody |
| 538 | %type <parenthetical_> CoverParenthesizedExpressionAndArrowParameterList |
| 539 | %type <statement_> DebuggerStatement |
| 540 | %type <statement_> Declaration_ |
| 541 | %type <statement_> Declaration |
| 542 | %type <clause_> DefaultClause |
| 543 | %type <element_> ElementList_ |
| 544 | %type <element_> ElementList |
| 545 | %type <element_> ElementListOpt |
| 546 | %type <statement_> ElseStatementOpt |
| 547 | %type <for_> EmptyStatement |
| 548 | %type <expression_> EqualityExpression |
| 549 | %type <expression_> Expression |
| 550 | %type <expression_> ExpressionOpt |
| 551 | %type <for_> ExpressionStatement_ |
| 552 | %type <statement_> ExpressionStatement |
| 553 | %type <statement_> ExternC |
| 554 | %type <statement_> ExternCStatement |
| 555 | %type <statement_> ExternCStatementListOpt |
| 556 | %type <finally_> Finally |
| 557 | %type <binding_> ForBinding |
| 558 | %type <forin_> ForDeclaration |
| 559 | %type <forin_> ForInStatementInitializer |
| 560 | %type <for_> ForStatementInitializer |
| 561 | %type <binding_> FormalParameter |
| 562 | %type <functionParameter_> FormalParameterList_ |
| 563 | %type <functionParameter_> FormalParameterList |
| 564 | %type <functionParameter_> FormalParameters |
| 565 | %type <string_> FromClause |
| 566 | %type <statement_> FunctionBody |
| 567 | %type <statement_> FunctionDeclaration |
| 568 | %type <target_> FunctionExpression |
| 569 | %type <statement_> FunctionStatementList |
| 570 | %type <statement_> GeneratorBody |
| 571 | %type <statement_> GeneratorDeclaration |
| 572 | %type <target_> GeneratorExpression |
| 573 | %type <method_> GeneratorMethod |
| 574 | %type <statement_> HoistableDeclaration |
| 575 | %type <identifier_> Identifier |
| 576 | %type <identifier_> IdentifierNoOf |
| 577 | %type <identifier_> IdentifierType |
| 578 | %type <identifier_> IdentifierTypeNoOf |
| 579 | %type <identifier_> IdentifierTypeOpt |
| 580 | %type <word_> IdentifierName |
| 581 | %type <variable_> IdentifierReference |
| 582 | %type <statement_> IfStatement |
| 583 | %type <import_> ImportClause |
| 584 | %type <statement_> ImportDeclaration |
| 585 | %type <import_> ImportSpecifier |
| 586 | %type <identifier_> ImportedBinding |
| 587 | %type <import_> ImportedDefaultBinding |
| 588 | %type <import_> ImportsList_ |
| 589 | %type <import_> ImportsList |
| 590 | %type <import_> ImportsListOpt |
| 591 | %type <target_> IndirectExpression |
| 592 | %type <expression_> Initializer |
| 593 | %type <expression_> InitializerOpt |
| 594 | %type <statement_> IterationStatement |
| 595 | %type <identifier_> LabelIdentifier |
| 596 | %type <statement_> LabelledItem |
| 597 | %type <statement_> LabelledStatement |
| 598 | %type <assignment_> LeftHandSideAssignment |
| 599 | %type <target_> LeftHandSideExpression |
| 600 | %type <bool_> LetOrConst |
| 601 | %type <binding_> LexicalBinding |
| 602 | %type <for_> LexicalDeclaration_ |
| 603 | %type <statement_> LexicalDeclaration |
| 604 | %type <literal_> Literal |
| 605 | %type <propertyName_> LiteralPropertyName |
| 606 | %type <expression_> LogicalANDExpression |
| 607 | %type <expression_> LogicalORExpression |
| 608 | %type <access_> MemberAccess |
| 609 | %type <target_> MemberExpression |
| 610 | %type <method_> MethodDefinition |
| 611 | %type <statement_> ModuleBody |
| 612 | %type <statement_> ModuleBodyOpt |
| 613 | %type <statement_> ModuleItem |
| 614 | %type <statement_> ModuleItemList |
| 615 | %type <statement_> ModuleItemListOpt |
| 616 | %type <module_> ModulePath |
| 617 | %type <string_> ModuleSpecifier |
| 618 | %type <expression_> MultiplicativeExpression |
| 619 | %type <import_> NameSpaceImport |
| 620 | %type <import_> NamedImports |
| 621 | %type <target_> NewExpression |
| 622 | %type <null_> NullLiteral |
| 623 | %type <literal_> ObjectLiteral |
| 624 | %type <expression_> PostfixExpression |
| 625 | %type <target_> PrimaryExpression |
| 626 | %type <propertyName_> PropertyName |
| 627 | %type <property_> PropertyDefinition |
| 628 | %type <property_> PropertyDefinitionList_ |
| 629 | %type <property_> PropertyDefinitionList |
| 630 | %type <property_> PropertyDefinitionListOpt |
| 631 | %type <functionParameter_> PropertySetParameterList |
| 632 | %type <literal_> RegularExpressionLiteral |
| 633 | %type <bool_> RegularExpressionSlash |
| 634 | %type <expression_> RelationalExpression |
| 635 | %type <statement_> ReturnStatement |
| 636 | %type <braced_> BracedParameter |
| 637 | %type <functionParameter_> RubyProcParameterList_ |
| 638 | %type <functionParameter_> RubyProcParameterList |
| 639 | %type <functionParameter_> RubyProcParameters |
| 640 | %type <functionParameter_> RubyProcParametersOpt |
| 641 | %type <statement_> Script |
| 642 | %type <statement_> ScriptBody |
| 643 | %type <statement_> ScriptBodyOpt |
| 644 | %type <expression_> ShiftExpression |
| 645 | %type <binding_> SingleNameBinding |
| 646 | %type <statement_> Statement__ |
| 647 | %type <statement_> Statement_ |
| 648 | %type <statement_> Statement |
| 649 | %type <statement_> StatementList |
| 650 | %type <statement_> StatementListOpt |
| 651 | %type <statement_> StatementListItem |
| 652 | %type <functionParameter_> StrictFormalParameters |
| 653 | %type <target_> SuperCall |
| 654 | %type <target_> SuperProperty |
| 655 | %type <statement_> SwitchStatement |
| 656 | %type <target_> TemplateLiteral |
| 657 | %type <span_> TemplateSpans |
| 658 | %type <statement_> ThrowStatement |
| 659 | %type <statement_> TryStatement |
| 660 | %type <statement_> TypeDefinition |
| 661 | %type <expression_> UnaryExpression_ |
| 662 | %type <expression_> UnaryExpression |
| 663 | %type <binding_> VariableDeclaration |
| 664 | %type <bindings_> VariableDeclarationList_ |
| 665 | %type <bindings_> VariableDeclarationList |
| 666 | %type <for_> VariableStatement_ |
| 667 | %type <statement_> VariableStatement |
| 668 | %type <statement_> WithStatement |
| 669 | %type <word_> Word |
| 670 | %type <word_> WordNoUnary |
| 671 | @begin ObjectiveC |
| 672 | %type <word_> WordOpt |
| 673 | @end |
| 674 | %type <expression_> YieldExpression |
| 675 | |
| 676 | @begin C |
| 677 | %type <constant_> EnumConstantListOpt_ |
| 678 | %type <constant_> EnumConstantListOpt |
| 679 | %type <number_> IntegerNumber |
| 680 | %type <integral_> IntegerType |
| 681 | %type <integral_> IntegerTypeOpt |
| 682 | %type <typedName_> PrefixedType |
| 683 | %type <specifier_> PrimitiveReference |
| 684 | %type <specifier_> PrimitiveType |
| 685 | %type <structField_> StructFieldListOpt |
| 686 | %type <typedName_> SuffixedType |
| 687 | %type <typedName_> SuffixedTypeOpt |
| 688 | %type <typedName_> TypeSignifier |
| 689 | %type <typedName_> TypeSignifierNone |
| 690 | %type <typedName_> TypeSignifierOpt |
| 691 | %type <signing_> TypeSigning |
| 692 | %type <modifier_> ParameterTail |
| 693 | %type <modifier_> TypeQualifierLeft |
| 694 | %type <modifier_> TypeQualifierLeftOpt |
| 695 | %type <typedName_> TypeQualifierRight |
| 696 | %type <typedName_> TypeQualifierRightOpt |
| 697 | %type <typedName_> TypedIdentifierDefinition |
| 698 | %type <typedThing_> TypedIdentifierEncoding |
| 699 | %type <typedName_> TypedIdentifierField |
| 700 | %type <typedName_> TypedIdentifierMaybe |
| 701 | %type <typedLocation_> TypedIdentifierNo |
| 702 | %type <typedName_> TypedIdentifierTagged |
| 703 | %type <typedName_> TypedIdentifierYes |
| 704 | %type <typedFormal_> TypedParameterList_ |
| 705 | %type <typedFormal_> TypedParameterList |
| 706 | %type <typedFormal_> TypedParameterListOpt |
| 707 | %type <typedParameter_> TypedParameters |
| 708 | @end |
| 709 | |
| 710 | @begin ObjectiveC |
| 711 | %type <expression_> AssignmentExpressionClassic |
| 712 | %type <expression_> BoxableExpression |
| 713 | %type <statement_> CategoryStatement |
| 714 | %type <expression_> ClassSuperOpt |
| 715 | %type <expression_> ConditionalExpressionClassic |
| 716 | %type <message_> ClassMessageDeclaration |
| 717 | %type <message_> ClassMessageDeclarationListOpt |
| 718 | %type <protocol_> ClassProtocolListOpt |
| 719 | %type <protocol_> ClassProtocols |
| 720 | %type <protocol_> ClassProtocolsOpt |
| 721 | %type <implementationField_> ImplementationFieldListOpt |
| 722 | %type <statement_> ImplementationStatement |
| 723 | %type <keyValue_> KeyValuePairList_ |
| 724 | %type <keyValue_> KeyValuePairList |
| 725 | %type <keyValue_> KeyValuePairListOpt |
| 726 | %type <target_> MessageExpression |
| 727 | %type <messageParameter_> MessageParameter |
| 728 | %type <messageParameter_> MessageParameters |
| 729 | %type <messageParameter_> MessageParameterList |
| 730 | %type <messageParameter_> MessageParameterListOpt |
| 731 | %type <bool_> MessageScope |
| 732 | %type <argument_> SelectorCall_ |
| 733 | %type <argument_> SelectorCall |
| 734 | %type <selector_> SelectorExpression_ |
| 735 | %type <selector_> SelectorExpression |
| 736 | %type <selector_> SelectorExpressionOpt |
| 737 | %type <argument_> SelectorList |
| 738 | %type <word_> SelectorWordOpt |
| 739 | %type <typedThing_> TypeOpt |
| 740 | %type <argument_> VariadicCall |
| 741 | @end |
| 742 | |
| 743 | @begin E4X |
| 744 | %type <propertyIdentifier_> PropertyIdentifier_ |
| 745 | %type <selector_> PropertySelector_ |
| 746 | %type <selector_> PropertySelector |
| 747 | %type <identifier_> QualifiedIdentifier_ |
| 748 | %type <identifier_> QualifiedIdentifier |
| 749 | %type <identifier_> WildcardIdentifier |
| 750 | %type <identifier_> XMLComment |
| 751 | %type <identifier_> XMLCDATA |
| 752 | %type <identifier_> XMLElement |
| 753 | %type <identifier_> XMLElementContent |
| 754 | %type <identifier_> XMLMarkup |
| 755 | %type <identifier_> XMLPI |
| 756 | |
| 757 | %type <attribute_> AttributeIdentifier |
| 758 | /* XXX: %type <statement_> DefaultXMLNamespaceStatement */ |
| 759 | %type <expression_> PropertyIdentifier |
| 760 | %type <expression_> XMLListInitilizer |
| 761 | %type <expression_> XMLInitilizer |
| 762 | @end |
| 763 | /* }}} */ |
| 764 | /* Token Priorities {{{ */ |
| 765 | %nonassoc "if" |
| 766 | %nonassoc "else" |
| 767 | |
| 768 | %nonassoc ":" |
| 769 | %nonassoc "!yield" |
| 770 | /* }}} */ |
| 771 | |
| 772 | %start Program |
| 773 | %token MarkModule |
| 774 | %token MarkScript |
| 775 | %token MarkExpression |
| 776 | |
| 777 | %% |
| 778 | |
| 779 | Program |
| 780 | : MarkScript Script |
| 781 | | MarkModule Module |
| 782 | | MarkExpression Expression[expression] { driver.context_ = $expression; } |
| 783 | ; |
| 784 | |
| 785 | /* Lexer State {{{ */ |
| 786 | LexPushInOn: { driver.in_.push(true); }; |
| 787 | LexPushInOff: { driver.in_.push(false); }; |
| 788 | LexPopIn: { driver.in_.pop(); }; |
| 789 | |
| 790 | LexPushReturnOn: { driver.return_.push(true); }; |
| 791 | LexPopReturn: { driver.return_.pop(); }; |
| 792 | Return: "return"[return] { if (!driver.return_.top()) CYERR(@return, "invalid return"); }; |
| 793 | |
| 794 | LexPushSuperOn: { driver.super_.push(true); }; |
| 795 | LexPushSuperOff: { driver.super_.push(false); }; |
| 796 | LexPopSuper: { driver.super_.pop(); }; |
| 797 | Super: "super"[super] { if (!driver.super_.top()) CYERR(@super, "invalid super"); }; |
| 798 | |
| 799 | LexPushYieldOn: { driver.yield_.push(true); }; |
| 800 | LexPushYieldOff: { driver.yield_.push(false); }; |
| 801 | LexPopYield: { driver.yield_.pop(); }; |
| 802 | |
| 803 | LexNewLineOrOpt |
| 804 | : { CYLEX(); if (driver.newline_) { CYHLD(@$, tk::NewLine); } } |
| 805 | ; |
| 806 | |
| 807 | LexNewLineOrNot |
| 808 | : { CYLEX(); CYHLD(@$, driver.newline_ ? tk::NewLine : tk::__); } |
| 809 | ; |
| 810 | |
| 811 | LexNoStar |
| 812 | : { CYMAP(YieldStar, Star); } |
| 813 | ; |
| 814 | |
| 815 | LexNoBrace |
| 816 | : { CYMAP(OpenBrace_, OpenBrace); } |
| 817 | ; |
| 818 | |
| 819 | LexNoClass |
| 820 | : { CYMAP(_class__, _class_); } |
| 821 | ; |
| 822 | |
| 823 | LexNoFunction |
| 824 | : { CYMAP(_function__, _function_); } |
| 825 | ; |
| 826 | |
| 827 | LexSetStatement |
| 828 | : LexNoBrace LexNoClass LexNoFunction |
| 829 | ; |
| 830 | /* }}} */ |
| 831 | /* Virtual Tokens {{{ */ |
| 832 | Var_ |
| 833 | : "var" |
| 834 | ; |
| 835 | /* }}} */ |
| 836 | |
| 837 | /* 11.6 Names and Keywords {{{ */ |
| 838 | IdentifierName |
| 839 | : Word[pass] { $$ = $pass; } |
| 840 | | "for" { $$ = CYNew CYWord("for"); } |
| 841 | | "in" { $$ = CYNew CYWord("in"); } |
| 842 | | "instanceof" { $$ = CYNew CYWord("instanceof"); } |
| 843 | ; |
| 844 | |
| 845 | WordNoUnary |
| 846 | : IdentifierNoOf[pass] { $$ = $pass; } |
| 847 | | "break" { $$ = CYNew CYWord("break"); } |
| 848 | | "case" { $$ = CYNew CYWord("case"); } |
| 849 | | "catch" { $$ = CYNew CYWord("catch"); } |
| 850 | | "class" LexOf { $$ = CYNew CYWord("class"); } |
| 851 | | ";class" { $$ = CYNew CYWord("class"); } |
| 852 | | "const" { $$ = CYNew CYWord("const"); } |
| 853 | | "continue" { $$ = CYNew CYWord("continue"); } |
| 854 | | "debugger" { $$ = CYNew CYWord("debugger"); } |
| 855 | | "default" { $$ = CYNew CYWord("default"); } |
| 856 | | "do" { $$ = CYNew CYWord("do"); } |
| 857 | | "else" { $$ = CYNew CYWord("else"); } |
| 858 | | "enum" { $$ = CYNew CYWord("enum"); } |
| 859 | | "export" { $$ = CYNew CYWord("export"); } |
| 860 | | "extends" { $$ = CYNew CYWord("extends"); } |
| 861 | | "false" { $$ = CYNew CYWord("false"); } |
| 862 | | "finally" { $$ = CYNew CYWord("finally"); } |
| 863 | | "function" LexOf { $$ = CYNew CYWord("function"); } |
| 864 | | "if" { $$ = CYNew CYWord("if"); } |
| 865 | | "import" { $$ = CYNew CYWord("import"); } |
| 866 | | "!in" { $$ = CYNew CYWord("in"); } |
| 867 | | "!of" { $$ = CYNew CYWord("of"); } |
| 868 | | "null" { $$ = CYNew CYWord("null"); } |
| 869 | | "return" { $$ = CYNew CYWord("return"); } |
| 870 | | "super" { $$ = CYNew CYWord("super"); } |
| 871 | | "switch" { $$ = CYNew CYWord("switch"); } |
| 872 | | "this" { $$ = CYNew CYWord("this"); } |
| 873 | | "throw" { $$ = CYNew CYWord("throw"); } |
| 874 | | "true" { $$ = CYNew CYWord("true"); } |
| 875 | | "try" { $$ = CYNew CYWord("try"); } |
| 876 | | "var" { $$ = CYNew CYWord("var"); } |
| 877 | | "while" { $$ = CYNew CYWord("while"); } |
| 878 | | "with" { $$ = CYNew CYWord("with"); } |
| 879 | ; |
| 880 | |
| 881 | Word |
| 882 | : WordNoUnary[pass] { $$ = $pass; } |
| 883 | | "delete" { $$ = CYNew CYWord("delete"); } |
| 884 | | "typeof" { $$ = CYNew CYWord("typeof"); } |
| 885 | | "void" { $$ = CYNew CYWord("void"); } |
| 886 | | "yield" { $$ = CYNew CYIdentifier("yield"); } |
| 887 | ; |
| 888 | |
| 889 | @begin ObjectiveC |
| 890 | WordOpt |
| 891 | : Word[pass] { $$ = $pass; } |
| 892 | | { $$ = NULL; } |
| 893 | ; |
| 894 | @end |
| 895 | /* }}} */ |
| 896 | /* 11.8.1 Null Literals {{{ */ |
| 897 | NullLiteral |
| 898 | : "null" { $$ = CYNew CYNull(); } |
| 899 | ; |
| 900 | /* }}} */ |
| 901 | /* 11.8.2 Boolean Literals {{{ */ |
| 902 | BooleanLiteral |
| 903 | : "true" { $$ = CYNew CYTrue(); } |
| 904 | | "false" { $$ = CYNew CYFalse(); } |
| 905 | ; |
| 906 | /* }}} */ |
| 907 | /* 11.8.5 Regular Expression Literals {{{ */ |
| 908 | RegularExpressionSlash |
| 909 | : "/" { $$ = false; } |
| 910 | | "/=" { $$ = true; } |
| 911 | ; |
| 912 | |
| 913 | RegularExpressionLiteral |
| 914 | : RegularExpressionSlash[equals] { CYMPT(@$); driver.SetRegEx($equals); } RegularExpressionLiteral_[pass] { $$ = $pass; } |
| 915 | ; |
| 916 | /* }}} */ |
| 917 | |
| 918 | /* 11.9 Automatic Semicolon Insertion {{{ */ |
| 919 | StrictSemi |
| 920 | : { driver.Warning(@$, "warning, automatic semi-colon insertion required"); } |
| 921 | ; |
| 922 | |
| 923 | NewLineNot |
| 924 | : LexNewLineOrNot "" |
| 925 | ; |
| 926 | |
| 927 | NewLineOpt |
| 928 | : LexNewLineOrNot "\n" |
| 929 | | NewLineNot |
| 930 | ; |
| 931 | |
| 932 | TerminatorSoft |
| 933 | : LexNewLineOrNot "\n" StrictSemi |
| 934 | | NewLineNot LexOf Terminator |
| 935 | ; |
| 936 | |
| 937 | TerminatorHard |
| 938 | : ";" |
| 939 | | error { if (yyla.type_get() != yyeof_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi |
| 940 | ; |
| 941 | |
| 942 | Terminator |
| 943 | : ";" |
| 944 | | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && !driver.newline_) CYERR(@error, "required semi-colon"); else CYEOK(); } StrictSemi |
| 945 | ; |
| 946 | |
| 947 | TerminatorOpt |
| 948 | : ";" |
| 949 | | error { yyerrok; driver.errors_.pop_back(); } StrictSemi |
| 950 | ; |
| 951 | /* }}} */ |
| 952 | |
| 953 | /* 12.1 Identifiers {{{ */ |
| 954 | IdentifierReference |
| 955 | : Identifier[pass] { $$ = CYNew CYVariable($pass); } |
| 956 | | "yield" { $$ = CYNew CYVariable(CYNew CYIdentifier("yield")); } |
| 957 | ; |
| 958 | |
| 959 | BindingIdentifier |
| 960 | : LexOf IdentifierNoOf[pass] { $$ = $pass; } |
| 961 | | LexOf "!of" { $$ = CYNew CYIdentifier("of"); } |
| 962 | | LexOf "yield" { $$ = CYNew CYIdentifier("yield"); } |
| 963 | ; |
| 964 | |
| 965 | BindingIdentifierOpt |
| 966 | : BindingIdentifier[pass] { $$ = $pass; } |
| 967 | | LexOf { $$ = NULL; } |
| 968 | ; |
| 969 | |
| 970 | LabelIdentifier |
| 971 | : Identifier[pass] { $$ = $pass; } |
| 972 | | "yield" { $$ = CYNew CYIdentifier("yield"); } |
| 973 | ; |
| 974 | |
| 975 | IdentifierTypeNoOf |
| 976 | : Identifier_[pass] { $$ = $pass; } |
| 977 | | "abstract" { $$ = CYNew CYIdentifier("abstract"); } |
| 978 | | "as" { $$ = CYNew CYIdentifier("as"); } |
| 979 | | "await" { $$ = CYNew CYIdentifier("await"); } |
| 980 | | "boolean" { $$ = CYNew CYIdentifier("boolean"); } |
| 981 | | "byte" { $$ = CYNew CYIdentifier("byte"); } |
| 982 | | "constructor" { $$ = CYNew CYIdentifier("constructor"); } |
| 983 | | "each" { $$ = CYNew CYIdentifier("each"); } |
| 984 | | "eval" { $$ = CYNew CYIdentifier("eval"); } |
| 985 | | "final" { $$ = CYNew CYIdentifier("final"); } |
| 986 | | "from" { $$ = CYNew CYIdentifier("from"); } |
| 987 | | "get" { $$ = CYNew CYIdentifier("get"); } |
| 988 | | "goto" { $$ = CYNew CYIdentifier("goto"); } |
| 989 | | "implements" { $$ = CYNew CYIdentifier("implements"); } |
| 990 | | "Infinity" { $$ = CYNew CYIdentifier("Infinity"); } |
| 991 | | "interface" { $$ = CYNew CYIdentifier("interface"); } |
| 992 | | "let" { $$ = CYNew CYIdentifier("let"); } |
| 993 | | "!let" LexBind LexOf { $$ = CYNew CYIdentifier("let"); } |
| 994 | | "native" { $$ = CYNew CYIdentifier("native"); } |
| 995 | | "package" { $$ = CYNew CYIdentifier("package"); } |
| 996 | | "private" { $$ = CYNew CYIdentifier("private"); } |
| 997 | | "protected" { $$ = CYNew CYIdentifier("protected"); } |
| 998 | | "__proto__" { $$ = CYNew CYIdentifier("__proto__"); } |
| 999 | | "prototype" { $$ = CYNew CYIdentifier("prototype"); } |
| 1000 | | "public" { $$ = CYNew CYIdentifier("public"); } |
| 1001 | | "set" { $$ = CYNew CYIdentifier("set"); } |
| 1002 | | "synchronized" { $$ = CYNew CYIdentifier("synchronized"); } |
| 1003 | | "target" { $$ = CYNew CYIdentifier("target"); } |
| 1004 | | "throws" { $$ = CYNew CYIdentifier("throws"); } |
| 1005 | | "transient" { $$ = CYNew CYIdentifier("transient"); } |
| 1006 | | "typeid" { $$ = CYNew CYIdentifier("typeid"); } |
| 1007 | | "undefined" { $$ = CYNew CYIdentifier("undefined"); } |
| 1008 | @begin ObjectiveC |
| 1009 | | "bool" { $$ = CYNew CYIdentifier("bool"); } |
| 1010 | | "BOOL" { $$ = CYNew CYIdentifier("BOOL"); } |
| 1011 | | "id" { $$ = CYNew CYIdentifier("id"); } |
| 1012 | | "SEL" { $$ = CYNew CYIdentifier("SEL"); } |
| 1013 | @end |
| 1014 | ; |
| 1015 | |
| 1016 | IdentifierType |
| 1017 | : IdentifierTypeNoOf[pass] { $$ = $pass; } |
| 1018 | | "of" { $$ = CYNew CYIdentifier("of"); } |
| 1019 | ; |
| 1020 | |
| 1021 | IdentifierTypeOpt |
| 1022 | : IdentifierType[pass] { $$ = $pass; } |
| 1023 | | { $$ = NULL; } |
| 1024 | ; |
| 1025 | |
| 1026 | IdentifierNoOf |
| 1027 | : IdentifierTypeNoOf |
| 1028 | | "char" { $$ = CYNew CYIdentifier("char"); } |
| 1029 | | "double" { $$ = CYNew CYIdentifier("double"); } |
| 1030 | | "float" { $$ = CYNew CYIdentifier("float"); } |
| 1031 | | "int" { $$ = CYNew CYIdentifier("int"); } |
| 1032 | | "__int128" { $$ = CYNew CYIdentifier("__int128"); } |
| 1033 | | "long" { $$ = CYNew CYIdentifier("long"); } |
| 1034 | | "short" { $$ = CYNew CYIdentifier("short"); } |
| 1035 | | "static" { $$ = CYNew CYIdentifier("static"); } |
| 1036 | | "volatile" { $$ = CYNew CYIdentifier("volatile"); } |
| 1037 | @begin C |
| 1038 | | "signed" { $$ = CYNew CYIdentifier("signed"); } |
| 1039 | | "unsigned" { $$ = CYNew CYIdentifier("unsigned"); } |
| 1040 | @end |
| 1041 | @begin ObjectiveC |
| 1042 | | "nil" { $$ = CYNew CYIdentifier("nil"); } |
| 1043 | | "NO" { $$ = CYNew CYIdentifier("NO"); } |
| 1044 | | "NULL" { $$ = CYNew CYIdentifier("NULL"); } |
| 1045 | | "YES" { $$ = CYNew CYIdentifier("YES"); } |
| 1046 | @end |
| 1047 | ; |
| 1048 | |
| 1049 | Identifier |
| 1050 | : IdentifierNoOf[pass] { $$ = $pass; } |
| 1051 | | "of" { $$ = CYNew CYIdentifier("of"); } |
| 1052 | | "!of" { $$ = CYNew CYIdentifier("of"); } |
| 1053 | ; |
| 1054 | /* }}} */ |
| 1055 | /* 12.2 Primary Expression {{{ */ |
| 1056 | PrimaryExpression |
| 1057 | : "this" { $$ = CYNew CYThis(); } |
| 1058 | | IdentifierReference[pass] { $$ = $pass; } |
| 1059 | | Literal[pass] { $$ = $pass; } |
| 1060 | | ArrayLiteral[pass] { $$ = $pass; } |
| 1061 | | ObjectLiteral[pass] { $$ = $pass; } |
| 1062 | | FunctionExpression[pass] { $$ = $pass; } |
| 1063 | | ClassExpression[pass] { $$ = $pass; } |
| 1064 | | GeneratorExpression[pass] { $$ = $pass; } |
| 1065 | | RegularExpressionLiteral[pass] { $$ = $pass; } |
| 1066 | | TemplateLiteral[pass] { $$ = $pass; } |
| 1067 | | CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) CYERR(@cover, "invalid parenthetical"); $$ = $cover; } |
| 1068 | | AutoComplete { driver.mode_ = CYDriver::AutoPrimary; YYACCEPT; } |
| 1069 | ; |
| 1070 | |
| 1071 | CoverParenthesizedExpressionAndArrowParameterList |
| 1072 | : "(" Expression[expression] ")" { $$ = CYNew CYParenthetical($expression); } |
| 1073 | | "(" LexOf ")" { $$ = NULL; } |
| 1074 | | "(" LexOf "..." BindingIdentifier ")" { CYNOT(@$); } |
| 1075 | | "(" Expression "," LexOf "..." BindingIdentifier ")" { CYNOT(@$); } |
| 1076 | ; |
| 1077 | /* }}} */ |
| 1078 | /* 12.2.4 Literals {{{ */ |
| 1079 | Literal |
| 1080 | : NullLiteral[pass] { $$ = $pass; } |
| 1081 | | BooleanLiteral[pass] { $$ = $pass; } |
| 1082 | | NumericLiteral[pass] { $$ = $pass; } |
| 1083 | | StringLiteral[pass] { $$ = $pass; } |
| 1084 | ; |
| 1085 | /* }}} */ |
| 1086 | /* 12.2.5 Array Initializer {{{ */ |
| 1087 | ArrayLiteral |
| 1088 | : "[" ElementListOpt[elements] "]" { $$ = CYNew CYArray($elements); } |
| 1089 | ; |
| 1090 | |
| 1091 | ArrayElement |
| 1092 | : AssignmentExpression[value] { $$ = CYNew CYElementValue($value); } |
| 1093 | | LexOf "..." AssignmentExpression[values] { $$ = CYNew CYElementSpread($values); } |
| 1094 | ; |
| 1095 | |
| 1096 | ElementList_ |
| 1097 | : "," ElementListOpt[elements] { $$ = $elements; } |
| 1098 | | { $$ = NULL; } |
| 1099 | ; |
| 1100 | |
| 1101 | ElementList |
| 1102 | : ArrayElement[element] ElementList_[next] { $$ = $element; $$->SetNext($next); } |
| 1103 | | LexOf "," ElementListOpt[next] { $$ = CYNew CYElementValue(NULL, $next); } |
| 1104 | ; |
| 1105 | |
| 1106 | ElementListOpt |
| 1107 | : ElementList[pass] { $$ = $pass; } |
| 1108 | | LexOf { $$ = NULL; } |
| 1109 | ; |
| 1110 | /* }}} */ |
| 1111 | /* 12.2.6 Object Initializer {{{ */ |
| 1112 | ObjectLiteral |
| 1113 | : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYObject($properties); } |
| 1114 | ; |
| 1115 | |
| 1116 | PropertyDefinitionList_ |
| 1117 | : "," PropertyDefinitionListOpt[properties] { $$ = $properties; } |
| 1118 | | { $$ = NULL; } |
| 1119 | ; |
| 1120 | |
| 1121 | PropertyDefinitionList |
| 1122 | : PropertyDefinition[property] PropertyDefinitionList_[next] { $property->SetNext($next); $$ = $property; } |
| 1123 | ; |
| 1124 | |
| 1125 | PropertyDefinitionListOpt |
| 1126 | : PropertyDefinitionList[properties] { $$ = $properties; } |
| 1127 | | { $$ = NULL; } |
| 1128 | ; |
| 1129 | |
| 1130 | PropertyDefinition |
| 1131 | : IdentifierReference[value] { $$ = CYNew CYPropertyValue($value->name_, $value); } |
| 1132 | | CoverInitializedName[name] { CYNOT(@$); } |
| 1133 | | PropertyName[name] ":" AssignmentExpression[value] { $$ = CYNew CYPropertyValue($name, $value); } |
| 1134 | | MethodDefinition[pass] { $$ = $pass; } |
| 1135 | ; |
| 1136 | |
| 1137 | PropertyName |
| 1138 | : LiteralPropertyName[pass] { $$ = $pass; } |
| 1139 | | ComputedPropertyName[pass] { $$ = $pass; } |
| 1140 | ; |
| 1141 | |
| 1142 | LiteralPropertyName |
| 1143 | : IdentifierName[pass] { $$ = $pass; } |
| 1144 | | StringLiteral[pass] { $$ = $pass; } |
| 1145 | | NumericLiteral[pass] { $$ = $pass; } |
| 1146 | ; |
| 1147 | |
| 1148 | ComputedPropertyName |
| 1149 | : "[" AssignmentExpression[expression] "]" { $$ = CYNew CYComputed($expression); } |
| 1150 | ; |
| 1151 | |
| 1152 | CoverInitializedName |
| 1153 | : IdentifierReference Initializer |
| 1154 | ; |
| 1155 | |
| 1156 | Initializer |
| 1157 | : "=" AssignmentExpression[initializer] { $$ = $initializer; } |
| 1158 | ; |
| 1159 | |
| 1160 | InitializerOpt |
| 1161 | : Initializer[pass] { $$ = $pass; } |
| 1162 | | { $$ = NULL; } |
| 1163 | ; |
| 1164 | /* }}} */ |
| 1165 | /* 12.2.9 Template Literals {{{ */ |
| 1166 | TemplateLiteral |
| 1167 | : NoSubstitutionTemplate[string] { $$ = CYNew CYTemplate($string, NULL); } |
| 1168 | | TemplateHead[string] LexPushInOff TemplateSpans[spans] { $$ = CYNew CYTemplate($string, $spans); } |
| 1169 | ; |
| 1170 | |
| 1171 | TemplateSpans |
| 1172 | : Expression[value] TemplateMiddle[string] TemplateSpans[spans] { $$ = CYNew CYSpan($value, $string, $spans); } |
| 1173 | | Expression[value] TemplateTail[string] LexPopIn { $$ = CYNew CYSpan($value, $string, NULL); } |
| 1174 | ; |
| 1175 | /* }}} */ |
| 1176 | |
| 1177 | /* 12.3 Left-Hand-Side Expressions {{{ */ |
| 1178 | MemberAccess |
| 1179 | : "[" Expression[property] "]" { $$ = CYNew CYDirectMember(NULL, $property); } |
| 1180 | | "." IdentifierName[property] { $$ = CYNew CYDirectMember(NULL, CYNew CYString($property)); } |
| 1181 | | "." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; } |
| 1182 | | TemplateLiteral { CYNOT(@$); } |
| 1183 | ; |
| 1184 | |
| 1185 | MemberExpression |
| 1186 | : PrimaryExpression[pass] { $$ = $pass; } |
| 1187 | | MemberExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; } |
| 1188 | | SuperProperty[pass] { $$ = $pass; } |
| 1189 | | MetaProperty { CYNOT(@$); } |
| 1190 | | "new" MemberExpression[constructor] Arguments[arguments] { $$ = CYNew cy::Syntax::New($constructor, $arguments); } |
| 1191 | ; |
| 1192 | |
| 1193 | SuperProperty |
| 1194 | : Super "[" Expression[property] "]" { $$ = CYNew CYSuperAccess($property); } |
| 1195 | | Super "." IdentifierName[property] { $$ = CYNew CYSuperAccess(CYNew CYString($property)); } |
| 1196 | ; |
| 1197 | |
| 1198 | MetaProperty |
| 1199 | : NewTarget |
| 1200 | ; |
| 1201 | |
| 1202 | NewTarget |
| 1203 | : "new" "." "target" |
| 1204 | ; |
| 1205 | |
| 1206 | NewExpression |
| 1207 | : MemberExpression[pass] { $$ = $pass; } |
| 1208 | | "new" NewExpression[expression] { $$ = CYNew cy::Syntax::New($expression, NULL); } |
| 1209 | ; |
| 1210 | |
| 1211 | CallExpression_ |
| 1212 | : MemberExpression[pass] { $$ = $pass; } |
| 1213 | | CallExpression[pass] { $$ = $pass; } |
| 1214 | ; |
| 1215 | |
| 1216 | CallExpression |
| 1217 | : CallExpression_[function] Arguments[arguments] { if (!$function->Eval()) $$ = CYNew CYCall($function, $arguments); else $$ = CYNew CYEval($arguments); } |
| 1218 | | SuperCall[pass] { $$ = $pass; } |
| 1219 | | CallExpression[object] { driver.context_ = $object; } MemberAccess[member] { $member->SetLeft($object); $$ = $member; } |
| 1220 | ; |
| 1221 | |
| 1222 | SuperCall |
| 1223 | : Super Arguments[arguments] { $$ = CYNew CYSuperCall($arguments); } |
| 1224 | ; |
| 1225 | |
| 1226 | Arguments |
| 1227 | : "(" ArgumentListOpt[arguments] ")" { $$ = $arguments; } |
| 1228 | ; |
| 1229 | |
| 1230 | ArgumentList_ |
| 1231 | : "," ArgumentList[arguments] { $$ = $arguments; } |
| 1232 | | { $$ = NULL; } |
| 1233 | ; |
| 1234 | |
| 1235 | ArgumentList |
| 1236 | : AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument(NULL, $value, $next); } |
| 1237 | | LexOf "..." AssignmentExpression { CYNOT(@$); } |
| 1238 | ; |
| 1239 | |
| 1240 | ArgumentListOpt |
| 1241 | : ArgumentList[pass] { $$ = $pass; } |
| 1242 | | LexOf { $$ = NULL; } |
| 1243 | ; |
| 1244 | |
| 1245 | AccessExpression |
| 1246 | : NewExpression[pass] { $$ = $pass; } |
| 1247 | | CallExpression[pass] { $$ = $pass; } |
| 1248 | ; |
| 1249 | |
| 1250 | LeftHandSideExpression |
| 1251 | : BracedExpression[pass] { $$ = $pass; } |
| 1252 | | IndirectExpression[pass] { $$ = $pass; } |
| 1253 | ; |
| 1254 | /* }}} */ |
| 1255 | /* 12.4 Postfix Expressions {{{ */ |
| 1256 | PostfixExpression |
| 1257 | : BracedExpression[pass] { $$ = $pass; } |
| 1258 | | AccessExpression[lhs] LexNewLineOrOpt "++" { $$ = CYNew CYPostIncrement($lhs); } |
| 1259 | | AccessExpression[lhs] LexNewLineOrOpt "--" { $$ = CYNew CYPostDecrement($lhs); } |
| 1260 | ; |
| 1261 | /* }}} */ |
| 1262 | /* 12.5 Unary Operators {{{ */ |
| 1263 | UnaryExpression_ |
| 1264 | : "delete" UnaryExpression[rhs] { $$ = CYNew CYDelete($rhs); } |
| 1265 | | "void" UnaryExpression[rhs] { $$ = CYNew CYVoid($rhs); } |
| 1266 | | "typeof" UnaryExpression[rhs] { $$ = CYNew CYTypeOf($rhs); } |
| 1267 | | "++" UnaryExpression[rhs] { $$ = CYNew CYPreIncrement($rhs); } |
| 1268 | | "--" UnaryExpression[rhs] { $$ = CYNew CYPreDecrement($rhs); } |
| 1269 | | "+" UnaryExpression[rhs] { $$ = CYNew CYAffirm($rhs); } |
| 1270 | | "-" UnaryExpression[rhs] { $$ = CYNew CYNegate($rhs); } |
| 1271 | | "~" UnaryExpression[rhs] { $$ = CYNew CYBitwiseNot($rhs); } |
| 1272 | | "!" UnaryExpression[rhs] { $$ = CYNew CYLogicalNot($rhs); } |
| 1273 | ; |
| 1274 | |
| 1275 | UnaryExpression |
| 1276 | : PostfixExpression[expression] { $$ = $expression; } |
| 1277 | | UnaryExpression_[pass] { $$ = $pass; } |
| 1278 | ; |
| 1279 | /* }}} */ |
| 1280 | /* 12.6 Multiplicative Operators {{{ */ |
| 1281 | MultiplicativeExpression |
| 1282 | : UnaryExpression[pass] { $$ = $pass; } |
| 1283 | | MultiplicativeExpression[lhs] "*" UnaryExpression[rhs] { $$ = CYNew CYMultiply($lhs, $rhs); } |
| 1284 | | MultiplicativeExpression[lhs] "/" UnaryExpression[rhs] { $$ = CYNew CYDivide($lhs, $rhs); } |
| 1285 | | MultiplicativeExpression[lhs] "%" UnaryExpression[rhs] { $$ = CYNew CYModulus($lhs, $rhs); } |
| 1286 | ; |
| 1287 | /* }}} */ |
| 1288 | /* 12.7 Additive Operators {{{ */ |
| 1289 | AdditiveExpression |
| 1290 | : MultiplicativeExpression[pass] { $$ = $pass; } |
| 1291 | | AdditiveExpression[lhs] "+" MultiplicativeExpression[rhs] { $$ = CYNew CYAdd($lhs, $rhs); } |
| 1292 | | AdditiveExpression[lhs] "-" MultiplicativeExpression[rhs] { $$ = CYNew CYSubtract($lhs, $rhs); } |
| 1293 | ; |
| 1294 | /* }}} */ |
| 1295 | /* 12.8 Bitwise Shift Operators {{{ */ |
| 1296 | ShiftExpression |
| 1297 | : AdditiveExpression[pass] { $$ = $pass; } |
| 1298 | | ShiftExpression[lhs] "<<" AdditiveExpression[rhs] { $$ = CYNew CYShiftLeft($lhs, $rhs); } |
| 1299 | | ShiftExpression[lhs] ">>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightSigned($lhs, $rhs); } |
| 1300 | | ShiftExpression[lhs] ">>>" AdditiveExpression[rhs] { $$ = CYNew CYShiftRightUnsigned($lhs, $rhs); } |
| 1301 | ; |
| 1302 | /* }}} */ |
| 1303 | /* 12.9 Relational Operators {{{ */ |
| 1304 | RelationalExpression |
| 1305 | : ShiftExpression[pass] { $$ = $pass; } |
| 1306 | | RelationalExpression[lhs] "<" ShiftExpression[rhs] { $$ = CYNew CYLess($lhs, $rhs); } |
| 1307 | | RelationalExpression[lhs] ">" ShiftExpression[rhs] { $$ = CYNew CYGreater($lhs, $rhs); } |
| 1308 | | RelationalExpression[lhs] "<=" ShiftExpression[rhs] { $$ = CYNew CYLessOrEqual($lhs, $rhs); } |
| 1309 | | RelationalExpression[lhs] ">=" ShiftExpression[rhs] { $$ = CYNew CYGreaterOrEqual($lhs, $rhs); } |
| 1310 | | RelationalExpression[lhs] "instanceof" ShiftExpression[rhs] { $$ = CYNew CYInstanceOf($lhs, $rhs); } |
| 1311 | | RelationalExpression[lhs] "in" ShiftExpression[rhs] { $$ = CYNew CYIn($lhs, $rhs); } |
| 1312 | ; |
| 1313 | /* }}} */ |
| 1314 | /* 12.10 Equality Operators {{{ */ |
| 1315 | EqualityExpression |
| 1316 | : RelationalExpression[pass] { $$ = $pass; } |
| 1317 | | EqualityExpression[lhs] "==" RelationalExpression[rhs] { $$ = CYNew CYEqual($lhs, $rhs); } |
| 1318 | | EqualityExpression[lhs] "!=" RelationalExpression[rhs] { $$ = CYNew CYNotEqual($lhs, $rhs); } |
| 1319 | | EqualityExpression[lhs] "===" RelationalExpression[rhs] { $$ = CYNew CYIdentical($lhs, $rhs); } |
| 1320 | | EqualityExpression[lhs] "!==" RelationalExpression[rhs] { $$ = CYNew CYNotIdentical($lhs, $rhs); } |
| 1321 | ; |
| 1322 | /* }}} */ |
| 1323 | /* 12.11 Binary Bitwise Operators {{{ */ |
| 1324 | BitwiseANDExpression |
| 1325 | : EqualityExpression[pass] { $$ = $pass; } |
| 1326 | | BitwiseANDExpression[lhs] "&" EqualityExpression[rhs] { $$ = CYNew CYBitwiseAnd($lhs, $rhs); } |
| 1327 | ; |
| 1328 | |
| 1329 | BitwiseXORExpression |
| 1330 | : BitwiseANDExpression[pass] { $$ = $pass; } |
| 1331 | | BitwiseXORExpression[lhs] "^" BitwiseANDExpression[rhs] { $$ = CYNew CYBitwiseXOr($lhs, $rhs); } |
| 1332 | ; |
| 1333 | |
| 1334 | BitwiseORExpression |
| 1335 | : BitwiseXORExpression[pass] { $$ = $pass; } |
| 1336 | | BitwiseORExpression[lhs] "|" BitwiseXORExpression[rhs] { $$ = CYNew CYBitwiseOr($lhs, $rhs); } |
| 1337 | ; |
| 1338 | /* }}} */ |
| 1339 | /* 12.12 Binary Logical Operators {{{ */ |
| 1340 | LogicalANDExpression |
| 1341 | : BitwiseORExpression[pass] { $$ = $pass; } |
| 1342 | | LogicalANDExpression[lhs] "&&" BitwiseORExpression[rhs] { $$ = CYNew CYLogicalAnd($lhs, $rhs); } |
| 1343 | ; |
| 1344 | |
| 1345 | LogicalORExpression |
| 1346 | : LogicalANDExpression[pass] { $$ = $pass; } |
| 1347 | | LogicalORExpression[lhs] "||" LogicalANDExpression[rhs] { $$ = CYNew CYLogicalOr($lhs, $rhs); } |
| 1348 | ; |
| 1349 | /* }}} */ |
| 1350 | /* 12.13 Conditional Operator ( ? : ) {{{ */ |
| 1351 | @begin ObjectiveC |
| 1352 | ConditionalExpressionClassic |
| 1353 | : LogicalORExpression[pass] { $$ = $pass; } |
| 1354 | | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpressionClassic[false] { $$ = CYNew CYCondition($test, $true, $false); } |
| 1355 | ; |
| 1356 | @end |
| 1357 | |
| 1358 | ConditionalExpression |
| 1359 | : LogicalORExpression[pass] { $$ = $pass; } |
| 1360 | | LogicalORExpression[test] "?" LexPushInOff AssignmentExpression[true] ":" LexPopIn AssignmentExpression[false] { $$ = CYNew CYCondition($test, $true, $false); } |
| 1361 | ; |
| 1362 | /* }}} */ |
| 1363 | /* 12.14 Assignment Operators {{{ */ |
| 1364 | LeftHandSideAssignment |
| 1365 | : LeftHandSideExpression[lhs] "=" { $$ = CYNew CYAssign($lhs, NULL); } |
| 1366 | | LeftHandSideExpression[lhs] "*=" { $$ = CYNew CYMultiplyAssign($lhs, NULL); } |
| 1367 | | LeftHandSideExpression[lhs] "/=" { $$ = CYNew CYDivideAssign($lhs, NULL); } |
| 1368 | | LeftHandSideExpression[lhs] "%=" { $$ = CYNew CYModulusAssign($lhs, NULL); } |
| 1369 | | LeftHandSideExpression[lhs] "+=" { $$ = CYNew CYAddAssign($lhs, NULL); } |
| 1370 | | LeftHandSideExpression[lhs] "-=" { $$ = CYNew CYSubtractAssign($lhs, NULL); } |
| 1371 | | LeftHandSideExpression[lhs] "<<=" { $$ = CYNew CYShiftLeftAssign($lhs, NULL); } |
| 1372 | | LeftHandSideExpression[lhs] ">>=" { $$ = CYNew CYShiftRightSignedAssign($lhs, NULL); } |
| 1373 | | LeftHandSideExpression[lhs] ">>>=" { $$ = CYNew CYShiftRightUnsignedAssign($lhs, NULL); } |
| 1374 | | LeftHandSideExpression[lhs] "&=" { $$ = CYNew CYBitwiseAndAssign($lhs, NULL); } |
| 1375 | | LeftHandSideExpression[lhs] "^=" { $$ = CYNew CYBitwiseXOrAssign($lhs, NULL); } |
| 1376 | | LeftHandSideExpression[lhs] "|=" { $$ = CYNew CYBitwiseOrAssign($lhs, NULL); } |
| 1377 | ; |
| 1378 | |
| 1379 | @begin ObjectiveC |
| 1380 | AssignmentExpressionClassic |
| 1381 | : LexOf ConditionalExpressionClassic[pass] { $$ = $pass; } |
| 1382 | | LexOf LeftHandSideAssignment[assignment] AssignmentExpressionClassic[rhs] { $assignment->SetRight($rhs); $$ = $assignment; } |
| 1383 | ; |
| 1384 | @end |
| 1385 | |
| 1386 | AssignmentExpression |
| 1387 | : LexOf ConditionalExpression[pass] { $$ = $pass; } |
| 1388 | | LexOf YieldExpression[pass] { $$ = $pass; } |
| 1389 | | ArrowFunction[pass] { $$ = $pass; } |
| 1390 | | LexOf LeftHandSideAssignment[assignment] AssignmentExpression[rhs] { $assignment->SetRight($rhs); $$ = $assignment; } |
| 1391 | ; |
| 1392 | /* }}} */ |
| 1393 | /* 12.15 Comma Operator ( , ) {{{ */ |
| 1394 | Expression |
| 1395 | : AssignmentExpression[pass] { $$ = $pass; } |
| 1396 | | Expression[expression] "," AssignmentExpression[next] { $$ = CYNew CYCompound($expression, $next); } |
| 1397 | ; |
| 1398 | |
| 1399 | ExpressionOpt |
| 1400 | : Expression[pass] { $$ = $pass; } |
| 1401 | | LexOf { $$ = NULL; } |
| 1402 | ; |
| 1403 | /* }}} */ |
| 1404 | |
| 1405 | /* 13 Statements and Declarations {{{ */ |
| 1406 | Statement__ |
| 1407 | : BlockStatement[pass] { $$ = $pass; } |
| 1408 | | VariableStatement[pass] { $$ = $pass; } |
| 1409 | | EmptyStatement[pass] { $$ = $pass; } |
| 1410 | | IfStatement[pass] { $$ = $pass; } |
| 1411 | | BreakableStatement[pass] { $$ = $pass; } |
| 1412 | | ContinueStatement[pass] { $$ = $pass; } |
| 1413 | | BreakStatement[pass] { $$ = $pass; } |
| 1414 | | ReturnStatement[pass] { $$ = $pass; } |
| 1415 | | WithStatement[pass] { $$ = $pass; } |
| 1416 | | LabelledStatement[pass] { $$ = $pass; } |
| 1417 | | ThrowStatement[pass] { $$ = $pass; } |
| 1418 | | TryStatement[pass] { $$ = $pass; } |
| 1419 | | DebuggerStatement[pass] { $$ = $pass; } |
| 1420 | ; |
| 1421 | |
| 1422 | Statement_ |
| 1423 | : LexOf Statement__[pass] { $$ = $pass; } |
| 1424 | | ExpressionStatement[pass] { $$ = $pass; } |
| 1425 | ; |
| 1426 | |
| 1427 | Statement |
| 1428 | : LexSetStatement LexLet Statement_[pass] { $$ = $pass; } |
| 1429 | ; |
| 1430 | |
| 1431 | Declaration_ |
| 1432 | : HoistableDeclaration[pass] { $$ = $pass; } |
| 1433 | | ClassDeclaration[pass] { $$ = $pass; } |
| 1434 | ; |
| 1435 | |
| 1436 | Declaration |
| 1437 | : LexSetStatement LexLet LexOf Declaration_[pass] { $$ = $pass; } |
| 1438 | | LexSetStatement LexicalDeclaration[pass] { $$ = $pass; } |
| 1439 | ; |
| 1440 | |
| 1441 | HoistableDeclaration |
| 1442 | : FunctionDeclaration[pass] { $$ = $pass; } |
| 1443 | | GeneratorDeclaration[pass] { $$ = $pass; } |
| 1444 | ; |
| 1445 | |
| 1446 | BreakableStatement |
| 1447 | : IterationStatement[pass] { $$ = $pass; } |
| 1448 | | SwitchStatement[pass] { $$ = $pass; } |
| 1449 | ; |
| 1450 | /* }}} */ |
| 1451 | /* 13.2 Block {{{ */ |
| 1452 | BlockStatement |
| 1453 | : ";{" StatementListOpt[code] "}" { $$ = CYNew CYBlock($code); } |
| 1454 | ; |
| 1455 | |
| 1456 | Block |
| 1457 | : "{" StatementListOpt[code] "}" { $$ = $code; } |
| 1458 | ; |
| 1459 | |
| 1460 | StatementList |
| 1461 | : StatementListItem[statement] StatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; } |
| 1462 | ; |
| 1463 | |
| 1464 | StatementListOpt |
| 1465 | : StatementList[pass] { $$ = $pass; } |
| 1466 | | LexSetStatement LexLet LexOf { $$ = NULL; } |
| 1467 | ; |
| 1468 | |
| 1469 | StatementListItem |
| 1470 | : Statement[pass] { $$ = $pass; } |
| 1471 | | Declaration[pass] { $$ = $pass; } |
| 1472 | ; |
| 1473 | /* }}} */ |
| 1474 | /* 13.3 Let and Const Declarations {{{ */ |
| 1475 | LexicalDeclaration_ |
| 1476 | : LetOrConst[constant] BindingList[bindings] { $$ = CYNew CYLexical($constant, $bindings); } |
| 1477 | ; |
| 1478 | |
| 1479 | LexicalDeclaration |
| 1480 | : LexicalDeclaration_[statement] Terminator { $$ = $statement; } |
| 1481 | ; |
| 1482 | |
| 1483 | LexLet |
| 1484 | : { CYMAP(_let__, _let_); } |
| 1485 | ; |
| 1486 | |
| 1487 | LexOf |
| 1488 | : { CYMAP(_of__, _of_); } |
| 1489 | ; |
| 1490 | |
| 1491 | LexBind |
| 1492 | : { CYMAP(OpenBrace_let, OpenBrace); CYMAP(OpenBracket_let, OpenBracket); } |
| 1493 | ; |
| 1494 | |
| 1495 | LetOrConst |
| 1496 | : LexLet LexOf "!let" LexBind LexOf { $$ = false; } |
| 1497 | | LexLet LexOf "const" { $$ = true; } |
| 1498 | ; |
| 1499 | |
| 1500 | BindingList_ |
| 1501 | : "," LexBind BindingList[bindings] { $$ = $bindings; } |
| 1502 | | { $$ = NULL; } |
| 1503 | ; |
| 1504 | |
| 1505 | BindingList |
| 1506 | : LexicalBinding[binding] BindingList_[next] { $$ = CYNew CYBindings($binding, $next); } |
| 1507 | ; |
| 1508 | |
| 1509 | LexicalBinding |
| 1510 | : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); } |
| 1511 | | LexOf BindingPattern Initializer { CYNOT(@$); } |
| 1512 | ; |
| 1513 | /* }}} */ |
| 1514 | /* 13.3.2 Variable Statement {{{ */ |
| 1515 | VariableStatement_ |
| 1516 | : Var_ VariableDeclarationList[bindings] { $$ = CYNew CYVar($bindings); } |
| 1517 | ; |
| 1518 | |
| 1519 | VariableStatement |
| 1520 | : VariableStatement_[statement] Terminator { $$ = $statement; } |
| 1521 | ; |
| 1522 | |
| 1523 | VariableDeclarationList_ |
| 1524 | : "," VariableDeclarationList[bindings] { $$ = $bindings; } |
| 1525 | | { $$ = NULL; } |
| 1526 | ; |
| 1527 | |
| 1528 | VariableDeclarationList |
| 1529 | : LexBind VariableDeclaration[binding] VariableDeclarationList_[next] { $$ = CYNew CYBindings($binding, $next); } |
| 1530 | ; |
| 1531 | |
| 1532 | VariableDeclaration |
| 1533 | : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); } |
| 1534 | | LexOf BindingPattern Initializer { CYNOT(@$); } |
| 1535 | ; |
| 1536 | /* }}} */ |
| 1537 | /* 13.3.3 Destructuring Binding Patterns {{{ */ |
| 1538 | BindingPattern |
| 1539 | : ObjectBindingPattern |
| 1540 | | ArrayBindingPattern |
| 1541 | ; |
| 1542 | |
| 1543 | ObjectBindingPattern |
| 1544 | : "let {" BindingPropertyListOpt "}" |
| 1545 | ; |
| 1546 | |
| 1547 | ArrayBindingPattern |
| 1548 | : "let [" BindingElementListOpt "]" |
| 1549 | ; |
| 1550 | |
| 1551 | BindingPropertyList_ |
| 1552 | : "," BindingPropertyListOpt |
| 1553 | | |
| 1554 | ; |
| 1555 | |
| 1556 | BindingPropertyList |
| 1557 | : BindingProperty BindingPropertyList_ |
| 1558 | ; |
| 1559 | |
| 1560 | BindingPropertyListOpt |
| 1561 | : BindingPropertyList |
| 1562 | | LexOf |
| 1563 | ; |
| 1564 | |
| 1565 | BindingElementList |
| 1566 | : BindingElementOpt[element] "," BindingElementListOpt[next] |
| 1567 | | BindingRestElement[element] |
| 1568 | | BindingElement[element] |
| 1569 | ; |
| 1570 | |
| 1571 | BindingElementListOpt |
| 1572 | : BindingElementList[pass] |
| 1573 | | LexBind LexOf |
| 1574 | ; |
| 1575 | |
| 1576 | BindingProperty |
| 1577 | : SingleNameBinding |
| 1578 | | LexOf PropertyName ":" BindingElement |
| 1579 | ; |
| 1580 | |
| 1581 | BindingElement |
| 1582 | : LexBind SingleNameBinding[pass] { $$ = $pass; } |
| 1583 | | LexBind LexOf BindingPattern InitializerOpt[initializer] { CYNOT(@$); } |
| 1584 | ; |
| 1585 | |
| 1586 | BindingElementOpt |
| 1587 | : BindingElement[pass] |
| 1588 | | LexBind LexOf |
| 1589 | ; |
| 1590 | |
| 1591 | SingleNameBinding |
| 1592 | : BindingIdentifier[identifier] InitializerOpt[initializer] { $$ = CYNew CYBinding($identifier, $initializer); } |
| 1593 | ; |
| 1594 | |
| 1595 | BindingRestElement |
| 1596 | : LexBind LexOf "..." BindingIdentifier |
| 1597 | ; |
| 1598 | /* }}} */ |
| 1599 | /* 13.4 Empty Statement {{{ */ |
| 1600 | EmptyStatement |
| 1601 | : ";" { $$ = CYNew CYEmpty(); } |
| 1602 | ; |
| 1603 | /* }}} */ |
| 1604 | /* 13.5 Expression Statement {{{ */ |
| 1605 | ExpressionStatement_ |
| 1606 | : Expression[expression] { $$ = CYNew CYExpress($[expression]); } |
| 1607 | |
| 1608 | ExpressionStatement |
| 1609 | : ExpressionStatement_[statement] Terminator { $$ = $statement; } |
| 1610 | ; |
| 1611 | /* }}} */ |
| 1612 | /* 13.6 The if Statement {{{ */ |
| 1613 | ElseStatementOpt |
| 1614 | : "else" Statement[false] { $$ = $false; } |
| 1615 | | %prec "if" { $$ = NULL; } |
| 1616 | ; |
| 1617 | |
| 1618 | IfStatement |
| 1619 | : "if" "(" Expression[test] ")" Statement[true] ElseStatementOpt[false] { $$ = CYNew CYIf($test, $true, $false); } |
| 1620 | ; |
| 1621 | /* }}} */ |
| 1622 | /* 13.7 Iteration Statements {{{ */ |
| 1623 | IterationStatement |
| 1624 | : "do" Statement[code] "while" "(" Expression[test] ")" TerminatorOpt { $$ = CYNew CYDoWhile($test, $code); } |
| 1625 | | "while" "(" Expression[test] ")" Statement[code] { $$ = CYNew CYWhile($test, $code); } |
| 1626 | | "for" "(" LexPushInOn ForStatementInitializer[initializer] LexPopIn ExpressionOpt[test] ";" ExpressionOpt[increment] ")" Statement[code] { $$ = CYNew CYFor($initializer, $test, $increment, $code); } |
| 1627 | | "for" "(" LexPushInOn LexLet LexOf Var_ LexBind BindingIdentifier[identifier] Initializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForInitialized(CYNew CYBinding($identifier, $initializer), $iterable, $code); } |
| 1628 | | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForIn($initializer, $iterable, $code); } |
| 1629 | | "for" "(" LexPushInOn ForInStatementInitializer[initializer] "of" LexPopIn AssignmentExpression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); } |
| 1630 | ; |
| 1631 | |
| 1632 | ForStatementInitializer |
| 1633 | : LexLet LexOf EmptyStatement[pass] { $$ = $pass; } |
| 1634 | | LexLet ExpressionStatement_[initializer] ";" { $$ = $initializer; } |
| 1635 | | LexLet LexOf VariableStatement_[initializer] ";" { $$ = $initializer; } |
| 1636 | | LexicalDeclaration_[initializer] ";" { $$ = $initializer; } |
| 1637 | ; |
| 1638 | |
| 1639 | ForInStatementInitializer |
| 1640 | : LexLet LexOf BracedExpression[pass] { $$ = $pass; } |
| 1641 | | LexLet LexOf IndirectExpression[pass] { $$ = $pass; } |
| 1642 | | LexLet LexOf Var_ LexBind ForBinding[binding] { $$ = CYNew CYForVariable($binding); } |
| 1643 | | ForDeclaration[pass] { $$ = $pass; } |
| 1644 | ; |
| 1645 | |
| 1646 | ForDeclaration |
| 1647 | : LetOrConst[constant] ForBinding[binding] { $$ = CYNew CYForLexical($constant, $binding); } |
| 1648 | ; |
| 1649 | |
| 1650 | ForBinding |
| 1651 | : BindingIdentifier[identifier] { $$ = CYNew CYBinding($identifier, NULL); } |
| 1652 | | LexOf BindingPattern { CYNOT(@$); } |
| 1653 | ; |
| 1654 | /* }}} */ |
| 1655 | /* 13.8 The continue Statement {{{ */ |
| 1656 | ContinueStatement |
| 1657 | : "continue" TerminatorSoft { $$ = CYNew CYContinue(NULL); } |
| 1658 | | "continue" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYContinue($label); } |
| 1659 | ; |
| 1660 | /* }}} */ |
| 1661 | /* 13.9 The break Statement {{{ */ |
| 1662 | BreakStatement |
| 1663 | : "break" TerminatorSoft { $$ = CYNew CYBreak(NULL); } |
| 1664 | | "break" NewLineNot LexOf Identifier[label] Terminator { $$ = CYNew CYBreak($label); } |
| 1665 | ; |
| 1666 | /* }}} */ |
| 1667 | /* 13.10 The return Statement {{{ */ |
| 1668 | ReturnStatement |
| 1669 | : Return TerminatorSoft { $$ = CYNew CYReturn(NULL); } |
| 1670 | | Return NewLineNot Expression[value] Terminator { $$ = CYNew CYReturn($value); } |
| 1671 | ; |
| 1672 | /* }}} */ |
| 1673 | /* 13.11 The with Statement {{{ */ |
| 1674 | WithStatement |
| 1675 | : "with" "(" Expression[scope] ")" Statement[code] { $$ = CYNew CYWith($scope, $code); } |
| 1676 | ; |
| 1677 | /* }}} */ |
| 1678 | /* 13.12 The switch Statement {{{ */ |
| 1679 | SwitchStatement |
| 1680 | : "switch" "(" Expression[value] ")" CaseBlock[clauses] { $$ = CYNew CYSwitch($value, $clauses); } |
| 1681 | ; |
| 1682 | |
| 1683 | CaseBlock |
| 1684 | : "{" CaseClausesOpt[clauses] "}" { $$ = $clauses; } |
| 1685 | ; |
| 1686 | |
| 1687 | CaseClause |
| 1688 | : "case" Expression[value] ":" StatementListOpt[code] { $$ = CYNew CYClause($value, $code); } |
| 1689 | ; |
| 1690 | |
| 1691 | CaseClausesOpt |
| 1692 | : CaseClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; } |
| 1693 | | DefaultClause[clause] CaseClausesOpt[next] { $clause->SetNext($next); $$ = $clause; } |
| 1694 | | { $$ = NULL; } |
| 1695 | ; |
| 1696 | |
| 1697 | // XXX: the standard makes certain you can only have one of these |
| 1698 | DefaultClause |
| 1699 | : "default" ":" StatementListOpt[code] { $$ = CYNew CYClause(NULL, $code); } |
| 1700 | ; |
| 1701 | /* }}} */ |
| 1702 | /* 13.13 Labelled Statements {{{ */ |
| 1703 | LabelledStatement |
| 1704 | : LabelIdentifier[name] ":" LabelledItem[statement] { $$ = CYNew CYLabel($name, $statement); } |
| 1705 | ; |
| 1706 | |
| 1707 | LabelledItem |
| 1708 | : Statement[pass] { $$ = $pass; } |
| 1709 | | LexSetStatement LexLet LexOf FunctionDeclaration[pass] { $$ = $pass; } |
| 1710 | ; |
| 1711 | /* }}} */ |
| 1712 | /* 13.14 The throw Statement {{{ */ |
| 1713 | ThrowStatement |
| 1714 | : "throw"[throw] TerminatorSoft { CYERR(@throw, "throw without exception"); } |
| 1715 | | "throw" NewLineNot Expression[value] Terminator { $$ = CYNew cy::Syntax::Throw($value); } |
| 1716 | ; |
| 1717 | /* }}} */ |
| 1718 | /* 13.15 The try Statement {{{ */ |
| 1719 | TryStatement |
| 1720 | : "try" Block[code] Catch[catch] { $$ = CYNew cy::Syntax::Try($code, $catch, NULL); } |
| 1721 | | "try" Block[code] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, NULL, $finally); } |
| 1722 | | "try" Block[code] Catch[catch] Finally[finally] { $$ = CYNew cy::Syntax::Try($code, $catch, $finally); } |
| 1723 | ; |
| 1724 | |
| 1725 | Catch |
| 1726 | : "catch" "(" LexBind CatchParameter[name] ")" Block[code] { $$ = CYNew cy::Syntax::Catch($name, $code); } |
| 1727 | ; |
| 1728 | |
| 1729 | Finally |
| 1730 | : "finally" Block[code] { $$ = CYNew CYFinally($code); } |
| 1731 | ; |
| 1732 | |
| 1733 | CatchParameter |
| 1734 | : BindingIdentifier[pass] { $$ = $pass; } |
| 1735 | | LexOf BindingPattern { CYNOT(@$); } |
| 1736 | ; |
| 1737 | /* }}} */ |
| 1738 | /* 13.16 The debugger Statement {{{ */ |
| 1739 | DebuggerStatement |
| 1740 | : "debugger" Terminator { $$ = CYNew CYDebugger(); } |
| 1741 | ; |
| 1742 | /* }}} */ |
| 1743 | |
| 1744 | /* 14.1 Function Definitions {{{ */ |
| 1745 | FunctionDeclaration |
| 1746 | : ";function" BindingIdentifier[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionStatement($name, $parameters, $code); } |
| 1747 | ; |
| 1748 | |
| 1749 | FunctionExpression |
| 1750 | : "function" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" LexPushSuperOff FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYFunctionExpression($name, $parameters, $code); } |
| 1751 | ; |
| 1752 | |
| 1753 | StrictFormalParameters |
| 1754 | : FormalParameters[pass] { $$ = $pass; } |
| 1755 | ; |
| 1756 | |
| 1757 | FormalParameters |
| 1758 | : LexBind LexOf { $$ = NULL; } |
| 1759 | | FormalParameterList |
| 1760 | ; |
| 1761 | |
| 1762 | FormalParameterList_ |
| 1763 | : "," FormalParameterList[parameters] { $$ = $parameters; } |
| 1764 | | { $$ = NULL; } |
| 1765 | ; |
| 1766 | |
| 1767 | FormalParameterList |
| 1768 | : FunctionRestParameter { CYNOT(@$); } |
| 1769 | | FormalParameter[binding] FormalParameterList_[next] { $$ = CYNew CYFunctionParameter($binding, $next); } |
| 1770 | ; |
| 1771 | |
| 1772 | FunctionRestParameter |
| 1773 | : BindingRestElement |
| 1774 | ; |
| 1775 | |
| 1776 | FormalParameter |
| 1777 | : BindingElement[pass] { $$ = $pass; } |
| 1778 | ; |
| 1779 | |
| 1780 | FunctionBody |
| 1781 | : LexPushYieldOff FunctionStatementList[code] LexPopYield { $$ = $code; } |
| 1782 | ; |
| 1783 | |
| 1784 | FunctionStatementList |
| 1785 | : LexPushReturnOn StatementListOpt[code] LexPopReturn { $$ = $code; } |
| 1786 | ; |
| 1787 | /* }}} */ |
| 1788 | /* 14.2 Arrow Function Definitions {{{ */ |
| 1789 | ArrowFunction |
| 1790 | : ArrowParameters[parameters] LexNewLineOrOpt "=>" LexNoBrace ConciseBody[code] { $$ = CYNew CYFatArrow($parameters, $code); } |
| 1791 | ; |
| 1792 | |
| 1793 | ArrowParameters |
| 1794 | : BindingIdentifier[identifier] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier)); } |
| 1795 | | LexOf CoverParenthesizedExpressionAndArrowParameterList[cover] { if ($cover == NULL) $$ = NULL; else { $$ = $cover->expression_->Parameter(); if ($$ == NULL) CYERR(@cover, "invalid parameter list"); } } |
| 1796 | ; |
| 1797 | |
| 1798 | ConciseBody |
| 1799 | : AssignmentExpression[expression] { $$ = CYNew CYReturn($expression); } |
| 1800 | | LexOf ";{" FunctionBody[code] "}" { $$ = $code; } |
| 1801 | ; |
| 1802 | /* }}} */ |
| 1803 | /* 14.3 Method Definitions {{{ */ |
| 1804 | MethodDefinition |
| 1805 | : PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyMethod($name, $parameters, $code); } |
| 1806 | | GeneratorMethod[pass] { $$ = $pass; } |
| 1807 | | "get" PropertyName[name] "(" ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertyGetter($name, $code); } |
| 1808 | | "set" PropertyName[name] "(" PropertySetParameterList[parameter] ")" "{" FunctionBody[code] "}" { $$ = CYNew CYPropertySetter($name, $parameter, $code); } |
| 1809 | ; |
| 1810 | |
| 1811 | PropertySetParameterList |
| 1812 | : FormalParameter[binding] { $$ = CYNew CYFunctionParameter($binding); } |
| 1813 | ; |
| 1814 | /* }}} */ |
| 1815 | /* 14.4 Generator Function Definitions {{{ */ |
| 1816 | GeneratorMethod |
| 1817 | : "*" PropertyName[name] "(" StrictFormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorMethod($name, $parameters, $code); */ } |
| 1818 | ; |
| 1819 | |
| 1820 | GeneratorDeclaration |
| 1821 | : ";function" LexOf "*" BindingIdentifier[name] "(" FormalParameters[code] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorStatement($name, $parameters, $code); */ } |
| 1822 | ; |
| 1823 | |
| 1824 | GeneratorExpression |
| 1825 | : "function" LexOf "*" BindingIdentifierOpt[name] "(" FormalParameters[parameters] ")" "{" GeneratorBody[code] "}" { CYNOT(@$); /* $$ = CYNew CYGeneratorExpression($name, $parameters, $code); */ } |
| 1826 | ; |
| 1827 | |
| 1828 | GeneratorBody |
| 1829 | : LexPushYieldOn FunctionStatementList[code] LexPopYield { $$ = $code; } |
| 1830 | ; |
| 1831 | |
| 1832 | YieldExpression |
| 1833 | : "!yield" LexNewLineOrNot "\n" LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ } |
| 1834 | | "!yield" LexNewLineOrNot "" LexNoStar LexOf { CYNOT(@$); /* $$ = CYNew CYYieldValue(NULL); */ } %prec "!yield" |
| 1835 | | "!yield" LexNewLineOrNot "" LexNoStar AssignmentExpression[value] { CYNOT(@$); /* $$ = CYNew CYYieldValue($value); */ } |
| 1836 | | "!yield" LexNewLineOrNot "" LexNoStar LexOf "yield *" AssignmentExpression[generator] { CYNOT(@$); /* $$ = CYNew CYYieldGenerator($generator); */ } |
| 1837 | ; |
| 1838 | /* }}} */ |
| 1839 | /* 14.5 Class Definitions {{{ */ |
| 1840 | ClassDeclaration |
| 1841 | : ";class" BindingIdentifier[name] ClassTail[tail] { $$ = CYNew CYClassStatement($name, $tail); } |
| 1842 | ; |
| 1843 | |
| 1844 | ClassExpression |
| 1845 | : "class" BindingIdentifierOpt[name] ClassTail[tail] { $$ = CYNew CYClassExpression($name, $tail); } |
| 1846 | ; |
| 1847 | |
| 1848 | ClassTail |
| 1849 | : ClassHeritageOpt[tail] { driver.class_.push($tail); } "{" LexPushSuperOn ClassBodyOpt "}" LexPopSuper { driver.class_.pop(); $$ = $tail; } |
| 1850 | ; |
| 1851 | |
| 1852 | ClassHeritage |
| 1853 | : "extends" AccessExpression[extends] { $$ = CYNew CYClassTail($extends); } |
| 1854 | ; |
| 1855 | |
| 1856 | ClassHeritageOpt |
| 1857 | : ClassHeritage[pass] { $$ = $pass; } |
| 1858 | | { $$ = CYNew CYClassTail(NULL); } |
| 1859 | ; |
| 1860 | |
| 1861 | ClassBody |
| 1862 | : ClassElementList |
| 1863 | ; |
| 1864 | |
| 1865 | ClassBodyOpt |
| 1866 | : ClassBody |
| 1867 | | |
| 1868 | ; |
| 1869 | |
| 1870 | ClassElementList |
| 1871 | : ClassElementListOpt ClassElement |
| 1872 | ; |
| 1873 | |
| 1874 | ClassElementListOpt |
| 1875 | : ClassElementList |
| 1876 | | |
| 1877 | ; |
| 1878 | |
| 1879 | ClassElement |
| 1880 | : MethodDefinition[method] { if (CYFunctionExpression *constructor = $method->Constructor()) driver.class_.top()->constructor_ = constructor; else driver.class_.top()->instance_->*$method; } |
| 1881 | | "static" MethodDefinition[method] { driver.class_.top()->static_->*$method; } |
| 1882 | | ";" |
| 1883 | ; |
| 1884 | /* }}} */ |
| 1885 | |
| 1886 | /* 15.1 Scripts {{{ */ |
| 1887 | Script |
| 1888 | : ScriptBodyOpt[code] { driver.script_ = CYNew CYScript($code); } |
| 1889 | ; |
| 1890 | |
| 1891 | ScriptBody |
| 1892 | : StatementList[pass] { $$ = $pass; } |
| 1893 | ; |
| 1894 | |
| 1895 | ScriptBodyOpt |
| 1896 | : ScriptBody[pass] { $$ = $pass; } |
| 1897 | | LexSetStatement LexLet LexOf { $$ = NULL; } |
| 1898 | ; |
| 1899 | /* }}} */ |
| 1900 | /* 15.2 Modules {{{ */ |
| 1901 | Module |
| 1902 | : ModuleBodyOpt[code] { driver.script_ = CYNew CYScript($code); } |
| 1903 | ; |
| 1904 | |
| 1905 | ModuleBody |
| 1906 | : ModuleItemList[pass] { $$ = $pass; } |
| 1907 | ; |
| 1908 | |
| 1909 | ModuleBodyOpt |
| 1910 | : ModuleBody[pass] { $$ = $pass; } |
| 1911 | | LexSetStatement LexLet LexOf { $$ = NULL; } |
| 1912 | ; |
| 1913 | |
| 1914 | ModuleItemList |
| 1915 | : ModuleItem[statement] ModuleItemListOpt[next] { $$ = $statement; CYSetLast($$) = $next; } |
| 1916 | ; |
| 1917 | |
| 1918 | ModuleItemListOpt |
| 1919 | : ModuleItemList[pass] { $$ = $pass; } |
| 1920 | | LexSetStatement LexLet LexOf { $$ = NULL; } |
| 1921 | ; |
| 1922 | |
| 1923 | ModuleItem |
| 1924 | : LexSetStatement LexLet LexOf ImportDeclaration[pass] { $$ = $pass; } |
| 1925 | | LexSetStatement LexLet LexOf ExportDeclaration { CYNOT(@$); } |
| 1926 | | StatementListItem[pass] { $$ = $pass; } |
| 1927 | ; |
| 1928 | /* }}} */ |
| 1929 | /* 15.2.2 Imports {{{ */ |
| 1930 | ImportDeclaration |
| 1931 | : "import" ImportClause[specifiers] FromClause[module] Terminator { $$ = CYNew CYImportDeclaration($specifiers, $module); } |
| 1932 | | "import" LexOf ModuleSpecifier[module] Terminator { $$ = CYNew CYImportDeclaration(NULL, $module); } |
| 1933 | ; |
| 1934 | |
| 1935 | ImportClause |
| 1936 | : ImportedDefaultBinding[default] { $$ = $default; } |
| 1937 | | LexOf NameSpaceImport[pass] { $$ = $pass; } |
| 1938 | | LexOf NamedImports[pass] { $$ = $pass; } |
| 1939 | | ImportedDefaultBinding[default] "," NameSpaceImport[next] { $$ = $default; CYSetLast($$) = $next; } |
| 1940 | | ImportedDefaultBinding[default] "," NamedImports[next] { $$ = $default; CYSetLast($$) = $next; } |
| 1941 | ; |
| 1942 | |
| 1943 | ImportedDefaultBinding |
| 1944 | : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(CYNew CYIdentifier("default"), $binding); } |
| 1945 | ; |
| 1946 | |
| 1947 | NameSpaceImport |
| 1948 | : "*" "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier(NULL, $binding); } |
| 1949 | ; |
| 1950 | |
| 1951 | NamedImports |
| 1952 | : "{" ImportsListOpt[pass] "}" { $$ = $pass; } |
| 1953 | ; |
| 1954 | |
| 1955 | FromClause |
| 1956 | : "from" ModuleSpecifier[pass] { $$ = $pass; } |
| 1957 | ; |
| 1958 | |
| 1959 | ImportsList_ |
| 1960 | : "," ImportsListOpt[pass] { $$ = $pass; } |
| 1961 | | { $$ = NULL; } |
| 1962 | ; |
| 1963 | |
| 1964 | ImportsList |
| 1965 | : ImportSpecifier[import] ImportsList_[next] { $$ = $import; CYSetLast($$) = $next; } |
| 1966 | ; |
| 1967 | |
| 1968 | ImportsListOpt |
| 1969 | : ImportsList[pass] { $$ = $pass; } |
| 1970 | | LexOf { $$ = NULL; } |
| 1971 | ; |
| 1972 | |
| 1973 | ImportSpecifier |
| 1974 | : ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($binding, $binding); } |
| 1975 | | LexOf IdentifierName[name] "as" ImportedBinding[binding] { $$ = CYNew CYImportSpecifier($name, $binding); } |
| 1976 | ; |
| 1977 | |
| 1978 | ModuleSpecifier |
| 1979 | : StringLiteral[pass] { $$ = $pass; } |
| 1980 | ; |
| 1981 | |
| 1982 | ImportedBinding |
| 1983 | : BindingIdentifier[pass] { $$ = $pass; } |
| 1984 | ; |
| 1985 | /* }}} */ |
| 1986 | /* 15.2.3 Exports {{{ */ |
| 1987 | ExportDeclaration_ |
| 1988 | : "*" FromClause Terminator |
| 1989 | | ExportClause FromClause Terminator |
| 1990 | | ExportClause Terminator |
| 1991 | | VariableStatement |
| 1992 | | "default" LexSetStatement LexOf HoistableDeclaration |
| 1993 | | "default" LexSetStatement LexOf ClassDeclaration |
| 1994 | | "default" LexSetStatement AssignmentExpression Terminator |
| 1995 | ; |
| 1996 | |
| 1997 | ExportDeclaration |
| 1998 | : "export" LexSetStatement LexLet LexOf ExportDeclaration_ |
| 1999 | | "export" Declaration |
| 2000 | ; |
| 2001 | |
| 2002 | ExportClause |
| 2003 | : ";{" ExportsListOpt "}" |
| 2004 | ; |
| 2005 | |
| 2006 | ExportsList_ |
| 2007 | : "," ExportsListOpt |
| 2008 | | |
| 2009 | ; |
| 2010 | |
| 2011 | ExportsList |
| 2012 | : ExportSpecifier ExportsList_ |
| 2013 | ; |
| 2014 | |
| 2015 | ExportsListOpt |
| 2016 | : ExportsList |
| 2017 | | |
| 2018 | ; |
| 2019 | |
| 2020 | ExportSpecifier |
| 2021 | : IdentifierName |
| 2022 | | IdentifierName "as" IdentifierName |
| 2023 | ; |
| 2024 | /* }}} */ |
| 2025 | |
| 2026 | @begin C |
| 2027 | /* Cycript (C): Type Encoding {{{ */ |
| 2028 | TypeSignifier |
| 2029 | : IdentifierType[name] { $$ = CYNew CYTypedName(@name, $name); } |
| 2030 | | StringLiteral[name] { $$ = CYNew CYTypedName(@name, $name); } |
| 2031 | | NumericLiteral[name] { $$ = CYNew CYTypedName(@name, $name); } |
| 2032 | | "(" "*" TypeQualifierRightOpt[typed] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); } |
| 2033 | ; |
| 2034 | |
| 2035 | TypeSignifierNone |
| 2036 | : { $$ = CYNew CYTypedName(@$); } |
| 2037 | ; |
| 2038 | |
| 2039 | TypeSignifierOpt |
| 2040 | : TypeSignifier[pass] { $$ = $pass; } |
| 2041 | | TypeSignifierNone[pass] { $$ = $pass; } |
| 2042 | ; |
| 2043 | |
| 2044 | ParameterTail |
| 2045 | : TypedParameterListOpt[formal] ")" { $$ = CYNew CYTypeFunctionWith($formal->variadic_, $formal->parameters_); } |
| 2046 | ; |
| 2047 | |
| 2048 | SuffixedType |
| 2049 | : SuffixedTypeOpt[typed] "[" AssignmentExpression[size] "]" { $$ = $typed; $$->modifier_ = CYNew CYTypeArrayOf($size, $$->modifier_); } |
| 2050 | | "(" "^" TypeQualifierRightOpt[typed] ")" "(" TypedParameters[parameters] ")" { $$ = $typed; $$->modifier_ = CYNew CYTypeBlockWith($parameters, $$->modifier_); } |
| 2051 | | TypeSignifier[typed] "(" ParameterTail[modifier] { $$ = $typed; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } |
| 2052 | | "("[parenthesis] ParameterTail[modifier] { $$ = CYNew CYTypedName(@parenthesis); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } |
| 2053 | ; |
| 2054 | |
| 2055 | SuffixedTypeOpt |
| 2056 | : SuffixedType[pass] { $$ = $pass; } |
| 2057 | | TypeSignifierOpt[pass] { $$ = $pass; } |
| 2058 | ; |
| 2059 | |
| 2060 | PrefixedType |
| 2061 | : "*" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypePointerTo($$->modifier_); } |
| 2062 | ; |
| 2063 | |
| 2064 | TypeQualifierLeft |
| 2065 | : "const" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeConstant(); } |
| 2066 | | "volatile" TypeQualifierLeftOpt[modifier] { $$ = $modifier; CYSetLast($$) = CYNew CYTypeVolatile(); } |
| 2067 | ; |
| 2068 | |
| 2069 | TypeQualifierLeftOpt |
| 2070 | : TypeQualifierLeft[pass] { $$ = $pass; } |
| 2071 | | { $$ = NULL; } |
| 2072 | ; |
| 2073 | |
| 2074 | TypeQualifierRight |
| 2075 | : SuffixedType[pass] { $$ = $pass; } |
| 2076 | | PrefixedType[pass] { $$ = $pass; } |
| 2077 | | "const" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeConstant($$->modifier_); } |
| 2078 | | "volatile" TypeQualifierRightOpt[typed] { $$ = $typed; $$->modifier_ = CYNew CYTypeVolatile($$->modifier_); } |
| 2079 | ; |
| 2080 | |
| 2081 | TypeQualifierRightOpt |
| 2082 | : TypeQualifierRight[pass] { $$ = $pass; } |
| 2083 | | TypeSignifierOpt[pass] { $$ = $pass; } |
| 2084 | ; |
| 2085 | |
| 2086 | IntegerType |
| 2087 | : "int" { $$ = CYNew CYTypeIntegral(CYTypeNeutral); } |
| 2088 | | "unsigned" IntegerTypeOpt[integral] { $$ = $integral->Unsigned(); if ($$ == NULL) CYERR(@1, "incompatible unsigned"); } |
| 2089 | | "signed" IntegerTypeOpt[integral] { $$ = $integral->Signed(); if ($$ == NULL) CYERR(@1, "incompatible signed"); } |
| 2090 | | "long" IntegerTypeOpt[integral] { $$ = $integral->Long(); if ($$ == NULL) CYERR(@1, "incompatible long"); } |
| 2091 | | "short" IntegerTypeOpt[integral] { $$ = $integral->Short(); if ($$ == NULL) CYERR(@1, "incompatible short"); } |
| 2092 | ; |
| 2093 | |
| 2094 | IntegerTypeOpt |
| 2095 | : IntegerType[pass] { $$ = $pass; } |
| 2096 | | { $$ = CYNew CYTypeIntegral(CYTypeNeutral); } |
| 2097 | ; |
| 2098 | |
| 2099 | StructFieldListOpt |
| 2100 | : TypedIdentifierField[typed] ";" StructFieldListOpt[next] { $$ = CYNew CYTypeStructField($typed, $typed->name_, $next); } |
| 2101 | | { $$ = NULL; } |
| 2102 | ; |
| 2103 | |
| 2104 | IntegerNumber |
| 2105 | : NumericLiteral[pass] { $$ = $pass; } |
| 2106 | | "-" NumericLiteral[positive] { $$ = $positive; $$->value_ = -$$->value_; } |
| 2107 | ; |
| 2108 | |
| 2109 | EnumConstantListOpt_ |
| 2110 | : "," EnumConstantListOpt[pass] { $$ = $pass; } |
| 2111 | | { $$ = NULL; } |
| 2112 | ; |
| 2113 | |
| 2114 | EnumConstantListOpt |
| 2115 | : IdentifierType[name] "=" IntegerNumber[value] EnumConstantListOpt_[next] { $$ = CYNew CYEnumConstant($name, $value, $next); } |
| 2116 | | { $$ = NULL; } |
| 2117 | ; |
| 2118 | |
| 2119 | TypeSigning |
| 2120 | : { $$ = CYTypeNeutral; } |
| 2121 | | "signed" { $$ = CYTypeSigned; } |
| 2122 | | "unsigned" { $$ = CYTypeUnsigned; } |
| 2123 | ; |
| 2124 | |
| 2125 | PrimitiveType |
| 2126 | : IdentifierType[name] { $$ = CYNew CYTypeVariable($name); } |
| 2127 | | IntegerType[pass] { $$ = $pass; } |
| 2128 | | TypeSigning[signing] "char" { $$ = CYNew CYTypeCharacter($signing); } |
| 2129 | | TypeSigning[signing] "__int128" { $$ = CYNew CYTypeInt128($signing); } |
| 2130 | | "float" { $$ = CYNew CYTypeFloating(0); } |
| 2131 | | "double" { $$ = CYNew CYTypeFloating(1); } |
| 2132 | | "long" "double" { $$ = CYNew CYTypeFloating(2); } |
| 2133 | | "void" { $$ = CYNew CYTypeVoid(); } |
| 2134 | ; |
| 2135 | |
| 2136 | PrimitiveReference |
| 2137 | : PrimitiveType[pass] { $$ = $pass; } |
| 2138 | | "struct" IdentifierType[name] { $$ = CYNew CYTypeReference(CYTypeReferenceStruct, $name); } |
| 2139 | | "enum" IdentifierType[name] { $$ = CYNew CYTypeReference(CYTypeReferenceEnum, $name); } |
| 2140 | | "struct" AutoComplete { driver.mode_ = CYDriver::AutoStruct; YYACCEPT; } |
| 2141 | | "enum" AutoComplete { driver.mode_ = CYDriver::AutoEnum; YYACCEPT; } |
| 2142 | ; |
| 2143 | |
| 2144 | TypedIdentifierMaybe |
| 2145 | : TypeQualifierLeftOpt[modifier] PrimitiveReference[specifier] TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = $specifier; CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } |
| 2146 | ; |
| 2147 | |
| 2148 | TypedIdentifierYes |
| 2149 | : TypedIdentifierMaybe[typed] { if ($typed->name_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; } |
| 2150 | ; |
| 2151 | |
| 2152 | TypedIdentifierNo |
| 2153 | : TypedIdentifierMaybe[typed] { if ($typed->name_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; } |
| 2154 | ; |
| 2155 | |
| 2156 | TypedIdentifierTagged |
| 2157 | : TypeQualifierLeftOpt[modifier] "struct" "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeStruct(NULL, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } |
| 2158 | | TypeQualifierLeftOpt[modifier] "enum" ":" PrimitiveType[specifier] "{" EnumConstantListOpt[constants] "}" TypeQualifierRightOpt[typed] { $$ = $typed; $$->specifier_ = CYNew CYTypeEnum(NULL, $specifier, $constants); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } |
| 2159 | ; |
| 2160 | |
| 2161 | TypedIdentifierField |
| 2162 | : TypedIdentifierYes[pass] { $$ = $pass; } |
| 2163 | | TypedIdentifierTagged[typed] { if ($typed->name_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; } |
| 2164 | ; |
| 2165 | |
| 2166 | TypedIdentifierEncoding |
| 2167 | : TypedIdentifierNo[pass] { $$ = $pass; } |
| 2168 | | TypedIdentifierTagged[typed] { if ($typed->name_ != NULL) CYERR($typed->location_, "unexpected identifier"); $$ = $typed; } |
| 2169 | ; |
| 2170 | |
| 2171 | TypedIdentifierDefinition |
| 2172 | : TypedIdentifierYes[pass] { $$ = $pass; } |
| 2173 | | TypeQualifierLeftOpt[modifier] "struct" IdentifierTypeOpt[name] "{" StructFieldListOpt[fields] "}" TypeQualifierRightOpt[typed] { if ($typed->name_ == NULL) CYERR($typed->location_, "expected identifier"); $$ = $typed; $$->specifier_ = CYNew CYTypeStruct($name, CYNew CYStructTail($fields)); CYSetLast($modifier) = $$->modifier_; $$->modifier_ = $modifier; } |
| 2174 | ; |
| 2175 | |
| 2176 | PrimaryExpression |
| 2177 | : "@encode" "(" TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYEncodedType($typed); } |
| 2178 | ; |
| 2179 | /* }}} */ |
| 2180 | @end |
| 2181 | |
| 2182 | @begin ObjectiveC |
| 2183 | /* Cycript (Objective-C): @class Declaration {{{ */ |
| 2184 | ClassSuperOpt |
| 2185 | /* XXX: why the hell did I choose MemberExpression? */ |
| 2186 | : ":" MemberExpression[extends] { $$ = $extends; } |
| 2187 | | { $$ = NULL; } |
| 2188 | ; |
| 2189 | |
| 2190 | ImplementationFieldListOpt |
| 2191 | : TypedIdentifierField[typed] ";" ImplementationFieldListOpt[next] { $$ = CYNew CYImplementationField($typed, $typed->name_, $next); } |
| 2192 | | { $$ = NULL; } |
| 2193 | ; |
| 2194 | |
| 2195 | MessageScope |
| 2196 | : "+" { $$ = false; } |
| 2197 | | "-" { $$ = true; } |
| 2198 | ; |
| 2199 | |
| 2200 | TypeOpt |
| 2201 | : "(" TypedIdentifierNo[type] ")" { $$ = $type; } |
| 2202 | | { $$ = CYNew CYType(CYNew CYTypeVariable("id")); } |
| 2203 | ; |
| 2204 | |
| 2205 | MessageParameter |
| 2206 | : Word[tag] ":" TypeOpt[type] BindingIdentifier[identifier] { $$ = CYNew CYMessageParameter($tag, $type, $identifier); } |
| 2207 | ; |
| 2208 | |
| 2209 | MessageParameterList |
| 2210 | : MessageParameter[parameter] MessageParameterListOpt[next] { $parameter->SetNext($next); $$ = $parameter; } |
| 2211 | ; |
| 2212 | |
| 2213 | MessageParameterListOpt |
| 2214 | : MessageParameterList[pass] { $$ = $pass; } |
| 2215 | | TypedParameterList_[formal] { if ($formal->variadic_) CYERR(@$, "unsupported variadic"); /*XXX*/ if ($formal->parameters_ != NULL) CYERR(@$, "temporarily unsupported"); $$ = NULL; } |
| 2216 | ; |
| 2217 | |
| 2218 | MessageParameters |
| 2219 | : MessageParameterList[pass] { $$ = $pass; } |
| 2220 | | Word[tag] { $$ = CYNew CYMessageParameter($tag); } |
| 2221 | ; |
| 2222 | |
| 2223 | ClassMessageDeclaration |
| 2224 | : MessageScope[instance] TypeOpt[type] MessageParameters[parameters] "{" LexPushSuperOn FunctionBody[code] "}" LexPopSuper { $$ = CYNew CYMessage($instance, $type, $parameters, $code); } |
| 2225 | ; |
| 2226 | |
| 2227 | ClassMessageDeclarationListOpt |
| 2228 | : ClassMessageDeclarationListOpt[next] ClassMessageDeclaration[message] { $message->SetNext($next); $$ = $message; } |
| 2229 | | { $$ = NULL; } |
| 2230 | ; |
| 2231 | |
| 2232 | // XXX: this should be AssignmentExpressionNoRight |
| 2233 | ClassProtocols |
| 2234 | : ShiftExpression[name] ClassProtocolsOpt[next] { $$ = CYNew CYProtocol($name, $next); } |
| 2235 | ; |
| 2236 | |
| 2237 | ClassProtocolsOpt |
| 2238 | : "," ClassProtocols[protocols] { $$ = $protocols; } |
| 2239 | | { $$ = NULL; } |
| 2240 | ; |
| 2241 | |
| 2242 | ClassProtocolListOpt |
| 2243 | : "<" ClassProtocols[protocols] ">" { $$ = $protocols; } |
| 2244 | | { $$ = NULL; } |
| 2245 | ; |
| 2246 | |
| 2247 | ImplementationStatement |
| 2248 | : "@implementation" Identifier[name] ClassSuperOpt[extends] ClassProtocolListOpt[protocols] "{" ImplementationFieldListOpt[fields] "}" ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYImplementation($name, $extends, $protocols, $fields, $messages); } |
| 2249 | ; |
| 2250 | |
| 2251 | CategoryName |
| 2252 | : "(" WordOpt ")" |
| 2253 | ; |
| 2254 | |
| 2255 | CategoryStatement |
| 2256 | : "@implementation" Identifier[name] CategoryName ClassMessageDeclarationListOpt[messages] "@end" { $$ = CYNew CYCategory($name, $messages); } |
| 2257 | ; |
| 2258 | |
| 2259 | Statement__ |
| 2260 | : ImplementationStatement[pass] { $$ = $pass; } |
| 2261 | | CategoryStatement[pass] { $$ = $pass; } |
| 2262 | ; |
| 2263 | /* }}} */ |
| 2264 | /* Cycript (Objective-C): Send Message {{{ */ |
| 2265 | VariadicCall |
| 2266 | : "," AssignmentExpressionClassic[value] VariadicCall[next] { $$ = CYNew CYArgument(NULL, $value, $next); } |
| 2267 | | { $$ = NULL; } |
| 2268 | ; |
| 2269 | |
| 2270 | SelectorWordOpt |
| 2271 | : WordOpt[name] { driver.contexts_.back().words_.push_back($name); } { $$ = $name; } |
| 2272 | | AutoComplete { driver.mode_ = CYDriver::AutoMessage; YYACCEPT; } |
| 2273 | ; |
| 2274 | |
| 2275 | SelectorCall_ |
| 2276 | : SelectorCall[pass] { $$ = $pass; } |
| 2277 | | VariadicCall[pass] { $$ = $pass; } |
| 2278 | ; |
| 2279 | |
| 2280 | SelectorCall |
| 2281 | : SelectorWordOpt[name] ":" AssignmentExpressionClassic[value] SelectorCall_[next] { $$ = CYNew CYArgument($name ?: CYNew CYWord(""), $value, $next); } |
| 2282 | ; |
| 2283 | |
| 2284 | SelectorList |
| 2285 | : SelectorCall[pass] { $$ = $pass; } |
| 2286 | | Word[name] { $$ = CYNew CYArgument($name, NULL); } |
| 2287 | ; |
| 2288 | |
| 2289 | MessageExpression |
| 2290 | : "[" AssignmentExpressionClassic[self] { driver.contexts_.push_back($self); } SelectorList[arguments] "]" { driver.contexts_.pop_back(); } { $$ = CYNew CYSendDirect($self, $arguments); } |
| 2291 | | "[" LexOf "super" { driver.context_ = NULL; } SelectorList[arguments] "]" { $$ = CYNew CYSendSuper($arguments); } |
| 2292 | ; |
| 2293 | |
| 2294 | SelectorExpression_ |
| 2295 | : WordOpt[name] ":" SelectorExpressionOpt[next] { $$ = CYNew CYSelectorPart($name, true, $next); } |
| 2296 | ; |
| 2297 | |
| 2298 | SelectorExpression |
| 2299 | : SelectorExpression_[pass] { $$ = $pass; } |
| 2300 | | Word[name] { $$ = CYNew CYSelectorPart($name, false, NULL); } |
| 2301 | ; |
| 2302 | |
| 2303 | SelectorExpressionOpt |
| 2304 | : SelectorExpression_[pass] { $$ = $pass; } |
| 2305 | | { $$ = NULL; } |
| 2306 | ; |
| 2307 | |
| 2308 | PrimaryExpression |
| 2309 | : MessageExpression[pass] { $$ = $pass; } |
| 2310 | | "@selector" "(" SelectorExpression[parts] ")" { $$ = CYNew CYSelector($parts); } |
| 2311 | ; |
| 2312 | /* }}} */ |
| 2313 | @end |
| 2314 | |
| 2315 | /* Cycript: @import Directive {{{ */ |
| 2316 | ModulePath |
| 2317 | : ModulePath[next] "." Word[part] { $$ = CYNew CYModule($part, $next); } |
| 2318 | | Word[part] { $$ = CYNew CYModule($part); } |
| 2319 | ; |
| 2320 | |
| 2321 | Declaration_ |
| 2322 | : "@import" ModulePath[path] { $$ = CYNew CYImport($path); } |
| 2323 | ; |
| 2324 | /* }}} */ |
| 2325 | |
| 2326 | @begin ObjectiveC |
| 2327 | /* Cycript (Objective-C): Boxed Expressions {{{ */ |
| 2328 | BoxableExpression |
| 2329 | : NullLiteral[pass] { $$ = $pass; } |
| 2330 | | BooleanLiteral[pass] { $$ = $pass; } |
| 2331 | | NumericLiteral[pass] { $$ = $pass; } |
| 2332 | | StringLiteral[pass] { $$ = $pass; } |
| 2333 | | CoverParenthesizedExpressionAndArrowParameterList[pass] { $$ = $pass; } |
| 2334 | | "YES" { $$ = CYNew CYTrue(); } |
| 2335 | | "NO" { $$ = CYNew CYFalse(); } |
| 2336 | ; |
| 2337 | |
| 2338 | KeyValuePairList_ |
| 2339 | : "," KeyValuePairListOpt[next] { $$ = $next; } |
| 2340 | | { $$ = NULL; } |
| 2341 | |
| 2342 | KeyValuePairList |
| 2343 | : AssignmentExpression[key] ":" AssignmentExpression[value] KeyValuePairList_[next] { $$ = CYNew CYObjCKeyValue($key, $value, $next); } |
| 2344 | ; |
| 2345 | |
| 2346 | KeyValuePairListOpt |
| 2347 | : KeyValuePairList[pass] { $$ = $pass; } |
| 2348 | | LexOf { $$ = NULL; } |
| 2349 | ; |
| 2350 | |
| 2351 | PrimaryExpression |
| 2352 | : "@" BoxableExpression[expression] { $$ = CYNew CYBox($expression); } |
| 2353 | | "@" "[" ElementListOpt[elements] "]" { $$ = CYNew CYObjCArray($elements); } |
| 2354 | | "@" "{" KeyValuePairListOpt[pairs] "}" { $$ = CYNew CYObjCDictionary($pairs); } |
| 2355 | |
| 2356 | | "@YES" { $$ = CYNew CYBox(CYNew CYTrue()); } |
| 2357 | | "@NO" { $$ = CYNew CYBox(CYNew CYFalse()); } |
| 2358 | | "@true" { $$ = CYNew CYBox(CYNew CYTrue()); } |
| 2359 | | "@false" { $$ = CYNew CYBox(CYNew CYFalse()); } |
| 2360 | | "@null" { $$ = CYNew CYBox(CYNew CYNull()); } |
| 2361 | ; |
| 2362 | /* }}} */ |
| 2363 | /* Cycript (Objective-C): Block Expressions {{{ */ |
| 2364 | PrimaryExpression |
| 2365 | : "^" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { if (CYTypeFunctionWith *function = $type->Function()) $$ = CYNew CYObjCBlock($type, function->parameters_, $code); else CYERR($type->location_, "expected parameters"); } |
| 2366 | ; |
| 2367 | /* }}} */ |
| 2368 | /* Cycript (Objective-C): Instance Literals {{{ */ |
| 2369 | PrimaryExpression |
| 2370 | : "#" NumericLiteral[address] { $$ = CYNew CYInstanceLiteral($address); } |
| 2371 | ; |
| 2372 | /* }}} */ |
| 2373 | @end |
| 2374 | |
| 2375 | @begin C |
| 2376 | /* Cycript (C): Pointer Indirection/Addressing {{{ */ |
| 2377 | UnaryExpression_ |
| 2378 | : IndirectExpression[pass] { $$ = $pass; } |
| 2379 | ; |
| 2380 | |
| 2381 | IndirectExpression |
| 2382 | : "*" UnaryExpression[rhs] { $$ = CYNew CYIndirect($rhs); } |
| 2383 | ; |
| 2384 | |
| 2385 | UnaryExpression_ |
| 2386 | : "&" UnaryExpression[rhs] { $$ = CYNew CYAddressOf($rhs); } |
| 2387 | ; |
| 2388 | |
| 2389 | MemberAccess |
| 2390 | : "->" "[" Expression[property] "]" { $$ = CYNew CYIndirectMember(NULL, $property); } |
| 2391 | | "->" IdentifierName[property] { $$ = CYNew CYIndirectMember(NULL, CYNew CYString($property)); } |
| 2392 | | "->" AutoComplete { driver.mode_ = CYDriver::AutoIndirect; YYACCEPT; } |
| 2393 | ; |
| 2394 | /* }}} */ |
| 2395 | /* Cycript (C): Lambda Expressions {{{ */ |
| 2396 | TypedParameterList_ |
| 2397 | : "," TypedParameterList[parameters] { $$ = $parameters; } |
| 2398 | | { $$ = CYNew CYTypedFormal(false); } |
| 2399 | ; |
| 2400 | |
| 2401 | TypedParameterList |
| 2402 | : TypedIdentifierMaybe[typed] TypedParameterList_[formal] { CYIdentifier *identifier; if ($typed->name_ == NULL) identifier = NULL; else { identifier = $typed->name_->Identifier(); if (identifier == NULL) CYERR($typed->location_, "invalid identifier"); } $$ = $formal; $$->parameters_ = CYNew CYTypedParameter($typed, identifier, $$->parameters_); } |
| 2403 | | "..." { $$ = CYNew CYTypedFormal(true); } |
| 2404 | ; |
| 2405 | |
| 2406 | TypedParameterListOpt |
| 2407 | : TypedParameterList[pass] { $$ = $pass; } |
| 2408 | | { $$ = CYNew CYTypedFormal(false); } |
| 2409 | ; |
| 2410 | |
| 2411 | TypedParameters |
| 2412 | : TypedParameterListOpt[formal] { if ($formal->variadic_) CYERR(@$, "unsupported variadic"); $$ = $formal->parameters_; } |
| 2413 | ; |
| 2414 | |
| 2415 | PrimaryExpression |
| 2416 | : "[" LexOf "&" "]" "(" TypedParameters[parameters] ")" "->" TypedIdentifierNo[type] "{" FunctionBody[code] "}" { $$ = CYNew CYLambda($type, $parameters, $code); } |
| 2417 | ; |
| 2418 | /* }}} */ |
| 2419 | /* Cycript (C): Structure Definitions {{{ */ |
| 2420 | IdentifierNoOf |
| 2421 | : "struct" NewLineOpt { $$ = CYNew CYIdentifier("struct"); } |
| 2422 | ; |
| 2423 | |
| 2424 | Statement__ |
| 2425 | : "struct" NewLineNot IdentifierType[name] "{" StructFieldListOpt[fields] "}" { $$ = CYNew CYStructDefinition($name, CYNew CYStructTail($fields)); } |
| 2426 | ; |
| 2427 | |
| 2428 | PrimaryExpression |
| 2429 | : "(" LexOf "struct" NewLineOpt IdentifierType[name] TypeQualifierRightOpt[typed] ")" { $typed->specifier_ = CYNew CYTypeReference(CYTypeReferenceStruct, $name); $$ = CYNew CYTypeExpression($typed); } |
| 2430 | | "(" LexOf "struct" NewLineOpt AutoComplete { driver.mode_ = CYDriver::AutoStruct; YYACCEPT; } |
| 2431 | ; |
| 2432 | /* }}} */ |
| 2433 | /* Cycript (C): Type Definitions {{{ */ |
| 2434 | IdentifierNoOf |
| 2435 | : "typedef" NewLineOpt { $$ = CYNew CYIdentifier("typedef"); } |
| 2436 | ; |
| 2437 | |
| 2438 | TypeDefinition |
| 2439 | : "typedef" NewLineNot TypedIdentifierDefinition[typed] TerminatorHard { CYIdentifier *identifier; if ($typed->name_ == NULL) identifier = NULL; else { identifier = $typed->name_->Identifier(); if (identifier == NULL) CYERR($typed->location_, "invalid identifier"); } $$ = CYNew CYTypeDefinition($typed, identifier); } |
| 2440 | ; |
| 2441 | |
| 2442 | Statement__ |
| 2443 | : TypeDefinition[pass] { $$ = $pass; } |
| 2444 | ; |
| 2445 | |
| 2446 | PrimaryExpression |
| 2447 | : "(" LexOf "typedef" NewLineOpt TypedIdentifierEncoding[typed] ")" { $$ = CYNew CYTypeExpression($typed); } |
| 2448 | ; |
| 2449 | /* }}} */ |
| 2450 | /* Cycript (C): extern "C" {{{ */ |
| 2451 | IdentifierNoOf |
| 2452 | : "extern" NewLineOpt { $$ = CYNew CYIdentifier("extern"); } |
| 2453 | ; |
| 2454 | |
| 2455 | ExternCStatement |
| 2456 | : TypedIdentifierField[typed] TerminatorHard { CYIdentifier *identifier; if ($typed->name_ == NULL) identifier = NULL; else { identifier = $typed->name_->Identifier(); if (identifier == NULL) CYERR($typed->location_, "invalid identifier"); } $$ = CYNew CYExternalDefinition(CYNew CYString("C"), $typed, identifier); } |
| 2457 | | TypeDefinition[pass] { $$ = $pass; } |
| 2458 | ; |
| 2459 | |
| 2460 | ExternCStatementListOpt |
| 2461 | : ExternCStatement[statement] ExternCStatementListOpt[next] { $$ = $statement; CYSetLast($$) = $next; } |
| 2462 | | { $$ = NULL; } |
| 2463 | ; |
| 2464 | |
| 2465 | ExternC |
| 2466 | : "{" ExternCStatementListOpt[pass] "}" { $$ = $pass; } |
| 2467 | | ExternCStatement[pass] { $$ = $pass; } |
| 2468 | ; |
| 2469 | |
| 2470 | ABI |
| 2471 | : StringLiteral[abi] { if (strcmp($abi->Value(), "C") != 0) CYERR(@abi, "unknown extern binding"); } |
| 2472 | ; |
| 2473 | |
| 2474 | Statement__ |
| 2475 | : "extern" NewLineNot ABI[abi] ExternC[pass] { $$ = $pass; } |
| 2476 | ; |
| 2477 | |
| 2478 | PrimaryExpression |
| 2479 | : "(" LexOf "extern" NewLineOpt ABI[abi] TypedIdentifierField[typed] ")" { $$ = CYNew CYExternalExpression(CYNew CYString("C"), $typed, $typed->name_); } |
| 2480 | ; |
| 2481 | /* }}} */ |
| 2482 | @end |
| 2483 | |
| 2484 | @begin E4X |
| 2485 | /* Lexer State {{{ */ |
| 2486 | LexPushRegExp |
| 2487 | : { driver.PushCondition(CYDriver::RegExpCondition); } |
| 2488 | ; |
| 2489 | |
| 2490 | LexPushXMLContent |
| 2491 | : { driver.PushCondition(CYDriver::XMLContentCondition); } |
| 2492 | ; |
| 2493 | |
| 2494 | LexPushXMLTag |
| 2495 | : { driver.PushCondition(CYDriver::XMLTagCondition); } |
| 2496 | ; |
| 2497 | |
| 2498 | LexPop |
| 2499 | : { driver.PopCondition(); } |
| 2500 | ; |
| 2501 | |
| 2502 | LexSetXMLContent |
| 2503 | : { driver.SetCondition(CYDriver::XMLContentCondition); } |
| 2504 | ; |
| 2505 | |
| 2506 | LexSetXMLTag |
| 2507 | : { driver.SetCondition(CYDriver::XMLTagCondition); } |
| 2508 | ; |
| 2509 | /* }}} */ |
| 2510 | /* Virtual Tokens {{{ */ |
| 2511 | XMLWhitespaceOpt |
| 2512 | : XMLWhitespace |
| 2513 | | |
| 2514 | ; |
| 2515 | /* }}} */ |
| 2516 | |
| 2517 | /* 8.1 Context Keywords {{{ */ |
| 2518 | Identifier |
| 2519 | : "namespace" { $$ = CYNew CYIdentifier("namespace"); } |
| 2520 | | "xml" { $$ = CYNew CYIdentifier("xml"); } |
| 2521 | ; |
| 2522 | /* }}} */ |
| 2523 | /* 8.3 XML Initializer Input Elements {{{ */ |
| 2524 | XMLMarkup |
| 2525 | : XMLComment { $$ = $1; } |
| 2526 | | XMLCDATA { $$ = $1; } |
| 2527 | | XMLPI { $$ = $1; } |
| 2528 | ; |
| 2529 | /* }}} */ |
| 2530 | |
| 2531 | /* 11.1 Primary Expressions {{{ */ |
| 2532 | PrimaryExpression |
| 2533 | : PropertyIdentifier { $$ = CYNew CYPropertyVariable($1); } |
| 2534 | | XMLInitilizer { $$ = $1; } |
| 2535 | | XMLListInitilizer { $$ = $1; } |
| 2536 | ; |
| 2537 | |
| 2538 | PropertyIdentifier |
| 2539 | : AttributeIdentifier { $$ = $1; } |
| 2540 | | QualifiedIdentifier { $$ = $1; } |
| 2541 | | WildcardIdentifier { $$ = $1; } |
| 2542 | ; |
| 2543 | /* }}} */ |
| 2544 | /* 11.1.1 Attribute Identifiers {{{ */ |
| 2545 | AttributeIdentifier |
| 2546 | : "@" QualifiedIdentifier_ { $$ = CYNew CYAttribute($2); } |
| 2547 | ; |
| 2548 | |
| 2549 | PropertySelector_ |
| 2550 | : PropertySelector { $$ = $1; } |
| 2551 | | "[" Expression "]" { $$ = CYNew CYSelector($2); } |
| 2552 | ; |
| 2553 | |
| 2554 | PropertySelector |
| 2555 | : Identifier { $$ = CYNew CYSelector($1); } |
| 2556 | | WildcardIdentifier { $$ = $1; } |
| 2557 | ; |
| 2558 | /* }}} */ |
| 2559 | /* 11.1.2 Qualified Identifiers {{{ */ |
| 2560 | QualifiedIdentifier_ |
| 2561 | : PropertySelector_ { $$ = CYNew CYQualified(NULL, $1); } |
| 2562 | | QualifiedIdentifier { $$ = $1; } |
| 2563 | ; |
| 2564 | |
| 2565 | QualifiedIdentifier |
| 2566 | : PropertySelector "::" PropertySelector_ { $$ = CYNew CYQualified($1, $3); } |
| 2567 | ; |
| 2568 | /* }}} */ |
| 2569 | /* 11.1.3 Wildcard Identifiers {{{ */ |
| 2570 | WildcardIdentifier |
| 2571 | : "*" { $$ = CYNew CYWildcard(); } |
| 2572 | ; |
| 2573 | /* }}} */ |
| 2574 | /* 11.1.4 XML Initializer {{{ */ |
| 2575 | XMLInitilizer |
| 2576 | : XMLMarkup { $$ = $1; } |
| 2577 | | XMLElement { $$ = $1; } |
| 2578 | ; |
| 2579 | |
| 2580 | XMLElement |
| 2581 | : "<" LexPushInOff XMLTagContent LexPop "/>" LexPopIn |
| 2582 | | "<" LexPushInOff XMLTagContent ">" LexSetXMLContent XMLElementContentOpt "</" LexSetXMLTag XMLTagName XMLWhitespaceOpt LexPop ">" LexPopIn |
| 2583 | ; |
| 2584 | |
| 2585 | XMLTagContent |
| 2586 | : LexPushXMLTag XMLTagName XMLAttributes |
| 2587 | ; |
| 2588 | |
| 2589 | XMLExpression |
| 2590 | : "{" LexPushRegExp Expression LexPop "}" |
| 2591 | ; |
| 2592 | |
| 2593 | XMLTagName |
| 2594 | : XMLExpression |
| 2595 | | XMLName |
| 2596 | ; |
| 2597 | |
| 2598 | XMLAttributes_ |
| 2599 | : XMLAttributes_ XMLAttribute |
| 2600 | | |
| 2601 | ; |
| 2602 | |
| 2603 | XMLAttributes |
| 2604 | : XMLAttributes_ XMLWhitespace XMLExpression XMLWhitespaceOpt |
| 2605 | | XMLAttributes_ XMLWhitespaceOpt |
| 2606 | ; |
| 2607 | |
| 2608 | XMLAttributeValue_ |
| 2609 | : XMLExpression |
| 2610 | | XMLAttributeValue |
| 2611 | ; |
| 2612 | |
| 2613 | XMLAttribute |
| 2614 | : XMLWhitespace XMLName XMLWhitespaceOpt "=" XMLWhitespaceOpt XMLAttributeValue_ |
| 2615 | ; |
| 2616 | |
| 2617 | XMLElementContent |
| 2618 | : XMLExpression XMLElementContentOpt |
| 2619 | | XMLMarkup XMLElementContentOpt |
| 2620 | | XMLText XMLElementContentOpt |
| 2621 | | XMLElement XMLElementContentOpt |
| 2622 | ; |
| 2623 | |
| 2624 | XMLElementContentOpt |
| 2625 | : XMLElementContent |
| 2626 | | |
| 2627 | ; |
| 2628 | /* }}} */ |
| 2629 | /* 11.1.5 XMLList Initializer {{{ */ |
| 2630 | XMLListInitilizer |
| 2631 | : "<>" LexPushInOff LexPushXMLContent XMLElementContent LexPop "</>" LexPopIn { $$ = CYNew CYXMLList($4); } |
| 2632 | ; |
| 2633 | /* }}} */ |
| 2634 | |
| 2635 | /* 11.2 Left-Hand-Side Expressions {{{ */ |
| 2636 | PropertyIdentifier_ |
| 2637 | : Identifier { $$ = $1; } |
| 2638 | | PropertyIdentifier { $$ = $1; } |
| 2639 | ; |
| 2640 | |
| 2641 | MemberAccess |
| 2642 | : "." PropertyIdentifier { $$ = CYNew CYPropertyMember(NULL, $2); } |
| 2643 | | ".." PropertyIdentifier_ { $$ = CYNew CYDescendantMember(NULL, $2); } |
| 2644 | | "." "(" Expression ")" { $$ = CYNew CYFilteringPredicate(NULL, $3); } |
| 2645 | ; |
| 2646 | /* }}} */ |
| 2647 | /* 12.1 The default xml namespace Statement {{{ */ |
| 2648 | /* XXX: DefaultXMLNamespaceStatement |
| 2649 | : "default" "xml" "namespace" "=" Expression Terminator { $$ = CYNew CYDefaultXMLNamespace($5); } |
| 2650 | ; |
| 2651 | |
| 2652 | Statement__ |
| 2653 | : DefaultXMLNamespaceStatement { $$ = $1; } |
| 2654 | ; */ |
| 2655 | /* }}} */ |
| 2656 | @end |
| 2657 | |
| 2658 | /* JavaScript FTL: Array Comprehensions {{{ */ |
| 2659 | Comprehension |
| 2660 | : AssignmentExpression[expression] ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); } |
| 2661 | ; |
| 2662 | |
| 2663 | ComprehensionFor |
| 2664 | : "for" "each" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); } |
| 2665 | ; |
| 2666 | /* }}} */ |
| 2667 | /* JavaScript FTL: for each {{{ */ |
| 2668 | IterationStatement |
| 2669 | : "for" "each" "(" LexPushInOn ForInStatementInitializer[initializer] "!in" LexPopIn Expression[iterable] ")" Statement[code] { $$ = CYNew CYForOf($initializer, $iterable, $code); } |
| 2670 | ; |
| 2671 | /* }}} */ |
| 2672 | |
| 2673 | /* JavaScript FTW: Array Comprehensions {{{ */ |
| 2674 | PrimaryExpression |
| 2675 | : ArrayComprehension |
| 2676 | ; |
| 2677 | |
| 2678 | ArrayComprehension |
| 2679 | : "[" Comprehension[comprehension] "]" { $$ = $comprehension; } |
| 2680 | ; |
| 2681 | |
| 2682 | Comprehension |
| 2683 | : LexOf ComprehensionFor[comprehension] ComprehensionTail[next] AssignmentExpression[expression] { $comprehension->SetNext($next); $$ = CYNew CYArrayComprehension($expression, $comprehension); } |
| 2684 | ; |
| 2685 | |
| 2686 | ComprehensionTail |
| 2687 | : { $$ = NULL; } |
| 2688 | | ComprehensionFor[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; } |
| 2689 | | ComprehensionIf[comprehension] ComprehensionTail[next] { $comprehension->SetNext($next); $$ = $comprehension; } |
| 2690 | ; |
| 2691 | |
| 2692 | ComprehensionFor |
| 2693 | : "for" "(" LexPushInOn LexBind ForBinding[binding] "!in" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForInComprehension($binding, $iterable); } |
| 2694 | | "for" "(" LexPushInOn LexBind ForBinding[binding] "of" LexPopIn Expression[iterable] ")" { $$ = CYNew CYForOfComprehension($binding, $iterable); } |
| 2695 | ; |
| 2696 | |
| 2697 | ComprehensionIf |
| 2698 | : "if" "(" AssignmentExpression[test] ")" { $$ = CYNew CYIfComprehension($test); } |
| 2699 | ; |
| 2700 | /* }}} */ |
| 2701 | /* JavaScript FTW: Named Arguments {{{ */ |
| 2702 | ArgumentList |
| 2703 | : LexOf WordNoUnary[tag] ":" AssignmentExpression[value] ArgumentList_[next] { $$ = CYNew CYArgument($tag, $value, $next); } |
| 2704 | ; |
| 2705 | /* }}} */ |
| 2706 | /* JavaScript FTW: Subscript Access {{{ */ |
| 2707 | MemberAccess |
| 2708 | : "." "[" AssignmentExpression[property] "]" { $$ = CYNew CYSubscriptMember(NULL, $property); } |
| 2709 | ; |
| 2710 | /* }}} */ |
| 2711 | /* JavaScript FTW: Undefined Monad {{{ */ |
| 2712 | MemberAccess |
| 2713 | : "?." IdentifierName[property] { $$ = CYNew CYAttemptMember(NULL, CYNew CYString($property)); } |
| 2714 | | "?." AutoComplete { driver.mode_ = CYDriver::AutoDirect; YYACCEPT; } |
| 2715 | ; |
| 2716 | /* }}} */ |
| 2717 | |
| 2718 | /* JavaScript FTW: Java "Anonymous Inner Classes" {{{ */ |
| 2719 | BracedParameter |
| 2720 | : "{" PropertyDefinitionListOpt[properties] "}" { $$ = CYNew CYExtend(NULL, $properties); } |
| 2721 | ; |
| 2722 | /* }}} */ |
| 2723 | |
| 2724 | /* JavaScript FTW: Ruby Blocks {{{ */ |
| 2725 | RubyProcParameterList_ |
| 2726 | : "," RubyProcParameterList[parameters] { $$ = $parameters; } |
| 2727 | | { $$ = NULL; } |
| 2728 | ; |
| 2729 | |
| 2730 | RubyProcParameterList |
| 2731 | : BindingIdentifier[identifier] RubyProcParameterList_[next] { $$ = CYNew CYFunctionParameter(CYNew CYBinding($identifier), $next); } |
| 2732 | | LexOf { $$ = NULL; } |
| 2733 | ; |
| 2734 | |
| 2735 | RubyProcParameters |
| 2736 | : "|" RubyProcParameterList[parameters] "|" { $$ = $parameters; } |
| 2737 | | "||" { $$ = NULL; } |
| 2738 | ; |
| 2739 | |
| 2740 | RubyProcParametersOpt |
| 2741 | : RubyProcParameters[pass] { $$ = $pass; } |
| 2742 | | { $$ = NULL; } |
| 2743 | ; |
| 2744 | |
| 2745 | BracedParameter |
| 2746 | : ";{" RubyProcParametersOpt[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyBlock(NULL, CYNew CYRubyProc($parameters, $code)); } |
| 2747 | ; |
| 2748 | |
| 2749 | PrimaryExpression |
| 2750 | : "{" RubyProcParameters[parameters] StatementListOpt[code] "}" { $$ = CYNew CYRubyProc($parameters, $code); } |
| 2751 | ; |
| 2752 | |
| 2753 | BracedExpression_ |
| 2754 | : AccessExpression[pass] LexNewLineOrOpt { $$ = $pass; } |
| 2755 | | BracedExpression_[lhs] { if (!$lhs->IsNew()) CYMAP(OpenBrace_, OpenBrace); } BracedParameter[rhs] LexNewLineOrOpt { $rhs->SetLeft($lhs); $$ = $rhs; } |
| 2756 | ; |
| 2757 | |
| 2758 | BracedExpression |
| 2759 | : BracedExpression_[pass] "\n" { $$ = $pass; } |
| 2760 | | BracedExpression_[pass] { $$ = $pass; } |
| 2761 | ; |
| 2762 | /* }}} */ |
| 2763 | /* JavaScript FTW: Ruby Scopes {{{ */ |
| 2764 | MemberAccess |
| 2765 | : "::" "[" Expression[property] "]" { $$ = CYNew CYResolveMember(NULL, $property); } |
| 2766 | | "::" IdentifierName[property] { $$ = CYNew CYResolveMember(NULL, CYNew CYString($property)); } |
| 2767 | | "::" AutoComplete { driver.mode_ = CYDriver::AutoResolve; YYACCEPT; } |
| 2768 | ; |
| 2769 | /* }}} */ |
| 2770 | /* JavaScript FTW: Ruby Symbols {{{ */ |
| 2771 | PrimaryExpression |
| 2772 | : ":" Word[name] { $$ = CYNew CYSymbol($name->Word()); } |
| 2773 | ; |
| 2774 | /* }}} */ |
| 2775 | |
| 2776 | %% |
| 2777 | |
| 2778 | bool CYDriver::Parse(CYMark mark) { |
| 2779 | mark_ = mark; |
| 2780 | CYLocal<CYPool> local(&pool_); |
| 2781 | cy::parser parser(*this); |
| 2782 | #ifdef YYDEBUG |
| 2783 | parser.set_debug_level(debug_); |
| 2784 | #endif |
| 2785 | return parser.parse() != 0; |
| 2786 | } |
| 2787 | |
| 2788 | void CYDriver::Warning(const cy::parser::location_type &location, const char *message) { |
| 2789 | if (!strict_) |
| 2790 | return; |
| 2791 | |
| 2792 | CYDriver::Error error; |
| 2793 | error.warning_ = true; |
| 2794 | error.location_ = location; |
| 2795 | error.message_ = message; |
| 2796 | errors_.push_back(error); |
| 2797 | } |
| 2798 | |
| 2799 | void cy::parser::error(const cy::parser::location_type &location, const std::string &message) { |
| 2800 | CYDriver::Error error; |
| 2801 | error.warning_ = false; |
| 2802 | error.location_ = location; |
| 2803 | error.message_ = message; |
| 2804 | driver.errors_.push_back(error); |
| 2805 | } |