OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 string_scanner.span_scanner; | 5 library string_scanner.span_scanner; |
6 | 6 |
7 import 'package:source_span/source_span.dart'; | 7 import 'package:source_span/source_span.dart'; |
8 | 8 |
9 import 'exception.dart'; | 9 import 'exception.dart'; |
10 import 'line_scanner.dart'; | 10 import 'line_scanner.dart'; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 /// | 51 /// |
52 /// [sourceUrl] is used as [SourceLocation.sourceUrl] for the returned | 52 /// [sourceUrl] is used as [SourceLocation.sourceUrl] for the returned |
53 /// [FileSpan]s as well as for error reporting. It can be a [String], a | 53 /// [FileSpan]s as well as for error reporting. It can be a [String], a |
54 /// [Uri], or `null`. | 54 /// [Uri], or `null`. |
55 SpanScanner(String string, {sourceUrl, int position}) | 55 SpanScanner(String string, {sourceUrl, int position}) |
56 : _sourceFile = new SourceFile(string, url: sourceUrl), | 56 : _sourceFile = new SourceFile(string, url: sourceUrl), |
57 super(string, sourceUrl: sourceUrl, position: position); | 57 super(string, sourceUrl: sourceUrl, position: position); |
58 | 58 |
59 /// Creates a [FileSpan] representing the source range between [startState] | 59 /// Creates a [FileSpan] representing the source range between [startState] |
60 /// and the current position. | 60 /// and the current position. |
61 FileSpan spanFrom(LineScannerState startState) => | 61 FileSpan spanFrom(LineScannerState startState, [LineScannerState endState]) { |
62 _sourceFile.span(startState.position, position); | 62 var endPosition = endState == null ? position : endState.position; |
| 63 return _sourceFile.span(startState.position, endPosition); |
| 64 } |
63 | 65 |
64 bool matches(Pattern pattern) { | 66 bool matches(Pattern pattern) { |
65 if (!super.matches(pattern)) { | 67 if (!super.matches(pattern)) { |
66 _lastSpan = null; | 68 _lastSpan = null; |
67 return false; | 69 return false; |
68 } | 70 } |
69 | 71 |
70 _lastSpan = _sourceFile.span(position, lastMatch.end); | 72 _lastSpan = _sourceFile.span(position, lastMatch.end); |
71 return true; | 73 return true; |
72 } | 74 } |
(...skipping 16 matching lines...) Expand all Loading... |
89 class _SpanScannerState implements LineScannerState { | 91 class _SpanScannerState implements LineScannerState { |
90 /// The [SpanScanner] that created this. | 92 /// The [SpanScanner] that created this. |
91 final SpanScanner _scanner; | 93 final SpanScanner _scanner; |
92 | 94 |
93 final int position; | 95 final int position; |
94 int get line => _scanner._sourceFile.getLine(position); | 96 int get line => _scanner._sourceFile.getLine(position); |
95 int get column => _scanner._sourceFile.getColumn(position); | 97 int get column => _scanner._sourceFile.getColumn(position); |
96 | 98 |
97 _SpanScannerState(this._scanner, this.position); | 99 _SpanScannerState(this._scanner, this.position); |
98 } | 100 } |
OLD | NEW |