Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: dart/lib/compiler/implementation/scanner/parser.dart

Issue 10831332: Support new getter syntax. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * An event generating parser of Dart programs. This parser expects 6 * An event generating parser of Dart programs. This parser expects
7 * all tokens in a linked list (aka a token stream). 7 * all tokens in a linked list (aka a token stream).
8 * 8 *
9 * The class [Scanner] is used to generate a token stream. See the 9 * The class [Scanner] is used to generate a token stream. See the
10 * file scanner.dart. 10 * file scanner.dart.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 Token parseReturnTypeOpt(Token token) { 77 Token parseReturnTypeOpt(Token token) {
78 if (token.stringValue === 'void') { 78 if (token.stringValue === 'void') {
79 listener.handleVoidKeyword(token); 79 listener.handleVoidKeyword(token);
80 return token.next; 80 return token.next;
81 } else { 81 } else {
82 return parseTypeOpt(token); 82 return parseTypeOpt(token);
83 } 83 }
84 } 84 }
85 85
86 Token parseFormalParametersOpt(Token token) {
87 if (optional('(', token)) {
88 return parseFormalParameters(token);
89 } else {
90 listener.handleNoFormalParameters(token);
91 return token;
92 }
93 }
94
86 Token parseFormalParameters(Token token) { 95 Token parseFormalParameters(Token token) {
87 Token begin = token; 96 Token begin = token;
88 listener.beginFormalParameters(begin); 97 listener.beginFormalParameters(begin);
89 expect('(', token); 98 expect('(', token);
90 int parameterCount = 0; 99 int parameterCount = 0;
91 if (optional(')', token.next)) { 100 if (optional(')', token.next)) {
92 listener.endFormalParameters(parameterCount, begin, token.next); 101 listener.endFormalParameters(parameterCount, begin, token.next);
93 return token.next.next; 102 return token.next.next;
94 } 103 }
95 do { 104 do {
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 // Skip type. 365 // Skip type.
357 token = peek; 366 token = peek;
358 } 367 }
359 if (token === getOrSet) token = token.next; 368 if (token === getOrSet) token = token.next;
360 token = parseIdentifier(token); 369 token = parseIdentifier(token);
361 bool isField; 370 bool isField;
362 while (true) { 371 while (true) {
363 // Loop to allow the listener to rewrite the token stream for 372 // Loop to allow the listener to rewrite the token stream for
364 // error handling. 373 // error handling.
365 final String value = token.stringValue; 374 final String value = token.stringValue;
366 if (value === '(') { 375 if (value === '(' || value === '{' || value === '=>') {
367 isField = false; 376 isField = false;
368 break; 377 break;
369 } else if ((value === '=') || (value === ';') || (value === ',')) { 378 } else if ((value === '=') || (value === ';') || (value === ',')) {
370 isField = true; 379 isField = true;
371 break; 380 break;
372 } else { 381 } else {
373 token = listener.unexpected(token); 382 token = listener.unexpected(token);
374 if (token.kind === EOF_TOKEN) { 383 if (token.kind === EOF_TOKEN) {
375 // TODO(ahe): This is a hack. It would be better to tell the 384 // TODO(ahe): This is a hack. It would be better to tell the
376 // listener more explicitly that it must pop an identifier. 385 // listener more explicitly that it must pop an identifier.
377 listener.endTopLevelFields(1, start, token); 386 listener.endTopLevelFields(1, start, token);
378 return token; 387 return token;
379 } 388 }
380 } 389 }
381 } 390 }
382 if (isField) { 391 if (isField) {
383 int fieldCount = 1; 392 int fieldCount = 1;
384 token = parseVariableInitializerOpt(token); 393 token = parseVariableInitializerOpt(token);
385 while (optional(',', token)) { 394 while (optional(',', token)) {
386 token = parseIdentifier(token.next); 395 token = parseIdentifier(token.next);
387 token = parseVariableInitializerOpt(token); 396 token = parseVariableInitializerOpt(token);
388 ++fieldCount; 397 ++fieldCount;
389 } 398 }
390 expectSemicolon(token); 399 expectSemicolon(token);
391 listener.endTopLevelFields(fieldCount, start, token); 400 listener.endTopLevelFields(fieldCount, start, token);
392 } else { 401 } else {
393 token = parseFormalParameters(token); 402 token = parseFormalParametersOpt(token);
394 token = parseFunctionBody(token, false); 403 token = parseFunctionBody(token, false);
395 listener.endTopLevelMethod(start, getOrSet, token); 404 listener.endTopLevelMethod(start, getOrSet, token);
396 } 405 }
397 return token.next; 406 return token.next;
398 } 407 }
399 408
400 Token parseVariableInitializerOpt(Token token) { 409 Token parseVariableInitializerOpt(Token token) {
401 if (optional('=', token)) { 410 if (optional('=', token)) {
402 Token assignment = token; 411 Token assignment = token;
403 listener.beginInitializer(token); 412 listener.beginInitializer(token);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 if (optional('operator', token)) { 605 if (optional('operator', token)) {
597 token = parseOperatorName(token); 606 token = parseOperatorName(token);
598 } else { 607 } else {
599 token = parseIdentifier(token); 608 token = parseIdentifier(token);
600 } 609 }
601 bool isField; 610 bool isField;
602 while (true) { 611 while (true) {
603 // Loop to allow the listener to rewrite the token stream for 612 // Loop to allow the listener to rewrite the token stream for
604 // error handling. 613 // error handling.
605 final String value = token.stringValue; 614 final String value = token.stringValue;
606 if ((value === '(') || (value === '.')) { 615 if ((value === '(') || (value === '.') || (value === '{') ||
kasperl 2012/08/20 12:55:31 So here all the === comparisons are wrapped in ()
ahe 2012/08/20 13:26:17 Done.
616 (value === '=>')) {
607 isField = false; 617 isField = false;
608 break; 618 break;
609 } else if ((value === '=') || (value === ';') || (value === ',')) { 619 } else if ((value === '=') || (value === ';') || (value === ',')) {
610 isField = true; 620 isField = true;
611 break; 621 break;
612 } else { 622 } else {
613 token = listener.unexpected(token); 623 token = listener.unexpected(token);
614 if (token.kind === EOF_TOKEN) { 624 if (token.kind === EOF_TOKEN) {
615 // TODO(ahe): This is a hack, see parseTopLevelMember. 625 // TODO(ahe): This is a hack, see parseTopLevelMember.
616 listener.endFields(1, start, token); 626 listener.endFields(1, start, token);
(...skipping 10 matching lines...) Expand all
627 while (optional(',', token)) { 637 while (optional(',', token)) {
628 // TODO(ahe): Count these. 638 // TODO(ahe): Count these.
629 token = parseIdentifier(token.next); 639 token = parseIdentifier(token.next);
630 token = parseVariableInitializerOpt(token); 640 token = parseVariableInitializerOpt(token);
631 ++fieldCount; 641 ++fieldCount;
632 } 642 }
633 expectSemicolon(token); 643 expectSemicolon(token);
634 listener.endFields(fieldCount, start, token); 644 listener.endFields(fieldCount, start, token);
635 } else { 645 } else {
636 token = parseQualifiedRestOpt(token); 646 token = parseQualifiedRestOpt(token);
637 token = parseFormalParameters(token); 647 token = parseFormalParametersOpt(token);
638 token = parseInitializersOpt(token); 648 token = parseInitializersOpt(token);
639 token = parseFunctionBody(token, false); 649 token = parseFunctionBody(token, false);
640 listener.endMethod(getOrSet, start, token); 650 listener.endMethod(getOrSet, start, token);
641 } 651 }
642 return token.next; 652 return token.next;
643 } 653 }
644 654
645 Token parseFactoryMethod(Token token) { 655 Token parseFactoryMethod(Token token) {
646 assert((optional('external', token) && optional('factory', token.next)) || 656 assert((optional('external', token) && optional('factory', token.next)) ||
647 optional('factory', token)); 657 optional('factory', token));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 if (getOrSet === token) token = token.next; 699 if (getOrSet === token) token = token.next;
690 listener.beginFunctionName(token); 700 listener.beginFunctionName(token);
691 if (optional('operator', token)) { 701 if (optional('operator', token)) {
692 token = parseOperatorName(token); 702 token = parseOperatorName(token);
693 } else { 703 } else {
694 token = parseIdentifier(token); 704 token = parseIdentifier(token);
695 } 705 }
696 } 706 }
697 token = parseQualifiedRestOpt(token); 707 token = parseQualifiedRestOpt(token);
698 listener.endFunctionName(token); 708 listener.endFunctionName(token);
699 token = parseFormalParameters(token); 709 token = parseFormalParametersOpt(token);
700 token = parseInitializersOpt(token); 710 token = parseInitializersOpt(token);
701 token = parseFunctionBody(token, false); 711 token = parseFunctionBody(token, false);
702 listener.endFunction(getOrSet, token); 712 listener.endFunction(getOrSet, token);
703 return token.next; 713 return token.next;
704 } 714 }
705 715
706 Token parseUnamedFunction(Token token) { 716 Token parseUnamedFunction(Token token) {
707 listener.beginUnamedFunction(token); 717 listener.beginUnamedFunction(token);
708 token = parseFormalParameters(token); 718 token = parseFormalParameters(token);
709 bool isBlock = optional('{', token); 719 bool isBlock = optional('{', token);
(...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after
1779 } 1789 }
1780 listener.handleContinueStatement(hasTarget, continueKeyword, token); 1790 listener.handleContinueStatement(hasTarget, continueKeyword, token);
1781 return expectSemicolon(token); 1791 return expectSemicolon(token);
1782 } 1792 }
1783 1793
1784 Token parseEmptyStatement(Token token) { 1794 Token parseEmptyStatement(Token token) {
1785 listener.handleEmptyStatement(token); 1795 listener.handleEmptyStatement(token);
1786 return expectSemicolon(token); 1796 return expectSemicolon(token);
1787 } 1797 }
1788 } 1798 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698