OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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('source_file'); | 5 #library('source_file'); |
6 | 6 |
7 #import('../../frog/leg/colors.dart'); | 7 #import('../../frog/leg/colors.dart'); |
8 | 8 |
9 /** | 9 /** |
10 * Represents a file of source code. | 10 * Represents a file of source code. |
(...skipping 24 matching lines...) Expand all Loading... |
35 } | 35 } |
36 return _lineStarts; | 36 return _lineStarts; |
37 } | 37 } |
38 | 38 |
39 int getLine(int position) { | 39 int getLine(int position) { |
40 // TODO(jimhug): Implement as binary search. | 40 // TODO(jimhug): Implement as binary search. |
41 var starts = lineStarts; | 41 var starts = lineStarts; |
42 for (int i=0; i < starts.length; i++) { | 42 for (int i=0; i < starts.length; i++) { |
43 if (starts[i] > position) return i-1; | 43 if (starts[i] > position) return i-1; |
44 } | 44 } |
45 world.internalError('bad position'); | 45 throw 'bad position'; |
46 } | 46 } |
47 | 47 |
48 int getColumn(int line, int position) { | 48 int getColumn(int line, int position) { |
49 return position - lineStarts[line]; | 49 return position - lineStarts[line]; |
50 } | 50 } |
51 | 51 |
52 /** | 52 /** |
53 * Create a pretty string representation from a character position | 53 * Create a pretty string representation from a character position |
54 * in the file. | 54 * in the file. |
55 */ | 55 */ |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 if (useColors) buf.add(RED_COLOR); | 89 if (useColors) buf.add(RED_COLOR); |
90 for (; i < toColumn; i++) { | 90 for (; i < toColumn; i++) { |
91 buf.add('^'); | 91 buf.add('^'); |
92 } | 92 } |
93 if (useColors) buf.add(NO_COLOR); | 93 if (useColors) buf.add(NO_COLOR); |
94 } | 94 } |
95 | 95 |
96 return buf.toString(); | 96 return buf.toString(); |
97 } | 97 } |
98 } | 98 } |
OLD | NEW |