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

Side by Side Diff: pkg/front_end/lib/src/scanner/scanner.dart

Issue 3010533002: flatten token hierarchy (Closed)
Patch Set: Created 3 years, 3 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
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'package:charcode/ascii.dart'; 5 import 'package:charcode/ascii.dart';
6 import 'package:front_end/src/scanner/errors.dart'; 6 import 'package:front_end/src/scanner/errors.dart';
7 import 'package:front_end/src/scanner/reader.dart'; 7 import 'package:front_end/src/scanner/reader.dart';
8 import 'package:front_end/src/scanner/string_utilities.dart'; 8 import 'package:front_end/src/scanner/string_utilities.dart';
9 import 'package:front_end/src/scanner/token.dart'; 9 import 'package:front_end/src/scanner/token.dart';
10 10
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 } 483 }
484 _appendEofToken(); 484 _appendEofToken();
485 return firstToken; 485 return firstToken;
486 } 486 }
487 487
488 void _appendBeginToken(TokenType type) { 488 void _appendBeginToken(TokenType type) {
489 BeginToken token; 489 BeginToken token;
490 if (_firstComment == null) { 490 if (_firstComment == null) {
491 token = new BeginToken(type, _tokenStart); 491 token = new BeginToken(type, _tokenStart);
492 } else { 492 } else {
493 token = new BeginTokenWithComment(type, _tokenStart, _firstComment); 493 token = new BeginToken(type, _tokenStart, _firstComment);
494 _firstComment = null; 494 _firstComment = null;
495 _lastComment = null; 495 _lastComment = null;
496 } 496 }
497 _tail = _tail.setNext(token); 497 _tail = _tail.setNext(token);
498 _groupingStack.add(token); 498 _groupingStack.add(token);
499 _stackEnd++; 499 _stackEnd++;
500 } 500 }
501 501
502 void _appendCommentToken(TokenType type, String value) { 502 void _appendCommentToken(TokenType type, String value) {
503 CommentToken token = null; 503 CommentToken token = null;
(...skipping 17 matching lines...) Expand all
521 } else { 521 } else {
522 _lastComment = _lastComment.setNext(token); 522 _lastComment = _lastComment.setNext(token);
523 } 523 }
524 } 524 }
525 525
526 void _appendEndToken(TokenType type, TokenType beginType) { 526 void _appendEndToken(TokenType type, TokenType beginType) {
527 Token token; 527 Token token;
528 if (_firstComment == null) { 528 if (_firstComment == null) {
529 token = new Token(type, _tokenStart); 529 token = new Token(type, _tokenStart);
530 } else { 530 } else {
531 token = new TokenWithComment(type, _tokenStart, _firstComment); 531 token = new Token(type, _tokenStart, _firstComment);
532 _firstComment = null; 532 _firstComment = null;
533 _lastComment = null; 533 _lastComment = null;
534 } 534 }
535 _tail = _tail.setNext(token); 535 _tail = _tail.setNext(token);
536 if (_stackEnd >= 0) { 536 if (_stackEnd >= 0) {
537 BeginToken begin = _groupingStack[_stackEnd]; 537 BeginToken begin = _groupingStack[_stackEnd];
538 if (begin.type == beginType) { 538 if (begin.type == beginType) {
539 begin.endToken = token; 539 begin.endToken = token;
540 _groupingStack.removeAt(_stackEnd--); 540 _groupingStack.removeAt(_stackEnd--);
541 } 541 }
(...skipping 16 matching lines...) Expand all
558 if (_stackEnd >= 0) { 558 if (_stackEnd >= 0) {
559 _hasUnmatchedGroups = true; 559 _hasUnmatchedGroups = true;
560 // TODO(brianwilkerson) Fix the ungrouped tokens? 560 // TODO(brianwilkerson) Fix the ungrouped tokens?
561 } 561 }
562 } 562 }
563 563
564 void _appendKeywordToken(Keyword keyword) { 564 void _appendKeywordToken(Keyword keyword) {
565 if (_firstComment == null) { 565 if (_firstComment == null) {
566 _tail = _tail.setNext(new KeywordToken(keyword, _tokenStart)); 566 _tail = _tail.setNext(new KeywordToken(keyword, _tokenStart));
567 } else { 567 } else {
568 _tail = _tail.setNext( 568 _tail =
569 new KeywordTokenWithComment(keyword, _tokenStart, _firstComment)); 569 _tail.setNext(new KeywordToken(keyword, _tokenStart, _firstComment));
570 _firstComment = null; 570 _firstComment = null;
571 _lastComment = null; 571 _lastComment = null;
572 } 572 }
573 } 573 }
574 574
575 void _appendStringToken(TokenType type, String value) { 575 void _appendStringToken(TokenType type, String value) {
576 if (_firstComment == null) { 576 if (_firstComment == null) {
577 _tail = _tail.setNext(new StringToken(type, value, _tokenStart)); 577 _tail = _tail.setNext(new StringToken(type, value, _tokenStart));
578 } else { 578 } else {
579 _tail = _tail.setNext( 579 _tail = _tail
580 new StringTokenWithComment(type, value, _tokenStart, _firstComment)); 580 .setNext(new StringToken(type, value, _tokenStart, _firstComment));
581 _firstComment = null; 581 _firstComment = null;
582 _lastComment = null; 582 _lastComment = null;
583 } 583 }
584 } 584 }
585 585
586 void _appendStringTokenWithOffset(TokenType type, String value, int offset) { 586 void _appendStringTokenWithOffset(TokenType type, String value, int offset) {
587 if (_firstComment == null) { 587 if (_firstComment == null) {
588 _tail = _tail.setNext(new StringToken(type, value, _tokenStart + offset)); 588 _tail = _tail.setNext(new StringToken(type, value, _tokenStart + offset));
589 } else { 589 } else {
590 _tail = _tail.setNext(new StringTokenWithComment( 590 _tail = _tail.setNext(
591 type, value, _tokenStart + offset, _firstComment)); 591 new StringToken(type, value, _tokenStart + offset, _firstComment));
592 _firstComment = null; 592 _firstComment = null;
593 _lastComment = null; 593 _lastComment = null;
594 } 594 }
595 } 595 }
596 596
597 void _appendTokenOfType(TokenType type) { 597 void _appendTokenOfType(TokenType type) {
598 if (_firstComment == null) { 598 if (_firstComment == null) {
599 _tail = _tail.setNext(new Token(type, _tokenStart)); 599 _tail = _tail.setNext(new Token(type, _tokenStart));
600 } else { 600 } else {
601 _tail = 601 _tail = _tail.setNext(new Token(type, _tokenStart, _firstComment));
602 _tail.setNext(new TokenWithComment(type, _tokenStart, _firstComment));
603 _firstComment = null; 602 _firstComment = null;
604 _lastComment = null; 603 _lastComment = null;
605 } 604 }
606 } 605 }
607 606
608 void _appendTokenOfTypeWithOffset(TokenType type, int offset) { 607 void _appendTokenOfTypeWithOffset(TokenType type, int offset) {
609 if (_firstComment == null) { 608 if (_firstComment == null) {
610 _tail = _tail.setNext(new Token(type, offset)); 609 _tail = _tail.setNext(new Token(type, offset));
611 } else { 610 } else {
612 _tail = _tail.setNext(new TokenWithComment(type, offset, _firstComment)); 611 _tail = _tail.setNext(new Token(type, offset, _firstComment));
613 _firstComment = null; 612 _firstComment = null;
614 _lastComment = null; 613 _lastComment = null;
615 } 614 }
616 } 615 }
617 616
618 void _beginToken() { 617 void _beginToken() {
619 _tokenStart = _reader.offset; 618 _tokenStart = _reader.offset;
620 } 619 }
621 620
622 /** 621 /**
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after
1335 } 1334 }
1336 1335
1337 /** 1336 /**
1338 * Checks if [value] is a single-line or multi-line comment. 1337 * Checks if [value] is a single-line or multi-line comment.
1339 */ 1338 */
1340 static bool _isDocumentationComment(String value) { 1339 static bool _isDocumentationComment(String value) {
1341 return StringUtilities.startsWith3(value, 0, $slash, $slash, $slash) || 1340 return StringUtilities.startsWith3(value, 0, $slash, $slash, $slash) ||
1342 StringUtilities.startsWith3(value, 0, $slash, $asterisk, $asterisk); 1341 StringUtilities.startsWith3(value, 0, $slash, $asterisk, $asterisk);
1343 } 1342 }
1344 } 1343 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/scanner/token.dart ('k') | pkg/front_end/lib/src/scanner/token.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698