| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 part of scanner; | 5 part of scanner; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Scanner that reads from a String and creates tokens that points to | 8 * Scanner that reads from a String and creates tokens that points to |
| 9 * substrings. | 9 * substrings. |
| 10 */ | 10 */ |
| 11 class StringScanner extends ArrayBasedScanner { | 11 class StringScanner extends ArrayBasedScanner { |
| 12 /** The file content. */ | 12 /** The file content. */ |
| 13 String string; | 13 String string; |
| 14 | 14 |
| 15 /** The current offset in [string]. */ | 15 /** The current offset in [string]. */ |
| 16 int scanOffset = -1; | 16 int scanOffset = -1; |
| 17 | 17 |
| 18 StringScanner(SourceFile file, {bool includeComments: false, | 18 StringScanner(SourceFile file, {bool includeComments: false}) |
| 19 bool enableNullAwareOperators: false}) | |
| 20 : string = file.slowText(), | 19 : string = file.slowText(), |
| 21 super(file, includeComments, enableNullAwareOperators) { | 20 super(file, includeComments) { |
| 22 ensureZeroTermination(); | 21 ensureZeroTermination(); |
| 23 } | 22 } |
| 24 | 23 |
| 25 StringScanner.fromString(this.string, {bool includeComments: false, | 24 StringScanner.fromString(this.string, {bool includeComments: false}) |
| 26 bool enableNullAwareOperators: false}) | 25 : super(null, includeComments) { |
| 27 : super(null, includeComments, enableNullAwareOperators) { | |
| 28 ensureZeroTermination(); | 26 ensureZeroTermination(); |
| 29 } | 27 } |
| 30 | 28 |
| 31 void ensureZeroTermination() { | 29 void ensureZeroTermination() { |
| 32 if (string.isEmpty || string.codeUnitAt(string.length - 1) != 0) { | 30 if (string.isEmpty || string.codeUnitAt(string.length - 1) != 0) { |
| 33 // TODO(lry): abort instead of copying the array, or warn? | 31 // TODO(lry): abort instead of copying the array, or warn? |
| 34 string = string + '\x00'; | 32 string = string + '\x00'; |
| 35 } | 33 } |
| 36 } | 34 } |
| 37 | 35 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 49 | 47 |
| 50 void appendSubstringToken(PrecedenceInfo info, int start, | 48 void appendSubstringToken(PrecedenceInfo info, int start, |
| 51 bool asciiOnly, [int extraOffset = 0]) { | 49 bool asciiOnly, [int extraOffset = 0]) { |
| 52 tail.next = new StringToken.fromSubstring(info, string, start, | 50 tail.next = new StringToken.fromSubstring(info, string, start, |
| 53 scanOffset + extraOffset, tokenStart, canonicalize: true); | 51 scanOffset + extraOffset, tokenStart, canonicalize: true); |
| 54 tail = tail.next; | 52 tail = tail.next; |
| 55 } | 53 } |
| 56 | 54 |
| 57 bool atEndOfFile() => scanOffset >= string.length - 1; | 55 bool atEndOfFile() => scanOffset >= string.length - 1; |
| 58 } | 56 } |
| OLD | NEW |