Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: utils/css/tokenkind.dart

Issue 9695048: Template parser (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Siggi's comments Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils/css/tokenizer_base.dart ('k') | utils/css/tool.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 // TODO(terry): Need to be consistent with tokens either they're ASCII tokens 5 // TODO(terry): Need to be consistent with tokens either they're ASCII tokens
6 // e.g., ASTERISK or they're CSS e.g., PSEUDO, COMBINATOR_*. 6 // e.g., ASTERISK or they're CSS e.g., PSEUDO, COMBINATOR_*.
7 class TokenKind { 7 class TokenKind {
8 // Common shared tokens used in TokenizerBase. 8 // Common shared tokens used in TokenizerBase.
9 static final int UNUSED = 0; // Unused place holder... 9 static final int UNUSED = 0; // Unused place holder...
10 static final int END_OF_FILE = 1; // TODO(terry): Must match base 10 static final int END_OF_FILE = 1; // TODO(terry): Must match base
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 /* 375 /*
376 * Return the token that matches the unit ident found. 376 * Return the token that matches the unit ident found.
377 */ 377 */
378 static int matchList(var identList, String tokenField, String text, 378 static int matchList(var identList, String tokenField, String text,
379 int offset, int length) { 379 int offset, int length) {
380 for (final entry in identList) { 380 for (final entry in identList) {
381 String ident = entry['value']; 381 String ident = entry['value'];
382 if (length == ident.length) { 382 if (length == ident.length) {
383 int idx = offset; 383 int idx = offset;
384 bool match = true; 384 bool match = true;
385 for (final identIdx = 0; identIdx < ident.length; identIdx++) { 385 for (int identIdx = 0; identIdx < ident.length; identIdx++) {
386 int identChar = ident.charCodeAt(identIdx); 386 int identChar = ident.charCodeAt(identIdx);
387 int char = text.charCodeAt(idx++); 387 int char = text.charCodeAt(idx++);
388 // Compare lowercase to lowercase then check if char is uppercase. 388 // Compare lowercase to lowercase then check if char is uppercase.
389 match = match && (char == identChar || 389 match = match && (char == identChar ||
390 ((char >= ASCII_UPPER_A && char <= ASCII_UPPER_Z) && 390 ((char >= ASCII_UPPER_A && char <= ASCII_UPPER_Z) &&
391 (char + 32) == identChar)); 391 (char + 32) == identChar));
392 if (!match) { 392 if (!match) {
393 break; 393 break;
394 } 394 }
395 } 395 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 * Match color name, case insensitive match and return the associated RGB 440 * Match color name, case insensitive match and return the associated RGB
441 * value as decimal number. 441 * value as decimal number.
442 */ 442 */
443 static int matchColorName(String text) { 443 static int matchColorName(String text) {
444 int length = text.length; 444 int length = text.length;
445 for (final entry in _EXTENDED_COLOR_NAMES) { 445 for (final entry in _EXTENDED_COLOR_NAMES) {
446 String ident = entry['name']; 446 String ident = entry['name'];
447 if (length == ident.length) { 447 if (length == ident.length) {
448 int idx = 0; 448 int idx = 0;
449 bool match = true; 449 bool match = true;
450 for (final identIdx = 0; identIdx < ident.length; identIdx++) { 450 for (int identIdx = 0; identIdx < ident.length; identIdx++) {
451 int identChar = ident.charCodeAt(identIdx); 451 int identChar = ident.charCodeAt(identIdx);
452 int char = text.charCodeAt(idx++); 452 int char = text.charCodeAt(idx++);
453 // Compare lowercase to lowercase then check if char is uppercase. 453 // Compare lowercase to lowercase then check if char is uppercase.
454 match = match && (char == identChar || 454 match = match && (char == identChar ||
455 ((char >= ASCII_UPPER_A && char <= ASCII_UPPER_Z) && 455 ((char >= ASCII_UPPER_A && char <= ASCII_UPPER_Z) &&
456 (char + 32) == identChar)); 456 (char + 32) == identChar));
457 if (!match) { 457 if (!match) {
458 break; 458 break;
459 } 459 }
460 } 460 }
(...skipping 17 matching lines...) Expand all
478 int dividend = num >> 4; 478 int dividend = num >> 4;
479 int remain = num % 16; 479 int remain = num % 16;
480 result.add(_HEX_DIGITS[remain]); 480 result.add(_HEX_DIGITS[remain]);
481 while (dividend != 0) { 481 while (dividend != 0) {
482 remain = dividend % 16; 482 remain = dividend % 16;
483 dividend >>= 4; 483 dividend >>= 4;
484 result.add(_HEX_DIGITS[remain]); 484 result.add(_HEX_DIGITS[remain]);
485 } 485 }
486 486
487 StringBuffer invertResult = new StringBuffer(); 487 StringBuffer invertResult = new StringBuffer();
488 for (final idx = result.length - 1; idx >= 0; idx--) { 488 for (int idx = result.length - 1; idx >= 0; idx--) {
489 invertResult.add(result[idx]); 489 invertResult.add(result[idx]);
490 } 490 }
491 return invertResult.toString(); 491 return invertResult.toString();
492 } 492 }
493 493
494 static String kindToString(int kind) { 494 static String kindToString(int kind) {
495 switch(kind) { 495 switch(kind) {
496 case TokenKind.UNUSED: return "ERROR"; 496 case TokenKind.UNUSED: return "ERROR";
497 case TokenKind.END_OF_FILE: return "end of file"; 497 case TokenKind.END_OF_FILE: return "end of file";
498 case TokenKind.LPAREN: return "("; 498 case TokenKind.LPAREN: return "(";
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 } 582 }
583 583
584 } 584 }
585 585
586 class NoColorMatchException implements Exception { 586 class NoColorMatchException implements Exception {
587 String _colorName; 587 String _colorName;
588 NoColorMatchException(this._colorName); 588 NoColorMatchException(this._colorName);
589 589
590 String get name() => _colorName; 590 String get name() => _colorName;
591 } 591 }
OLDNEW
« no previous file with comments | « utils/css/tokenizer_base.dart ('k') | utils/css/tool.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698