| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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:charcode/ascii.dart'; | 5 import 'package:charcode/ascii.dart'; |
| 6 | 6 |
| 7 import 'line_scanner.dart'; | 7 import 'line_scanner.dart'; |
| 8 import 'span_scanner.dart'; | 8 import 'span_scanner.dart'; |
| 9 | 9 |
| 10 // TODO(nweiz): Currently this duplicates code in line_scanner.dart. Once | 10 // TODO(nweiz): Currently this duplicates code in line_scanner.dart. Once |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 } else { | 60 } else { |
| 61 _column = newPosition - | 61 _column = newPosition - |
| 62 string.lastIndexOf(_newlineRegExp, newPosition) - 1; | 62 string.lastIndexOf(_newlineRegExp, newPosition) - 1; |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 EagerSpanScanner(String string, {sourceUrl, int position}) | 67 EagerSpanScanner(String string, {sourceUrl, int position}) |
| 68 : super(string, sourceUrl: sourceUrl, position: position); | 68 : super(string, sourceUrl: sourceUrl, position: position); |
| 69 | 69 |
| 70 bool scanChar(int character) { |
| 71 if (!super.scanChar(character)) return false; |
| 72 _adjustLineAndColumn(character); |
| 73 return true; |
| 74 } |
| 75 |
| 70 int readChar() { | 76 int readChar() { |
| 71 var char = super.readChar(); | 77 var character = super.readChar(); |
| 72 if (char == $lf || (char == $cr && peekChar() != $lf)) { | 78 _adjustLineAndColumn(character); |
| 79 return character; |
| 80 } |
| 81 |
| 82 /// Adjusts [_line] and [_column] after having consumed [character]. |
| 83 void _adjustLineAndColumn(int character) { |
| 84 if (character == $lf || (character == $cr && peekChar() != $lf)) { |
| 73 _line += 1; | 85 _line += 1; |
| 74 _column = 0; | 86 _column = 0; |
| 75 } else { | 87 } else { |
| 76 _column += 1; | 88 _column += 1; |
| 77 } | 89 } |
| 78 return char; | |
| 79 } | 90 } |
| 80 | 91 |
| 81 bool scan(Pattern pattern) { | 92 bool scan(Pattern pattern) { |
| 82 if (!super.scan(pattern)) return false; | 93 if (!super.scan(pattern)) return false; |
| 83 | 94 |
| 84 var newlines = _newlinesIn(lastMatch[0]); | 95 var newlines = _newlinesIn(lastMatch[0]); |
| 85 _line += newlines.length; | 96 _line += newlines.length; |
| 86 if (newlines.isEmpty) { | 97 if (newlines.isEmpty) { |
| 87 _column += lastMatch[0].length; | 98 _column += lastMatch[0].length; |
| 88 } else { | 99 } else { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 104 /// A class representing the state of an [EagerSpanScanner]. | 115 /// A class representing the state of an [EagerSpanScanner]. |
| 105 class _EagerSpanScannerState implements LineScannerState { | 116 class _EagerSpanScannerState implements LineScannerState { |
| 106 final EagerSpanScanner _scanner; | 117 final EagerSpanScanner _scanner; |
| 107 final int position; | 118 final int position; |
| 108 final int line; | 119 final int line; |
| 109 final int column; | 120 final int column; |
| 110 | 121 |
| 111 _EagerSpanScannerState(this._scanner, this.position, this.line, this.column); | 122 _EagerSpanScannerState(this._scanner, this.position, this.line, this.column); |
| 112 } | 123 } |
| 113 | 124 |
| OLD | NEW |