| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 licenset hat can be found in the LICENSE file. | 3 // BSD-style licenset hat can be found in the LICENSE file. |
| 4 | 4 |
| 5 library fasta.scanner.recover; | 5 library fasta.scanner.recover; |
| 6 | 6 |
| 7 import '../../scanner/token.dart' show TokenType; | 7 import '../../scanner/token.dart' show TokenType; |
| 8 | 8 |
| 9 import '../fasta_codes.dart' | 9 import '../fasta_codes.dart' |
| 10 show | 10 show |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 if (current is ErrorToken) { | 160 if (current is ErrorToken) { |
| 161 ErrorToken first = current; | 161 ErrorToken first = current; |
| 162 Token next = current; | 162 Token next = current; |
| 163 bool treatAsWhitespace = false; | 163 bool treatAsWhitespace = false; |
| 164 do { | 164 do { |
| 165 current = next; | 165 current = next; |
| 166 if (errorTail == null) { | 166 if (errorTail == null) { |
| 167 error = next; | 167 error = next; |
| 168 } else { | 168 } else { |
| 169 errorTail.next = next; | 169 errorTail.next = next; |
| 170 next.previousToken = errorTail; | 170 next.previous = errorTail; |
| 171 } | 171 } |
| 172 errorTail = next; | 172 errorTail = next; |
| 173 next = next.next; | 173 next = next.next; |
| 174 } while (next is ErrorToken && first.errorCode == next.errorCode); | 174 } while (next is ErrorToken && first.errorCode == next.errorCode); |
| 175 | 175 |
| 176 FastaCode code = first.errorCode; | 176 FastaCode code = first.errorCode; |
| 177 if (code == codeEncoding || | 177 if (code == codeEncoding || |
| 178 code == codeNonAsciiWhitespace || | 178 code == codeNonAsciiWhitespace || |
| 179 code == codeAsciiControlCharacter) { | 179 code == codeAsciiControlCharacter) { |
| 180 treatAsWhitespace = true; | 180 treatAsWhitespace = true; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 201 assert(current.next != null); | 201 assert(current.next != null); |
| 202 } else { | 202 } else { |
| 203 treatAsWhitespace = true; | 203 treatAsWhitespace = true; |
| 204 } | 204 } |
| 205 if (treatAsWhitespace) continue; | 205 if (treatAsWhitespace) continue; |
| 206 } | 206 } |
| 207 if (goodTail == null) { | 207 if (goodTail == null) { |
| 208 good = current; | 208 good = current; |
| 209 } else { | 209 } else { |
| 210 goodTail.next = current; | 210 goodTail.next = current; |
| 211 current.previousToken = goodTail; | 211 current.previous = goodTail; |
| 212 } | 212 } |
| 213 beforeGoodTail = goodTail; | 213 beforeGoodTail = goodTail; |
| 214 goodTail = current; | 214 goodTail = current; |
| 215 } | 215 } |
| 216 | 216 |
| 217 error.previousToken = new SymbolToken.eof(-1)..next = error; | 217 error.previous = new SymbolToken.eof(-1)..next = error; |
| 218 Token tail; | 218 Token tail; |
| 219 if (good != null) { | 219 if (good != null) { |
| 220 errorTail.next = good; | 220 errorTail.next = good; |
| 221 good.previousToken = errorTail; | 221 good.previous = errorTail; |
| 222 tail = goodTail; | 222 tail = goodTail; |
| 223 } else { | 223 } else { |
| 224 tail = errorTail; | 224 tail = errorTail; |
| 225 } | 225 } |
| 226 if (!tail.isEof) | 226 if (!tail.isEof) tail.next = new SymbolToken.eof(tail.end)..previous = tail; |
| 227 tail.next = new SymbolToken.eof(tail.end)..previousToken = tail; | |
| 228 return error; | 227 return error; |
| 229 } | 228 } |
| 230 | 229 |
| 231 Token synthesizeToken(int charOffset, String value, TokenType type) { | 230 Token synthesizeToken(int charOffset, String value, TokenType type) { |
| 232 return new StringToken.fromString(type, value, charOffset); | 231 return new StringToken.fromString(type, value, charOffset); |
| 233 } | 232 } |
| 234 | 233 |
| 235 Token skipToEof(Token token) { | 234 Token skipToEof(Token token) { |
| 236 while (!token.isEof) { | 235 while (!token.isEof) { |
| 237 token = token.next; | 236 token = token.next; |
| 238 } | 237 } |
| 239 return token; | 238 return token; |
| 240 } | 239 } |
| 241 | 240 |
| 242 String closeBraceFor(String openBrace) { | 241 String closeBraceFor(String openBrace) { |
| 243 return const { | 242 return const { |
| 244 '(': ')', | 243 '(': ')', |
| 245 '[': ']', | 244 '[': ']', |
| 246 '{': '}', | 245 '{': '}', |
| 247 '<': '>', | 246 '<': '>', |
| 248 r'${': '}', | 247 r'${': '}', |
| 249 }[openBrace]; | 248 }[openBrace]; |
| 250 } | 249 } |
| OLD | NEW |