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

Side by Side Diff: pkg/source_maps/lib/parser.dart

Issue 237123003: Support unmapped areas in source maps. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 /// Contains the top-level function to parse source maps version 3. 5 /// Contains the top-level function to parse source maps version 3.
6 library source_maps.parser; 6 library source_maps.parser;
7 7
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'span.dart'; 10 import 'span.dart';
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // following order: 178 // following order:
179 // 0: the starting column in the current line of the generated file 179 // 0: the starting column in the current line of the generated file
180 // 1: the id of the original source file 180 // 1: the id of the original source file
181 // 2: the starting line in the original source 181 // 2: the starting line in the original source
182 // 3: the starting column in the original source 182 // 3: the starting column in the original source
183 // 4: the id of the original symbol name 183 // 4: the id of the original symbol name
184 // The values are relative to the previous encountered values. 184 // The values are relative to the previous encountered values.
185 if (tokenizer.nextKind.isNewSegment) throw _segmentError(0, line); 185 if (tokenizer.nextKind.isNewSegment) throw _segmentError(0, line);
186 column += tokenizer._consumeValue(); 186 column += tokenizer._consumeValue();
187 if (!tokenizer.nextKind.isValue) { 187 if (!tokenizer.nextKind.isValue) {
188 entries.add(new TargetEntry(column, srcUrlId, srcLine, srcColumn)); 188 entries.add(new TargetEntry(column));
189 } else { 189 } else {
190 srcUrlId += tokenizer._consumeValue(); 190 srcUrlId += tokenizer._consumeValue();
191 if (srcUrlId >= urls.length) { 191 if (srcUrlId >= urls.length) {
192 throw new StateError( 192 throw new StateError(
193 'Invalid source url id. $targetUrl, $line, $srcUrlId'); 193 'Invalid source url id. $targetUrl, $line, $srcUrlId');
194 } 194 }
195 if (!tokenizer.nextKind.isValue) throw _segmentError(2, line); 195 if (!tokenizer.nextKind.isValue) throw _segmentError(2, line);
196 srcLine += tokenizer._consumeValue(); 196 srcLine += tokenizer._consumeValue();
197 if (!tokenizer.nextKind.isValue) throw _segmentError(3, line); 197 if (!tokenizer.nextKind.isValue) throw _segmentError(3, line);
198 srcColumn += tokenizer._consumeValue(); 198 srcColumn += tokenizer._consumeValue();
199 if (!tokenizer.nextKind.isValue) { 199 if (!tokenizer.nextKind.isValue) {
200 entries.add(new TargetEntry(column, srcUrlId, srcLine, srcColumn)); 200 entries.add(new TargetEntry(column,
201 sourceUrlId: srcUrlId,
Siggi Cherem (dart-lang) 2014/04/18 02:00:31 nit: just to match the style we use in this packag
Siggi Cherem (dart-lang) 2014/04/22 18:12:44 Thinking more about it, let's switch back to posit
zarah 2014/04/23 07:52:12 Done.
zarah 2014/04/23 07:52:12 Updated to 0.9.1-dev .
202 sourceLine: srcLine,
203 sourceColumn: srcColumn));
201 } else { 204 } else {
202 srcNameId += tokenizer._consumeValue(); 205 srcNameId += tokenizer._consumeValue();
203 if (srcNameId >= names.length) { 206 if (srcNameId >= names.length) {
204 throw new StateError( 207 throw new StateError(
205 'Invalid name id: $targetUrl, $line, $srcNameId'); 208 'Invalid name id: $targetUrl, $line, $srcNameId');
206 } 209 }
207 entries.add( 210 entries.add(
208 new TargetEntry(column, srcUrlId, srcLine, srcColumn, srcNameId)); 211 new TargetEntry(column,
Siggi Cherem (dart-lang) 2014/04/18 02:00:31 similarly here. We can also move this 'new ..." to
zarah 2014/04/23 07:52:12 Done.
212 sourceUrlId: srcUrlId,
213 sourceLine: srcLine,
214 sourceColumn: srcColumn,
215 sourceNameId: srcNameId));
209 } 216 }
210 } 217 }
211 if (tokenizer.nextKind.isNewSegment) tokenizer._consumeNewSegment(); 218 if (tokenizer.nextKind.isNewSegment) tokenizer._consumeNewSegment();
212 } 219 }
213 if (!entries.isEmpty) { 220 if (!entries.isEmpty) {
214 lines.add(new TargetLineEntry(line, entries)); 221 lines.add(new TargetLineEntry(line, entries));
215 } 222 }
216 } 223 }
217 224
218 _segmentError(int seen, int line) => new StateError( 225 _segmentError(int seen, int line) => new StateError(
(...skipping 16 matching lines...) Expand all
235 TargetEntry _findColumn(int line, int column, TargetLineEntry lineEntry) { 242 TargetEntry _findColumn(int line, int column, TargetLineEntry lineEntry) {
236 if (lineEntry == null || lineEntry.entries.length == 0) return null; 243 if (lineEntry == null || lineEntry.entries.length == 0) return null;
237 if (lineEntry.line != line) return lineEntry.entries.last; 244 if (lineEntry.line != line) return lineEntry.entries.last;
238 var entries = lineEntry.entries; 245 var entries = lineEntry.entries;
239 int index = binarySearch(entries, (e) => e.column > column); 246 int index = binarySearch(entries, (e) => e.column > column);
240 return (index <= 0) ? null : entries[index - 1]; 247 return (index <= 0) ? null : entries[index - 1];
241 } 248 }
242 249
243 Span spanFor(int line, int column, {Map<String, SourceFile> files}) { 250 Span spanFor(int line, int column, {Map<String, SourceFile> files}) {
244 var entry = _findColumn(line, column, _findLine(line)); 251 var entry = _findColumn(line, column, _findLine(line));
245 if (entry == null) return null; 252 if (entry == null || entry.sourceUrlId == null) return null;
246 var url = urls[entry.sourceUrlId]; 253 var url = urls[entry.sourceUrlId];
247 if (files != null && files[url] != null) { 254 if (files != null && files[url] != null) {
248 var file = files[url]; 255 var file = files[url];
249 var start = file.getOffset(entry.sourceLine, entry.sourceColumn); 256 var start = file.getOffset(entry.sourceLine, entry.sourceColumn);
250 if (entry.sourceNameId != null) { 257 if (entry.sourceNameId != null) {
251 var text = names[entry.sourceNameId]; 258 var text = names[entry.sourceNameId];
252 return new FileSpan(files[url], start, start + text.length, true); 259 return new FileSpan(files[url], start, start + text.length, true);
253 } else { 260 } else {
254 return new FileSpan(files[url], start); 261 return new FileSpan(files[url], start);
255 } 262 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 } 322 }
316 323
317 /// A target segment entry read from a source map 324 /// A target segment entry read from a source map
318 class TargetEntry { 325 class TargetEntry {
319 final int column; 326 final int column;
320 final int sourceUrlId; 327 final int sourceUrlId;
321 final int sourceLine; 328 final int sourceLine;
322 final int sourceColumn; 329 final int sourceColumn;
323 final int sourceNameId; 330 final int sourceNameId;
324 331
325 TargetEntry(this.column, this.sourceUrlId, this.sourceLine, 332 TargetEntry(this.column, {this.sourceUrlId, this.sourceLine,
326 this.sourceColumn, [this.sourceNameId]); 333 this.sourceColumn, this.sourceNameId});
327 334
328 String toString() => '$runtimeType: ' 335 String toString() => '$runtimeType: '
329 '($column, $sourceUrlId, $sourceLine, $sourceColumn, $sourceNameId)'; 336 '($column, $sourceUrlId, $sourceLine, $sourceColumn, $sourceNameId)';
330 } 337 }
331 338
332 /** A character iterator over a string that can peek one character ahead. */ 339 /** A character iterator over a string that can peek one character ahead. */
333 class _MappingTokenizer implements Iterator<String> { 340 class _MappingTokenizer implements Iterator<String> {
334 final String _internal; 341 final String _internal;
335 final int _length; 342 final int _length;
336 int index = -1; 343 int index = -1;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 static const _TokenKind EOF = const _TokenKind(isEof: true); 388 static const _TokenKind EOF = const _TokenKind(isEof: true);
382 static const _TokenKind VALUE = const _TokenKind(); 389 static const _TokenKind VALUE = const _TokenKind();
383 final bool isNewLine; 390 final bool isNewLine;
384 final bool isNewSegment; 391 final bool isNewSegment;
385 final bool isEof; 392 final bool isEof;
386 bool get isValue => !isNewLine && !isNewSegment && !isEof; 393 bool get isValue => !isNewLine && !isNewSegment && !isEof;
387 394
388 const _TokenKind( 395 const _TokenKind(
389 {this.isNewLine: false, this.isNewSegment: false, this.isEof: false}); 396 {this.isNewLine: false, this.isNewSegment: false, this.isEof: false});
390 } 397 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698