OLD | NEW |
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 library fasta.scanner.abstract_scanner; | 5 library fasta.scanner.abstract_scanner; |
6 | 6 |
7 import 'dart:collection' show ListMixin; | 7 import 'dart:collection' show ListMixin; |
8 | 8 |
9 import 'dart:typed_data' show Uint16List, Uint32List; | 9 import 'dart:typed_data' show Uint16List, Uint32List; |
10 | 10 |
11 import '../scanner.dart' | 11 import '../scanner.dart' |
12 show ErrorToken, Scanner, buildUnexpectedCharacterToken; | 12 show ErrorToken, Scanner, buildUnexpectedCharacterToken; |
13 | 13 |
14 import 'error_token.dart' show UnmatchedToken, UnterminatedToken; | 14 import 'error_token.dart' show UnmatchedToken, UnterminatedToken; |
15 | 15 |
16 import 'keyword.dart' show KeywordState, Keyword; | 16 import 'keyword.dart' show KeywordState, Keyword; |
17 | 17 |
18 import 'precedence.dart'; | 18 import 'precedence.dart'; |
19 | 19 |
20 import 'token.dart' show BeginGroupToken, SymbolToken, Token; | 20 import 'token.dart' show BeginGroupToken, CommentToken, SymbolToken, Token; |
21 | 21 |
22 import 'token_constants.dart'; | 22 import 'token_constants.dart'; |
23 | 23 |
24 import 'characters.dart'; | 24 import 'characters.dart'; |
25 | 25 |
26 abstract class AbstractScanner implements Scanner { | 26 abstract class AbstractScanner implements Scanner { |
27 final bool includeComments; | 27 final bool includeComments; |
28 | 28 |
29 /** | 29 /** |
30 * The string offset for the next token that will be created. | 30 * The string offset for the next token that will be created. |
(...skipping 16 matching lines...) Expand all Loading... |
47 /** | 47 /** |
48 * A pointer to the last scanned token. | 48 * A pointer to the last scanned token. |
49 */ | 49 */ |
50 Token tail; | 50 Token tail; |
51 | 51 |
52 /** | 52 /** |
53 * A pointer to the stream of comment tokens created by this scanner | 53 * A pointer to the stream of comment tokens created by this scanner |
54 * before they are assigned to the [Token] precedingComments field | 54 * before they are assigned to the [Token] precedingComments field |
55 * of a non-comment token. A value of `null` indicates no comment tokens. | 55 * of a non-comment token. A value of `null` indicates no comment tokens. |
56 */ | 56 */ |
57 Token comments; | 57 CommentToken comments; |
58 | 58 |
59 /** | 59 /** |
60 * A pointer to the last scanned comment token or `null` if none. | 60 * A pointer to the last scanned comment token or `null` if none. |
61 */ | 61 */ |
62 Token commentsTail; | 62 Token commentsTail; |
63 | 63 |
64 final List<int> lineStarts; | 64 final List<int> lineStarts; |
65 | 65 |
66 AbstractScanner(this.includeComments, {int numberOfBytesHint}) | 66 AbstractScanner(this.includeComments, {int numberOfBytesHint}) |
67 : lineStarts = new LineStarts(numberOfBytesHint) { | 67 : lineStarts = new LineStarts(numberOfBytesHint) { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 181 |
182 /** Documentation in subclass [ArrayBasedScanner]. */ | 182 /** Documentation in subclass [ArrayBasedScanner]. */ |
183 void appendGt(PrecedenceInfo info); | 183 void appendGt(PrecedenceInfo info); |
184 | 184 |
185 /** Documentation in subclass [ArrayBasedScanner]. */ | 185 /** Documentation in subclass [ArrayBasedScanner]. */ |
186 void appendGtGt(PrecedenceInfo info); | 186 void appendGtGt(PrecedenceInfo info); |
187 | 187 |
188 /** Documentation in subclass [ArrayBasedScanner]. */ | 188 /** Documentation in subclass [ArrayBasedScanner]. */ |
189 void appendComment(start, PrecedenceInfo info, bool asciiOnly); | 189 void appendComment(start, PrecedenceInfo info, bool asciiOnly); |
190 | 190 |
| 191 /** Documentation in subclass [ArrayBasedScanner]. */ |
| 192 void appendDartDoc(start, PrecedenceInfo info, bool asciiOnly); |
| 193 |
191 /// Append [token] to the token stream. | 194 /// Append [token] to the token stream. |
192 void appendErrorToken(ErrorToken token); | 195 void appendErrorToken(ErrorToken token); |
193 | 196 |
194 /** Documentation in subclass [ArrayBasedScanner]. */ | 197 /** Documentation in subclass [ArrayBasedScanner]. */ |
195 void discardOpenLt(); | 198 void discardOpenLt(); |
196 | 199 |
197 /// Return true when at EOF. | 200 /// Return true when at EOF. |
198 bool atEndOfFile(); | 201 bool atEndOfFile(); |
199 | 202 |
200 Token tokenize() { | 203 Token tokenize() { |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 appendPrecedenceToken(SLASH_EQ_INFO); | 718 appendPrecedenceToken(SLASH_EQ_INFO); |
716 return advance(); | 719 return advance(); |
717 } else { | 720 } else { |
718 appendPrecedenceToken(SLASH_INFO); | 721 appendPrecedenceToken(SLASH_INFO); |
719 return next; | 722 return next; |
720 } | 723 } |
721 } | 724 } |
722 | 725 |
723 int tokenizeSingleLineComment(int next, int start) { | 726 int tokenizeSingleLineComment(int next, int start) { |
724 bool asciiOnly = true; | 727 bool asciiOnly = true; |
| 728 bool dartdoc = identical($SLASH, peek()); |
725 while (true) { | 729 while (true) { |
726 next = advance(); | 730 next = advance(); |
727 if (next > 127) asciiOnly = false; | 731 if (next > 127) asciiOnly = false; |
728 if (identical($LF, next) || | 732 if (identical($LF, next) || |
729 identical($CR, next) || | 733 identical($CR, next) || |
730 identical($EOF, next)) { | 734 identical($EOF, next)) { |
731 if (!asciiOnly) handleUnicode(start); | 735 if (!asciiOnly) handleUnicode(start); |
732 appendComment(start, SINGLE_LINE_COMMENT_INFO, asciiOnly); | 736 if (dartdoc) { |
| 737 appendDartDoc(start, SINGLE_LINE_COMMENT_INFO, asciiOnly); |
| 738 } else { |
| 739 appendComment(start, SINGLE_LINE_COMMENT_INFO, asciiOnly); |
| 740 } |
733 return next; | 741 return next; |
734 } | 742 } |
735 } | 743 } |
736 } | 744 } |
737 | 745 |
738 int tokenizeMultiLineComment(int next, int start) { | 746 int tokenizeMultiLineComment(int next, int start) { |
739 bool asciiOnlyComment = true; // Track if the entire comment is ASCII. | 747 bool asciiOnlyComment = true; // Track if the entire comment is ASCII. |
740 bool asciiOnlyLines = true; // Track ASCII since the last handleUnicode. | 748 bool asciiOnlyLines = true; // Track ASCII since the last handleUnicode. |
741 int unicodeStart = start; | 749 int unicodeStart = start; |
742 int nesting = 1; | 750 int nesting = 1; |
743 next = advance(); | 751 next = advance(); |
| 752 bool dartdoc = identical($STAR, next); |
744 while (true) { | 753 while (true) { |
745 if (identical($EOF, next)) { | 754 if (identical($EOF, next)) { |
746 if (!asciiOnlyLines) handleUnicode(unicodeStart); | 755 if (!asciiOnlyLines) handleUnicode(unicodeStart); |
747 unterminated('/*'); | 756 unterminated('/*'); |
748 break; | 757 break; |
749 } else if (identical($STAR, next)) { | 758 } else if (identical($STAR, next)) { |
750 next = advance(); | 759 next = advance(); |
751 if (identical($SLASH, next)) { | 760 if (identical($SLASH, next)) { |
752 --nesting; | 761 --nesting; |
753 if (0 == nesting) { | 762 if (0 == nesting) { |
754 if (!asciiOnlyLines) handleUnicode(unicodeStart); | 763 if (!asciiOnlyLines) handleUnicode(unicodeStart); |
755 next = advance(); | 764 next = advance(); |
756 appendComment(start, MULTI_LINE_COMMENT_INFO, asciiOnlyComment); | 765 if (dartdoc) { |
| 766 appendDartDoc(start, MULTI_LINE_COMMENT_INFO, asciiOnlyComment); |
| 767 } else { |
| 768 appendComment(start, MULTI_LINE_COMMENT_INFO, asciiOnlyComment); |
| 769 } |
757 break; | 770 break; |
758 } else { | 771 } else { |
759 next = advance(); | 772 next = advance(); |
760 } | 773 } |
761 } | 774 } |
762 } else if (identical($SLASH, next)) { | 775 } else if (identical($SLASH, next)) { |
763 next = advance(); | 776 next = advance(); |
764 if (identical($STAR, next)) { | 777 if (identical($STAR, next)) { |
765 next = advance(); | 778 next = advance(); |
766 ++nesting; | 779 ++nesting; |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1235 switchToUint32(newLength); | 1248 switchToUint32(newLength); |
1236 } | 1249 } |
1237 } | 1250 } |
1238 | 1251 |
1239 void switchToUint32(int newLength) { | 1252 void switchToUint32(int newLength) { |
1240 final newArray = new Uint32List(newLength); | 1253 final newArray = new Uint32List(newLength); |
1241 newArray.setRange(0, arrayLength, array); | 1254 newArray.setRange(0, arrayLength, array); |
1242 array = newArray; | 1255 array = newArray; |
1243 } | 1256 } |
1244 } | 1257 } |
OLD | NEW |