| 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 UnterminatedToken; | 14 import 'error_token.dart' show 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, CommentToken, SymbolToken, Token; | 20 import 'token.dart' |
| 21 show BeginGroupToken, CommentToken, DartDocToken, SymbolToken, Token; |
| 21 | 22 |
| 22 import 'token_constants.dart'; | 23 import 'token_constants.dart'; |
| 23 | 24 |
| 24 import 'characters.dart'; | 25 import 'characters.dart'; |
| 25 | 26 |
| 26 abstract class AbstractScanner implements Scanner { | 27 abstract class AbstractScanner implements Scanner { |
| 27 final bool includeComments; | 28 final bool includeComments; |
| 28 | 29 |
| 29 /** | 30 /** |
| 31 * A flag indicating whether to parse generic method comments, of the form |
| 32 * `/*=T*/` and `/*<T>*/`. The flag [includeComments] must be set to `true`. |
| 33 */ |
| 34 bool scanGenericMethodComments = false; |
| 35 |
| 36 /** |
| 30 * The string offset for the next token that will be created. | 37 * The string offset for the next token that will be created. |
| 31 * | 38 * |
| 32 * Note that in the [Utf8BytesScanner], [stringOffset] and [scanOffset] values | 39 * Note that in the [Utf8BytesScanner], [stringOffset] and [scanOffset] values |
| 33 * are different. One string character can be encoded using multiple UTF-8 | 40 * are different. One string character can be encoded using multiple UTF-8 |
| 34 * bytes. | 41 * bytes. |
| 35 */ | 42 */ |
| 36 int tokenStart = -1; | 43 int tokenStart = -1; |
| 37 | 44 |
| 38 /** | 45 /** |
| 39 * A pointer to the token stream created by this scanner. The first token | 46 * A pointer to the token stream created by this scanner. The first token |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 185 |
| 179 /** Documentation in subclass [ArrayBasedScanner]. */ | 186 /** Documentation in subclass [ArrayBasedScanner]. */ |
| 180 int appendEndGroup(PrecedenceInfo info, int openKind); | 187 int appendEndGroup(PrecedenceInfo info, int openKind); |
| 181 | 188 |
| 182 /** Documentation in subclass [ArrayBasedScanner]. */ | 189 /** Documentation in subclass [ArrayBasedScanner]. */ |
| 183 void appendGt(PrecedenceInfo info); | 190 void appendGt(PrecedenceInfo info); |
| 184 | 191 |
| 185 /** Documentation in subclass [ArrayBasedScanner]. */ | 192 /** Documentation in subclass [ArrayBasedScanner]. */ |
| 186 void appendGtGt(PrecedenceInfo info); | 193 void appendGtGt(PrecedenceInfo info); |
| 187 | 194 |
| 188 /** Documentation in subclass [ArrayBasedScanner]. */ | |
| 189 void appendComment(start, PrecedenceInfo info, bool asciiOnly); | |
| 190 | |
| 191 /** Documentation in subclass [ArrayBasedScanner]. */ | |
| 192 void appendDartDoc(start, PrecedenceInfo info, bool asciiOnly); | |
| 193 | |
| 194 /// Append [token] to the token stream. | 195 /// Append [token] to the token stream. |
| 195 void appendErrorToken(ErrorToken token); | 196 void appendErrorToken(ErrorToken token); |
| 196 | 197 |
| 198 /** |
| 199 * Returns a new comment from the scan offset [start] to the current |
| 200 * [scanOffset] plus the [extraOffset]. For example, if the current |
| 201 * scanOffset is 10, then [appendSubstringToken(5, -1)] will append the |
| 202 * substring string [5,9). |
| 203 * |
| 204 * Note that [extraOffset] can only be used if the covered character(s) are |
| 205 * known to be ASCII. |
| 206 */ |
| 207 CommentToken createCommentToken( |
| 208 PrecedenceInfo info, int start, bool asciiOnly, |
| 209 [int extraOffset = 0]); |
| 210 |
| 211 /** |
| 212 * Returns a new dartdoc from the scan offset [start] to the current |
| 213 * [scanOffset] plus the [extraOffset]. For example, if the current |
| 214 * scanOffset is 10, then [appendSubstringToken(5, -1)] will append the |
| 215 * substring string [5,9). |
| 216 * |
| 217 * Note that [extraOffset] can only be used if the covered character(s) are |
| 218 * known to be ASCII. |
| 219 */ |
| 220 DartDocToken createDartDocToken( |
| 221 PrecedenceInfo info, int start, bool asciiOnly, |
| 222 [int extraOffset = 0]); |
| 223 |
| 197 /** Documentation in subclass [ArrayBasedScanner]. */ | 224 /** Documentation in subclass [ArrayBasedScanner]. */ |
| 198 void discardOpenLt(); | 225 void discardOpenLt(); |
| 199 | 226 |
| 200 /// Return true when at EOF. | 227 /// Return true when at EOF. |
| 201 bool atEndOfFile(); | 228 bool atEndOfFile(); |
| 202 | 229 |
| 203 Token tokenize() { | 230 Token tokenize() { |
| 204 while (!atEndOfFile()) { | 231 while (!atEndOfFile()) { |
| 205 int next = advance(); | 232 int next = advance(); |
| 206 while (!identical(next, $EOF)) { | 233 while (!identical(next, $EOF)) { |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 if (next > 127) { | 818 if (next > 127) { |
| 792 asciiOnlyLines = false; | 819 asciiOnlyLines = false; |
| 793 asciiOnlyComment = false; | 820 asciiOnlyComment = false; |
| 794 } | 821 } |
| 795 next = advance(); | 822 next = advance(); |
| 796 } | 823 } |
| 797 } | 824 } |
| 798 return next; | 825 return next; |
| 799 } | 826 } |
| 800 | 827 |
| 828 void appendComment(int start, PrecedenceInfo info, bool asciiOnly) { |
| 829 if (!includeComments) return; |
| 830 CommentToken newComment = createCommentToken(info, start, asciiOnly); |
| 831 if (scanGenericMethodComments) { |
| 832 String value = newComment.lexeme; |
| 833 int length = value.length; |
| 834 if (length > 5 && |
| 835 value.codeUnitAt(0) == $SLASH && |
| 836 value.codeUnitAt(1) == $STAR && |
| 837 value.codeUnitAt(2) == $EQ) { |
| 838 newComment = new CommentToken.fromString( |
| 839 GENERIC_METHOD_TYPE_ASSIGN, value, start); |
| 840 } else if (length > 6 && |
| 841 value.codeUnitAt(0) == $SLASH && |
| 842 value.codeUnitAt(1) == $STAR && |
| 843 value.codeUnitAt(2) == $LT && |
| 844 value.codeUnitAt(length - 1) == $SLASH && |
| 845 value.codeUnitAt(length - 2) == $STAR && |
| 846 value.codeUnitAt(length - 3) == $GT) { |
| 847 newComment = |
| 848 new CommentToken.fromString(GENERIC_METHOD_TYPE_LIST, value, start); |
| 849 } |
| 850 } |
| 851 _appendToCommentStream(newComment); |
| 852 } |
| 853 |
| 854 void appendDartDoc(int start, PrecedenceInfo info, bool asciiOnly) { |
| 855 if (!includeComments) return; |
| 856 Token newComment = createDartDocToken(info, start, asciiOnly); |
| 857 _appendToCommentStream(newComment); |
| 858 } |
| 859 |
| 860 /** |
| 861 * Append the given token to the [tail] of the current stream of tokens. |
| 862 */ |
| 863 void appendToken(Token token) { |
| 864 tail.next = token; |
| 865 tail.next.previousToken = tail; |
| 866 tail = tail.next; |
| 867 if (comments != null) { |
| 868 tail.precedingCommentTokens = comments; |
| 869 comments = null; |
| 870 commentsTail = null; |
| 871 } |
| 872 } |
| 873 |
| 874 void _appendToCommentStream(Token newComment) { |
| 875 if (comments == null) { |
| 876 comments = newComment; |
| 877 commentsTail = comments; |
| 878 } else { |
| 879 commentsTail.next = newComment; |
| 880 commentsTail.next.previousToken = commentsTail; |
| 881 commentsTail = commentsTail.next; |
| 882 } |
| 883 } |
| 884 |
| 801 int tokenizeRawStringKeywordOrIdentifier(int next) { | 885 int tokenizeRawStringKeywordOrIdentifier(int next) { |
| 802 // [next] is $r. | 886 // [next] is $r. |
| 803 int nextnext = peek(); | 887 int nextnext = peek(); |
| 804 if (identical(nextnext, $DQ) || identical(nextnext, $SQ)) { | 888 if (identical(nextnext, $DQ) || identical(nextnext, $SQ)) { |
| 805 int start = scanOffset; | 889 int start = scanOffset; |
| 806 next = advance(); | 890 next = advance(); |
| 807 return tokenizeString(next, start, true); | 891 return tokenizeString(next, start, true); |
| 808 } | 892 } |
| 809 return tokenizeKeywordOrIdentifier(next, true); | 893 return tokenizeKeywordOrIdentifier(next, true); |
| 810 } | 894 } |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1197 switchToUint32(newLength); | 1281 switchToUint32(newLength); |
| 1198 } | 1282 } |
| 1199 } | 1283 } |
| 1200 | 1284 |
| 1201 void switchToUint32(int newLength) { | 1285 void switchToUint32(int newLength) { |
| 1202 final newArray = new Uint32List(newLength); | 1286 final newArray = new Uint32List(newLength); |
| 1203 newArray.setRange(0, arrayLength, array); | 1287 newArray.setRange(0, arrayLength, array); |
| 1204 array = newArray; | 1288 array = newArray; |
| 1205 } | 1289 } |
| 1206 } | 1290 } |
| OLD | NEW |