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

Unified Diff: pkg/analyzer/lib/src/dart/scanner/scanner.dart

Issue 2900963009: enable analyzer scanner adapter generic method support (Closed)
Patch Set: Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/fasta/token_utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/fasta/token_utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698