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

Side by Side Diff: frog/source.dart

Issue 8823010: frog: life is better with colors :) (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: '' Created 9 years 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 // TODO(jimhug): This should be an interface to work better with tools. 5 // TODO(jimhug): This should be an interface to work better with tools.
6 /** 6 /**
7 * Represents a file of source code. 7 * Represents a file of source code.
8 */ 8 */
9 class SourceFile implements Comparable { 9 class SourceFile implements Comparable {
10 // TODO(terry): This filename for in memory buffer. May need to rework if 10 // TODO(terry): This filename for in memory buffer. May need to rework if
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 65 }
66 66
67 int getColumn(int line, int position) { 67 int getColumn(int line, int position) {
68 return position - lineStarts[line]; 68 return position - lineStarts[line];
69 } 69 }
70 70
71 /** 71 /**
72 * Create a pretty string representation from a character position 72 * Create a pretty string representation from a character position
73 * in the file. 73 * in the file.
74 */ 74 */
75 String getLocationMessage(String message, int start, [int end, bool includeTex t=false]) { 75 String getLocationMessage(String message, int start,
76 [int end, bool includeText=false]) {
76 var line = getLine(start); 77 var line = getLine(start);
77 var column = getColumn(line, start); 78 var column = getColumn(line, start);
78 79
79 var buf = new StringBuffer( 80 var buf = new StringBuffer('${filename}:${line + 1}:${column + 1}: $message' );
Jennifer Messerly 2011/12/06 22:50:03 long line
Siggi Cherem (dart-lang) 2011/12/06 23:37:38 Done.
80 '${filename}:${line + 1}:${column + 1}: $message');
81 if (includeText) { 81 if (includeText) {
82 buf.add('\n'); 82 buf.add('\n');
83 var textLine; 83 var textLine;
84 // +1 for 0-indexing, +1 again to avoid the last line of the file 84 // +1 for 0-indexing, +1 again to avoid the last line of the file
85 if ((line + 2) < _lineStarts.length) { 85 if ((line + 2) < _lineStarts.length) {
86 textLine = text.substring(_lineStarts[line], _lineStarts[line+1]); 86 textLine = text.substring(_lineStarts[line], _lineStarts[line+1]);
87 } else { 87 } else {
88 textLine = text.substring(_lineStarts[line]) + '\n'; 88 textLine = text.substring(_lineStarts[line]) + '\n';
89 } 89 }
90 buf.add(textLine);
91 int i = 0;
92 for (; i < column; i++) {
93 buf.add(' ');
94 }
95 90
96 int toColumn = Math.min(column + (end-start), textLine.length); 91 int toColumn = Math.min(column + (end-start), textLine.length);
92 if (options.useColors) {
93 buf.add(textLine.substring(0, column));
94 buf.add(_RED_COLOR);
95 buf.add(textLine.substring(column, toColumn));
96 buf.add(_NO_COLOR);
97 buf.add(textLine.substring(toColumn));
98 } else {
99 buf.add(textLine);
100 int i = 0;
101 for (; i < column; i++) {
102 buf.add(' ');
103 }
97 104
98 for (; i < toColumn; i++) { 105 for (; i < toColumn; i++) {
Jennifer Messerly 2011/12/06 22:50:03 Would it be nice to display the arrows even in col
Bob Nystrom 2011/12/06 23:12:46 +1 for always showing ^^^^
Siggi Cherem (dart-lang) 2011/12/06 23:37:38 I added them back, but with colors too. I was no
99 buf.add('^'); 106 buf.add('^');
107 }
100 } 108 }
101 } 109 }
102 110
103 return buf.toString(); 111 return buf.toString();
104 } 112 }
105 113
106 /** Compares two source files. */ 114 /** Compares two source files. */
107 int compareTo(SourceFile other) { 115 int compareTo(SourceFile other) {
108 if (orderInLibrary != null && other.orderInLibrary != null) { 116 if (orderInLibrary != null && other.orderInLibrary != null) {
109 return orderInLibrary - other.orderInLibrary; 117 return orderInLibrary - other.orderInLibrary;
(...skipping 21 matching lines...) Expand all
131 final int end; 139 final int end;
132 140
133 SourceSpan(this.file, this.start, this.end); 141 SourceSpan(this.file, this.start, this.end);
134 142
135 /** Returns the source text corresponding to this [Span]. */ 143 /** Returns the source text corresponding to this [Span]. */
136 String get text() { 144 String get text() {
137 return file.text.substring(start, end); 145 return file.text.substring(start, end);
138 } 146 }
139 147
140 toMessageString(String message) { 148 toMessageString(String message) {
141 return file.getLocationMessage(message, start, end, true); 149 return file.getLocationMessage(message, start, end: end, includeText: true);
142 } 150 }
143 151
144 String get locationText() { 152 String get locationText() {
145 var line = file.getLine(start); 153 var line = file.getLine(start);
146 var column = file.getColumn(line, start); 154 var column = file.getColumn(line, start);
147 return '${file.filename}:${line + 1}:${column + 1}'; 155 return '${file.filename}:${line + 1}:${column + 1}';
148 } 156 }
149 157
150 /** Compares two source spans by file and position. Handles nulls. */ 158 /** Compares two source spans by file and position. Handles nulls. */
151 int compareTo(SourceSpan other) { 159 int compareTo(SourceSpan other) {
152 if (file == other.file) { 160 if (file == other.file) {
153 int d = start - other.start; 161 int d = start - other.start;
154 return d == 0 ? (end - other.end) : d; 162 return d == 0 ? (end - other.end) : d;
155 } 163 }
156 return file.compareTo(other.file); 164 return file.compareTo(other.file);
157 } 165 }
158 } 166 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698