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

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

Issue 2711453002: Implement shell-style comments and record shebangs as comments. (Closed)
Patch Set: Created 3 years, 10 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) 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 library dart2js.scanner.string_scanner; 5 library dart2js.scanner.string_scanner;
6 6
7 import 'array_based_scanner.dart' show 7 import 'array_based_scanner.dart' show
8 ArrayBasedScanner; 8 ArrayBasedScanner;
9 9
10 import 'precedence.dart' show 10 import 'precedence.dart' show
11 PrecedenceInfo; 11 PrecedenceInfo;
12 12
13 import 'token.dart' show 13 import 'token.dart' show
14 StringToken, 14 StringToken,
15 Token; 15 Token;
16 16
17 /** 17 /**
18 * Scanner that reads from a String and creates tokens that points to 18 * Scanner that reads from a String and creates tokens that points to
19 * substrings. 19 * substrings.
20 */ 20 */
21 class StringScanner extends ArrayBasedScanner { 21 class StringScanner extends ArrayBasedScanner {
22 /** The file content. */ 22 /** The file content. */
23 String string; 23 String string;
24 24
25 /** The current offset in [string]. */ 25 /** The current offset in [string]. */
26 int scanOffset = -1; 26 int scanOffset = -1;
27 27
28 StringScanner(String string, {bool includeComments: false}) 28 StringScanner(String string,
29 {bool includeComments: false, bool enableShellStyleComments: false})
29 : string = ensureZeroTermination(string), 30 : string = ensureZeroTermination(string),
30 super(includeComments); 31 super(includeComments, enableShellStyleComments);
31 32
32 static String ensureZeroTermination(String string) { 33 static String ensureZeroTermination(String string) {
33 return (string.isEmpty || string.codeUnitAt(string.length - 1) != 0) 34 return (string.isEmpty || string.codeUnitAt(string.length - 1) != 0)
34 // TODO(lry): abort instead of copying the array, or warn? 35 // TODO(lry): abort instead of copying the array, or warn?
35 ? string + '\x00' 36 ? string + '\x00'
36 : string; 37 : string;
37 } 38 }
38 39
39 int advance() => string.codeUnitAt(++scanOffset); 40 int advance() => string.codeUnitAt(++scanOffset);
40 int peek() => string.codeUnitAt(scanOffset + 1); 41 int peek() => string.codeUnitAt(scanOffset + 1);
(...skipping 10 matching lines...) Expand all
51 void appendSubstringToken(PrecedenceInfo info, int start, bool asciiOnly, 52 void appendSubstringToken(PrecedenceInfo info, int start, bool asciiOnly,
52 [int extraOffset = 0]) { 53 [int extraOffset = 0]) {
53 tail.next = new StringToken.fromSubstring( 54 tail.next = new StringToken.fromSubstring(
54 info, string, start, scanOffset + extraOffset, tokenStart, 55 info, string, start, scanOffset + extraOffset, tokenStart,
55 canonicalize: true); 56 canonicalize: true);
56 tail = tail.next; 57 tail = tail.next;
57 } 58 }
58 59
59 bool atEndOfFile() => scanOffset >= string.length - 1; 60 bool atEndOfFile() => scanOffset >= string.length - 1;
60 } 61 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698