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

Side by Side Diff: frog/leg/scanner/string_scanner.dart

Issue 9873021: Move frog/leg to lib/compiler/implementation. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « frog/leg/scanner/source_list.dart ('k') | frog/leg/scanner/token.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /**
6 * Scanner that reads from a String and creates tokens that points to
7 * substrings.
8 */
9 class StringScanner extends ArrayBasedScanner<SourceString> {
10 final String string;
11
12 StringScanner(String this.string) : super();
13
14 int nextByte() => charAt(++byteOffset);
15
16 int peek() => charAt(byteOffset + 1);
17
18 int charAt(index)
19 => (string.length > index) ? string.charCodeAt(index) : $EOF;
20
21 SourceString asciiString(int start, int offset) {
22 return new SubstringWrapper(string, start, byteOffset + offset);
23 }
24
25 SourceString utf8String(int start, int offset) {
26 return new SubstringWrapper(string, start, byteOffset + offset + 1);
27 }
28
29 void appendByteStringToken(PrecedenceInfo info, SourceString value) {
30 // assert(kind != $a || keywords.get(value) == null);
31 tail.next = new StringToken.fromSource(info, value, tokenStart);
32 tail = tail.next;
33 }
34 }
35
36 class SubstringWrapper implements SourceString {
37 final String internalString;
38 final int begin;
39 final int end;
40
41 const SubstringWrapper(String this.internalString,
42 int this.begin, int this.end);
43
44 int hashCode() => slowToString().hashCode();
45
46 bool operator ==(other) {
47 return other is SourceString && slowToString() == other.slowToString();
48 }
49
50 void printOn(StringBuffer sb) {
51 sb.add(internalString.substring(begin, end));
52 }
53
54 String slowToString() => internalString.substring(begin, end);
55
56 String toString() => "SubstringWrapper(${slowToString()})";
57
58 String get stringValue() => null;
59
60 Iterator<int> iterator() =>
61 new StringCodeIterator.substring(internalString, begin, end);
62
63 SourceString copyWithoutQuotes(int initial, int terminal) {
64 assert(0 <= initial);
65 assert(0 <= terminal);
66 assert(initial + terminal <= internalString.length);
67 return new SubstringWrapper(internalString,
68 begin + initial, end - terminal);
69 }
70
71 bool isEmpty() => begin == end;
72
73 bool isPrivate() => !isEmpty() && internalString.charCodeAt(begin) === $_;
74 }
OLDNEW
« no previous file with comments | « frog/leg/scanner/source_list.dart ('k') | frog/leg/scanner/token.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698