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

Unified Diff: lib/src/span_scanner.dart

Issue 1318603008: Add new SpanScanner.eager(). (Closed) Base URL: git@github.com:dart-lang/string_scanner@master
Patch Set: Created 5 years, 4 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 | « lib/src/line_scanner.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/span_scanner.dart
diff --git a/lib/src/span_scanner.dart b/lib/src/span_scanner.dart
index 2a78b5bc0b0d524e6ae1b9b88e7a29ed588dd9c5..ebe230d8a70bb93bd2eb16e41da73167555a17c6 100644
--- a/lib/src/span_scanner.dart
+++ b/lib/src/span_scanner.dart
@@ -6,6 +6,7 @@ library string_scanner.span_scanner;
import 'package:source_span/source_span.dart';
+import 'eager_span_scanner.dart';
import 'exception.dart';
import 'line_scanner.dart';
import 'string_scanner.dart';
@@ -56,6 +57,20 @@ class SpanScanner extends StringScanner implements LineScanner {
: _sourceFile = new SourceFile(string, url: sourceUrl),
super(string, sourceUrl: sourceUrl, position: position);
+ /// Creates a new [SpanScanner] that eagerly computes line and column numbers.
+ ///
+ /// In general [new SpanScanner] will be more efficient, since it avoids extra
+ /// computation on every scan. However, eager scanning can be useful for
+ /// situations where the normal course of parsing frequently involves
+ /// accessing the current line and column numbers.
+ ///
+ /// Note that *only* the `line` and `column` fields on the `SpanScanner`
+ /// itself and its `LineScannerState` are eagerly computed. To limit their
+ /// memory footprint, returned spans and locations will still lazily compute
+ /// their line and column numbers.
+ factory SpanScanner.eager(String string, {sourceUrl, int position}) =
+ EagerSpanScanner;
+
/// Creates a [FileSpan] representing the source range between [startState]
/// and the current position.
FileSpan spanFrom(LineScannerState startState, [LineScannerState endState]) {
« no previous file with comments | « lib/src/line_scanner.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698