| 337 | } |
| 338 | |
| 339 | cASTNode* cParser::parseCallExpression(cASTNode* target, bool required) |
| 340 | { |
| 341 | PARSE_TRACE("parseCallExpression"); |
| 342 | Apto::SmartPtr<cASTNode> ce(target); |
| 343 | |
| 344 | if (currentToken() == TOKEN(DOT) && peekToken() == TOKEN(BUILTIN_METHOD)) { |
| 345 | nextToken(); // consume '.' |
| 346 | |
| 347 | cASTBuiltInCall* bi = new cASTBuiltInCall(FILEPOS, currentText(), ce.Release()); |
| 348 | ce.Set(bi); |
| 349 | |
| 350 | if (nextToken() != TOKEN(PREC_OPEN)) PARSE_UNEXPECT(); |
| 351 | if (nextToken() != TOKEN(PREC_CLOSE)) bi->SetArguments(parseArgumentList()); |
| 352 | if (currentToken() != TOKEN(PREC_CLOSE)) PARSE_UNEXPECT(); |
| 353 | nextToken(); // consume ')' |
| 354 | |
| 355 | if (currentToken() != TOKEN(DOT) || currentToken() != TOKEN(IDX_OPEN)) return ce.Release(); |
| 356 | } |
| 357 | |
| 358 | |
| 359 | bool eoe = false; |
| 360 | while (!eoe) { |
| 361 | if (currentToken() == TOKEN(DOT)) { |
| 362 | if (nextToken() != TOKEN(ID)) PARSE_UNEXPECT(); |
| 363 | cString name(currentText()); |
| 364 | nextToken(); // consume id |
| 365 | |
| 366 | if (currentToken() == TOKEN(PREC_OPEN)) { |
| 367 | cASTObjectCall* oc = new cASTObjectCall(FILEPOS, ce.Release(), name); |
| 368 | ce.Set(oc); |
| 369 | if (nextToken() != TOKEN(PREC_CLOSE)) oc->SetArguments(parseArgumentList()); |
| 370 | if (currentToken() != TOKEN(PREC_CLOSE)) PARSE_UNEXPECT(); |
| 371 | nextToken(); // consume ')' |
| 372 | |
| 373 | // If the next token is not a continued call expression, then set the end-of-expression flag |
| 374 | if (currentToken() != TOKEN(IDX_OPEN) && currentToken() != TOKEN(DOT)) eoe = true; |
| 375 | } else { |
| 376 | ce.Set(new cASTObjectReference(FILEPOS, ce.Release(), name)); |
| 377 | |
| 378 | if (required && currentToken() == TOKEN(ASSIGN)) { |
| 379 | cASTObjectAssignment* oa = new cASTObjectAssignment(FILEPOS, ce.Release()); |
| 380 | ce.Set(oa); |
| 381 | nextToken(); // consume '=' |
| 382 | oa->SetExpression(parseExpression()); |
| 383 | eoe = true; |
| 384 | } |
| 385 | } |
| 386 | } else if (currentToken() == TOKEN(IDX_OPEN)) { |
| 387 | do { |
| 388 | nextToken(); // consume '[' |
| 389 | ce.Set(new cASTExpressionBinary(FILEPOS, TOKEN(IDX_OPEN), ce.Release(), parseExpression())); |
| 390 | if (currentToken() != TOKEN(IDX_CLOSE)) PARSE_UNEXPECT(); |
| 391 | } while (nextToken() == TOKEN(IDX_OPEN)); |
| 392 | |
| 393 | if (required && currentToken() == TOKEN(ASSIGN)) { |
| 394 | cASTObjectAssignment* oa = new cASTObjectAssignment(FILEPOS, ce.Release()); |
| 395 | ce.Set(oa); |
| 396 | nextToken(); // consume '=' |
nothing calls this directly
no test coverage detected