Index: pkg/analyzer/lib/src/dart/scanner/scanner.dart |
diff --git a/pkg/analyzer/lib/src/dart/scanner/scanner.dart b/pkg/analyzer/lib/src/dart/scanner/scanner.dart |
index 1a78ccfb4bbeaa183e99182fd1e6337cf7c76625..6d72b5ff945853185f891ea38663be7685ea93e0 100644 |
--- a/pkg/analyzer/lib/src/dart/scanner/scanner.dart |
+++ b/pkg/analyzer/lib/src/dart/scanner/scanner.dart |
@@ -48,7 +48,8 @@ class Scanner extends fe.Scanner { |
factory Scanner(Source source, CharacterReader reader, |
AnalysisErrorListener errorListener) => |
fe.Scanner.useFasta |
- ? new _Scanner2(source, reader.getContents(), errorListener) |
+ ? new _Scanner2( |
+ source, reader.getContents(), reader.offset, errorListener) |
: new Scanner._(source, reader, errorListener); |
Scanner._(this.source, CharacterReader reader, this._errorListener) |
@@ -75,6 +76,11 @@ class _Scanner2 implements Scanner { |
final String _contents; |
/** |
+ * The offset of the first character from the reader. |
+ */ |
+ final int _readerOffset; |
+ |
+ /** |
* The error listener that will be informed of any errors that are found |
* during the scan. |
*/ |
@@ -97,7 +103,8 @@ class _Scanner2 implements Scanner { |
@override |
bool scanLazyAssignmentOperators = false; |
- _Scanner2(this.source, this._contents, this._errorListener) { |
+ _Scanner2( |
+ this.source, this._contents, this._readerOffset, this._errorListener) { |
lineStarts.add(0); |
} |
@@ -130,7 +137,15 @@ class _Scanner2 implements Scanner { |
@override |
void setSourceStart(int line, int column) { |
- throw 'unsupported operation'; |
+ lineStarts.removeAt(0); |
+ int offset = _readerOffset; |
+ if (line < 1 || column < 1 || offset < 0 || (line + column - 2) >= offset) { |
+ return; |
+ } |
+ for (int i = 2; i < line; i++) { |
+ lineStarts.add(1); |
+ } |
+ lineStarts.add(offset - column + 1); |
} |
@override |
@@ -140,15 +155,9 @@ class _Scanner2 implements Scanner { |
@override |
Token tokenize() { |
- // Note: Fasta always supports lazy assignment operators (`&&=` and `||=`), |
- // so we can ignore the `scanLazyAssignmentOperators` flag. |
- if (scanGenericMethodComments) { |
- // Fasta doesn't support generic method comments. |
- // TODO(danrubel): remove this once fasts support has been added. |
- throw 'No generic method comment support in Fasta'; |
- } |
fasta.ScannerResult result = fasta.scanString(_contents, |
includeComments: _preserveComments, |
+ scanGenericMethodComments: scanGenericMethodComments, |
scanLazyAssignmentOperators: scanLazyAssignmentOperators); |
// fasta pretends there is an additional line at EOF |
lineStarts |
@@ -161,6 +170,14 @@ class _Scanner2 implements Scanner { |
token = token.next; |
} |
firstToken = token; |
+ // Update all token offsets based upon the reader's starting offset |
+ if (_readerOffset != -1) { |
+ final int delta = _readerOffset + 1; |
+ do { |
+ token.offset += delta; |
+ token = token.next; |
+ } while (!token.isEof); |
+ } |
return firstToken; |
} |