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

Side by Side Diff: dart/lib/compiler/implementation/scanner/string_scanner.dart

Issue 11092101: Diagnose unbalanced parentheses better. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 2 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
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 /** 5 /**
6 * Scanner that reads from a String and creates tokens that points to 6 * Scanner that reads from a String and creates tokens that points to
7 * substrings. 7 * substrings.
8 */ 8 */
9 class StringScanner extends ArrayBasedScanner<SourceString> { 9 class StringScanner extends ArrayBasedScanner<SourceString> {
10 final String string; 10 final String string;
(...skipping 14 matching lines...) Expand all
25 25
26 SourceString utf8String(int start, int offset) { 26 SourceString utf8String(int start, int offset) {
27 return new SubstringWrapper(string, start, byteOffset + offset + 1); 27 return new SubstringWrapper(string, start, byteOffset + offset + 1);
28 } 28 }
29 29
30 void appendByteStringToken(PrecedenceInfo info, SourceString value) { 30 void appendByteStringToken(PrecedenceInfo info, SourceString value) {
31 // assert(kind != $a || keywords.get(value) == null); 31 // assert(kind != $a || keywords.get(value) == null);
32 tail.next = new StringToken.fromSource(info, value, tokenStart); 32 tail.next = new StringToken.fromSource(info, value, tokenStart);
33 tail = tail.next; 33 tail = tail.next;
34 } 34 }
35
36 void unmatchedBeginGroup(BeginGroupToken begin) {
37 SourceString error = new SourceString('unmatched "${begin.stringValue}"');
38 Token close =
39 new StringToken.fromSource(BAD_INPUT_INFO, error, begin.charOffset);
40 // We want to ensure that unmatched BeginGroupTokens are reported
41 // as errors. However, the rest of the parser assume the groups
42 // are well-balanced and will never look at the endGroup
43 // token. This is a nice property that allows us to skip quickly
44 // over correct code. By inserting an additional error token in
45 // the stream, we can keep ignoring endGroup tokens.
46 Token next =
47 new StringToken.fromSource(BAD_INPUT_INFO, error, begin.charOffset);
48 begin.endGroup = close;
49 close.next = next;
50 next.next = begin.next;
51 }
35 } 52 }
36 53
37 class SubstringWrapper implements SourceString { 54 class SubstringWrapper implements SourceString {
38 final String internalString; 55 final String internalString;
39 final int begin; 56 final int begin;
40 final int end; 57 final int end;
41 58
42 const SubstringWrapper(String this.internalString, 59 const SubstringWrapper(String this.internalString,
43 int this.begin, int this.end); 60 int this.begin, int this.end);
44 61
(...skipping 21 matching lines...) Expand all
66 assert(0 <= terminal); 83 assert(0 <= terminal);
67 assert(initial + terminal <= internalString.length); 84 assert(initial + terminal <= internalString.length);
68 return new SubstringWrapper(internalString, 85 return new SubstringWrapper(internalString,
69 begin + initial, end - terminal); 86 begin + initial, end - terminal);
70 } 87 }
71 88
72 bool isEmpty() => begin == end; 89 bool isEmpty() => begin == end;
73 90
74 bool isPrivate() => !isEmpty() && internalString.charCodeAt(begin) === $_; 91 bool isPrivate() => !isEmpty() && internalString.charCodeAt(begin) === $_;
75 } 92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698