| 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 import 'package:source_span/source_span.dart'; | 5 import 'package:source_span/source_span.dart'; |
| 6 | 6 |
| 7 import 'eager_span_scanner.dart'; | 7 import 'eager_span_scanner.dart'; |
| 8 import 'exception.dart'; | 8 import 'exception.dart'; |
| 9 import 'line_scanner.dart'; | 9 import 'line_scanner.dart'; |
| 10 import 'relative_span_scanner.dart'; | 10 import 'relative_span_scanner.dart'; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 "this LineScanner."); | 31 "this LineScanner."); |
| 32 } | 32 } |
| 33 | 33 |
| 34 this.position = state.position; | 34 this.position = state.position; |
| 35 } | 35 } |
| 36 | 36 |
| 37 /// The [FileSpan] for [lastMatch]. | 37 /// The [FileSpan] for [lastMatch]. |
| 38 /// | 38 /// |
| 39 /// This is the span for the entire match. There's no way to get spans for | 39 /// This is the span for the entire match. There's no way to get spans for |
| 40 /// subgroups since [Match] exposes no information about their positions. | 40 /// subgroups since [Match] exposes no information about their positions. |
| 41 FileSpan get lastSpan => _lastSpan; | 41 FileSpan get lastSpan { |
| 42 if (lastMatch == null) _lastSpan = null; |
| 43 return _lastSpan; |
| 44 } |
| 42 FileSpan _lastSpan; | 45 FileSpan _lastSpan; |
| 43 | 46 |
| 44 /// The current location of the scanner. | 47 /// The current location of the scanner. |
| 45 FileLocation get location => _sourceFile.location(position); | 48 FileLocation get location => _sourceFile.location(position); |
| 46 | 49 |
| 47 /// Returns an empty span at the current location. | 50 /// Returns an empty span at the current location. |
| 48 FileSpan get emptySpan => location.pointSpan(); | 51 FileSpan get emptySpan => location.pointSpan(); |
| 49 | 52 |
| 50 /// Creates a new [SpanScanner] that starts scanning from [position]. | 53 /// Creates a new [SpanScanner] that starts scanning from [position]. |
| 51 /// | 54 /// |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 return true; | 98 return true; |
| 96 } | 99 } |
| 97 | 100 |
| 98 void error(String message, {Match match, int position, int length}) { | 101 void error(String message, {Match match, int position, int length}) { |
| 99 validateErrorArgs(string, match, position, length); | 102 validateErrorArgs(string, match, position, length); |
| 100 | 103 |
| 101 if (match == null && position == null && length == null) match = lastMatch; | 104 if (match == null && position == null && length == null) match = lastMatch; |
| 102 if (position == null) { | 105 if (position == null) { |
| 103 position = match == null ? this.position : match.start; | 106 position = match == null ? this.position : match.start; |
| 104 } | 107 } |
| 105 if (length == null) length = match == null ? 1 : match.end - match.start; | 108 if (length == null) length = match == null ? 0 : match.end - match.start; |
| 106 | 109 |
| 107 var span = _sourceFile.span(position, position + length); | 110 var span = _sourceFile.span(position, position + length); |
| 108 throw new StringScannerException(message, span, string); | 111 throw new StringScannerException(message, span, string); |
| 109 } | 112 } |
| 110 } | 113 } |
| 111 | 114 |
| 112 /// A class representing the state of a [SpanScanner]. | 115 /// A class representing the state of a [SpanScanner]. |
| 113 class _SpanScannerState implements LineScannerState { | 116 class _SpanScannerState implements LineScannerState { |
| 114 /// The [SpanScanner] that created this. | 117 /// The [SpanScanner] that created this. |
| 115 final SpanScanner _scanner; | 118 final SpanScanner _scanner; |
| 116 | 119 |
| 117 final int position; | 120 final int position; |
| 118 int get line => _scanner._sourceFile.getLine(position); | 121 int get line => _scanner._sourceFile.getLine(position); |
| 119 int get column => _scanner._sourceFile.getColumn(position); | 122 int get column => _scanner._sourceFile.getColumn(position); |
| 120 | 123 |
| 121 _SpanScannerState(this._scanner, this.position); | 124 _SpanScannerState(this._scanner, this.position); |
| 122 } | 125 } |
| OLD | NEW |