| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 fasta.scanner.abstract_scanner; | 5 library fasta.scanner.abstract_scanner; |
| 6 | 6 |
| 7 import '../scanner.dart' show | 7 import '../scanner.dart' show |
| 8 ErrorToken, | 8 ErrorToken, |
| 9 Scanner, | 9 Scanner, |
| 10 buildUnexpectedCharacterToken; | 10 buildUnexpectedCharacterToken; |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 next = advance(); | 224 next = advance(); |
| 225 // Sequences of spaces are common, so advance through them fast. | 225 // Sequences of spaces are common, so advance through them fast. |
| 226 while (identical(next, $SPACE)) { | 226 while (identical(next, $SPACE)) { |
| 227 // We don't invoke [:appendWhiteSpace(next):] here for efficiency, | 227 // We don't invoke [:appendWhiteSpace(next):] here for efficiency, |
| 228 // assuming that it does not do anything for space characters. | 228 // assuming that it does not do anything for space characters. |
| 229 next = advance(); | 229 next = advance(); |
| 230 } | 230 } |
| 231 return next; | 231 return next; |
| 232 } | 232 } |
| 233 | 233 |
| 234 if ($a <= next && next <= $z) { | 234 int nextLower = next | 0x20; |
| 235 |
| 236 if ($a <= nextLower && nextLower <= $z) { |
| 235 if (identical($r, next)) { | 237 if (identical($r, next)) { |
| 236 return tokenizeRawStringKeywordOrIdentifier(next); | 238 return tokenizeRawStringKeywordOrIdentifier(next); |
| 237 } | 239 } |
| 238 return tokenizeKeywordOrIdentifier(next, true); | 240 return tokenizeKeywordOrIdentifier(next, true); |
| 239 } | 241 } |
| 240 | 242 |
| 241 if (($A <= next && next <= $Z) || | 243 if (identical(next, $CLOSE_PAREN)) { |
| 242 identical(next, $_) || | 244 return appendEndGroup(CLOSE_PAREN_INFO, OPEN_PAREN_TOKEN); |
| 243 identical(next, $$)) { | 245 } |
| 246 |
| 247 if (identical(next, $OPEN_PAREN)) { |
| 248 appendBeginGroup(OPEN_PAREN_INFO); |
| 249 return advance(); |
| 250 } |
| 251 |
| 252 if (identical(next, $SEMICOLON)) { |
| 253 appendPrecedenceToken(SEMICOLON_INFO); |
| 254 // Type parameters and arguments cannot contain semicolon. |
| 255 discardOpenLt(); |
| 256 return advance(); |
| 257 } |
| 258 |
| 259 if (identical(next, $PERIOD)) { |
| 260 return tokenizeDotsOrNumber(next); |
| 261 } |
| 262 |
| 263 if (identical(next, $COMMA)) { |
| 264 appendPrecedenceToken(COMMA_INFO); |
| 265 return advance(); |
| 266 } |
| 267 |
| 268 if (identical(next, $EQ)) { |
| 269 return tokenizeEquals(next); |
| 270 } |
| 271 |
| 272 if (identical(next, $CLOSE_CURLY_BRACKET)) { |
| 273 return appendEndGroup(CLOSE_CURLY_BRACKET_INFO, OPEN_CURLY_BRACKET_TOKEN); |
| 274 } |
| 275 |
| 276 if (identical(next, $SLASH)) { |
| 277 return tokenizeSlashOrComment(next); |
| 278 } |
| 279 |
| 280 |
| 281 if (identical(next, $OPEN_CURLY_BRACKET)) { |
| 282 appendBeginGroup(OPEN_CURLY_BRACKET_INFO); |
| 283 return advance(); |
| 284 } |
| 285 |
| 286 if (identical(next, $DQ) || identical(next, $SQ)) { |
| 287 return tokenizeString(next, scanOffset, false); |
| 288 } |
| 289 |
| 290 if(identical(next, $_)){ |
| 244 return tokenizeKeywordOrIdentifier(next, true); | 291 return tokenizeKeywordOrIdentifier(next, true); |
| 245 } | 292 } |
| 246 | 293 |
| 294 if (identical(next, $COLON)) { |
| 295 appendPrecedenceToken(COLON_INFO); |
| 296 return advance(); |
| 297 } |
| 298 |
| 247 if (identical(next, $LT)) { | 299 if (identical(next, $LT)) { |
| 248 return tokenizeLessThan(next); | 300 return tokenizeLessThan(next); |
| 249 } | 301 } |
| 250 | 302 |
| 251 if (identical(next, $GT)) { | 303 if (identical(next, $GT)) { |
| 252 return tokenizeGreaterThan(next); | 304 return tokenizeGreaterThan(next); |
| 253 } | 305 } |
| 254 | 306 |
| 255 if (identical(next, $EQ)) { | |
| 256 return tokenizeEquals(next); | |
| 257 } | |
| 258 | |
| 259 if (identical(next, $BANG)) { | 307 if (identical(next, $BANG)) { |
| 260 return tokenizeExclamation(next); | 308 return tokenizeExclamation(next); |
| 261 } | 309 } |
| 262 | 310 |
| 311 if (identical(next, $OPEN_SQUARE_BRACKET)) { |
| 312 return tokenizeOpenSquareBracket(next); |
| 313 } |
| 314 |
| 315 if (identical(next, $CLOSE_SQUARE_BRACKET)) { |
| 316 return appendEndGroup( |
| 317 CLOSE_SQUARE_BRACKET_INFO, OPEN_SQUARE_BRACKET_TOKEN); |
| 318 } |
| 319 |
| 320 if (identical(next, $AT)) { |
| 321 return tokenizeAt(next); |
| 322 } |
| 323 |
| 324 if (next >= $1 && next <= $9) { |
| 325 return tokenizeNumber(next); |
| 326 } |
| 327 |
| 328 if (identical(next, $AMPERSAND)) { |
| 329 return tokenizeAmpersand(next); |
| 330 } |
| 331 |
| 332 if (identical(next, $0)) { |
| 333 return tokenizeHexOrNumber(next); |
| 334 } |
| 335 |
| 336 if (identical(next, $QUESTION)) { |
| 337 return tokenizeQuestion(next); |
| 338 } |
| 339 |
| 340 if (identical(next, $BAR)) { |
| 341 return tokenizeBar(next); |
| 342 } |
| 343 |
| 263 if (identical(next, $PLUS)) { | 344 if (identical(next, $PLUS)) { |
| 264 return tokenizePlus(next); | 345 return tokenizePlus(next); |
| 265 } | 346 } |
| 266 | 347 |
| 348 if(identical(next, $$)){ |
| 349 return tokenizeKeywordOrIdentifier(next, true); |
| 350 } |
| 351 |
| 267 if (identical(next, $MINUS)) { | 352 if (identical(next, $MINUS)) { |
| 268 return tokenizeMinus(next); | 353 return tokenizeMinus(next); |
| 269 } | 354 } |
| 270 | 355 |
| 271 if (identical(next, $STAR)) { | 356 if (identical(next, $STAR)) { |
| 272 return tokenizeMultiply(next); | 357 return tokenizeMultiply(next); |
| 273 } | 358 } |
| 274 | 359 |
| 360 if (identical(next, $CARET)) { |
| 361 return tokenizeCaret(next); |
| 362 } |
| 363 |
| 364 if (identical(next, $TILDE)) { |
| 365 return tokenizeTilde(next); |
| 366 } |
| 367 |
| 275 if (identical(next, $PERCENT)) { | 368 if (identical(next, $PERCENT)) { |
| 276 return tokenizePercent(next); | 369 return tokenizePercent(next); |
| 277 } | 370 } |
| 278 | 371 |
| 279 if (identical(next, $AMPERSAND)) { | 372 if (identical(next, $BACKPING)) { |
| 280 return tokenizeAmpersand(next); | 373 appendPrecedenceToken(BACKPING_INFO); |
| 281 } | 374 return advance(); |
| 282 | |
| 283 if (identical(next, $BAR)) { | |
| 284 return tokenizeBar(next); | |
| 285 } | |
| 286 | |
| 287 if (identical(next, $CARET)) { | |
| 288 return tokenizeCaret(next); | |
| 289 } | |
| 290 | |
| 291 if (identical(next, $OPEN_SQUARE_BRACKET)) { | |
| 292 return tokenizeOpenSquareBracket(next); | |
| 293 } | |
| 294 | |
| 295 if (identical(next, $TILDE)) { | |
| 296 return tokenizeTilde(next); | |
| 297 } | 375 } |
| 298 | 376 |
| 299 if (identical(next, $BACKSLASH)) { | 377 if (identical(next, $BACKSLASH)) { |
| 300 appendPrecedenceToken(BACKSLASH_INFO); | 378 appendPrecedenceToken(BACKSLASH_INFO); |
| 301 return advance(); | 379 return advance(); |
| 302 } | 380 } |
| 303 | 381 |
| 304 if (identical(next, $HASH)) { | 382 if (identical(next, $HASH)) { |
| 305 return tokenizeTag(next); | 383 return tokenizeTag(next); |
| 306 } | 384 } |
| 307 | 385 |
| 308 if (identical(next, $OPEN_PAREN)) { | |
| 309 appendBeginGroup(OPEN_PAREN_INFO); | |
| 310 return advance(); | |
| 311 } | |
| 312 | |
| 313 if (identical(next, $CLOSE_PAREN)) { | |
| 314 return appendEndGroup(CLOSE_PAREN_INFO, OPEN_PAREN_TOKEN); | |
| 315 } | |
| 316 | |
| 317 if (identical(next, $COMMA)) { | |
| 318 appendPrecedenceToken(COMMA_INFO); | |
| 319 return advance(); | |
| 320 } | |
| 321 | |
| 322 if (identical(next, $COLON)) { | |
| 323 appendPrecedenceToken(COLON_INFO); | |
| 324 return advance(); | |
| 325 } | |
| 326 | |
| 327 if (identical(next, $SEMICOLON)) { | |
| 328 appendPrecedenceToken(SEMICOLON_INFO); | |
| 329 // Type parameters and arguments cannot contain semicolon. | |
| 330 discardOpenLt(); | |
| 331 return advance(); | |
| 332 } | |
| 333 | |
| 334 if (identical(next, $QUESTION)) { | |
| 335 return tokenizeQuestion(next); | |
| 336 } | |
| 337 | |
| 338 if (identical(next, $CLOSE_SQUARE_BRACKET)) { | |
| 339 return appendEndGroup( | |
| 340 CLOSE_SQUARE_BRACKET_INFO, OPEN_SQUARE_BRACKET_TOKEN); | |
| 341 } | |
| 342 | |
| 343 if (identical(next, $BACKPING)) { | |
| 344 appendPrecedenceToken(BACKPING_INFO); | |
| 345 return advance(); | |
| 346 } | |
| 347 | |
| 348 if (identical(next, $OPEN_CURLY_BRACKET)) { | |
| 349 appendBeginGroup(OPEN_CURLY_BRACKET_INFO); | |
| 350 return advance(); | |
| 351 } | |
| 352 | |
| 353 if (identical(next, $CLOSE_CURLY_BRACKET)) { | |
| 354 return appendEndGroup(CLOSE_CURLY_BRACKET_INFO, OPEN_CURLY_BRACKET_TOKEN); | |
| 355 } | |
| 356 | |
| 357 if (identical(next, $SLASH)) { | |
| 358 return tokenizeSlashOrComment(next); | |
| 359 } | |
| 360 | |
| 361 if (identical(next, $AT)) { | |
| 362 return tokenizeAt(next); | |
| 363 } | |
| 364 | |
| 365 if (identical(next, $DQ) || identical(next, $SQ)) { | |
| 366 return tokenizeString(next, scanOffset, false); | |
| 367 } | |
| 368 | |
| 369 if (identical(next, $PERIOD)) { | |
| 370 return tokenizeDotsOrNumber(next); | |
| 371 } | |
| 372 | |
| 373 if (identical(next, $0)) { | |
| 374 return tokenizeHexOrNumber(next); | |
| 375 } | |
| 376 | |
| 377 // TODO(ahe): Would a range check be faster? | |
| 378 if (identical(next, $1) || | |
| 379 identical(next, $2) || | |
| 380 identical(next, $3) || | |
| 381 identical(next, $4) || | |
| 382 identical(next, $5) || | |
| 383 identical(next, $6) || | |
| 384 identical(next, $7) || | |
| 385 identical(next, $8) || | |
| 386 identical(next, $9)) { | |
| 387 return tokenizeNumber(next); | |
| 388 } | |
| 389 | |
| 390 if (identical(next, $EOF)) { | |
| 391 return $EOF; | |
| 392 } | |
| 393 if (next < 0x1f) { | 386 if (next < 0x1f) { |
| 394 return unexpected(next); | 387 return unexpected(next); |
| 395 } | 388 } |
| 396 | 389 |
| 397 next = currentAsUnicode(next); | 390 next = currentAsUnicode(next); |
| 398 | 391 |
| 399 return unexpected(next); | 392 return unexpected(next); |
| 400 } | 393 } |
| 401 | 394 |
| 402 int tokenizeTag(int next) { | 395 int tokenizeTag(int next) { |
| (...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1167 | 1160 |
| 1168 PrecedenceInfo closeBraceInfoFor(BeginGroupToken begin) { | 1161 PrecedenceInfo closeBraceInfoFor(BeginGroupToken begin) { |
| 1169 return const { | 1162 return const { |
| 1170 '(': CLOSE_PAREN_INFO, | 1163 '(': CLOSE_PAREN_INFO, |
| 1171 '[': CLOSE_SQUARE_BRACKET_INFO, | 1164 '[': CLOSE_SQUARE_BRACKET_INFO, |
| 1172 '{': CLOSE_CURLY_BRACKET_INFO, | 1165 '{': CLOSE_CURLY_BRACKET_INFO, |
| 1173 '<': GT_INFO, | 1166 '<': GT_INFO, |
| 1174 r'${': CLOSE_CURLY_BRACKET_INFO, | 1167 r'${': CLOSE_CURLY_BRACKET_INFO, |
| 1175 }[begin.value]; | 1168 }[begin.value]; |
| 1176 } | 1169 } |
| OLD | NEW |