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

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

Issue 9168008: Enabled CSS tests, added CSS tests to buildbot, fixed tooling with nodejs, and added more tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: More coding convention changes (consistency). Created 8 years, 11 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/parser.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 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 'info' : const {'params' : 1, 'expr' : false}}, 370 'info' : const {'params' : 1, 'expr' : false}},
371 ]; 371 ];
372 372
373 List<int> tokens; 373 List<int> tokens;
374 374
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 (var 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 (var identIdx = 0; identIdx < ident.length; identIdx++) { 385 for (final 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 22 matching lines...) Expand all
418 return matchList(_DIRECTIVES, 'type', text, offset, length); 418 return matchList(_DIRECTIVES, 'type', text, offset, length);
419 } 419 }
420 420
421 /* 421 /*
422 * Return the unit token as its pretty name. 422 * Return the unit token as its pretty name.
423 */ 423 */
424 static String unitToString(int unitTokenToFind) { 424 static String unitToString(int unitTokenToFind) {
425 if (unitTokenToFind == TokenKind.PERCENT) { 425 if (unitTokenToFind == TokenKind.PERCENT) {
426 return '%'; 426 return '%';
427 } else { 427 } else {
428 for (var entry in _UNITS) { 428 for (final entry in _UNITS) {
429 int unit = entry['unit']; 429 int unit = entry['unit'];
430 if (unit == unitTokenToFind) { 430 if (unit == unitTokenToFind) {
431 return entry['value']; 431 return entry['value'];
432 } 432 }
433 } 433 }
434 } 434 }
435 435
436 return '<BAD UNIT>'; // Not a unit token. 436 return '<BAD UNIT>'; // Not a unit token.
437 } 437 }
438 438
439 /* 439 /*
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 (var 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 (var identIdx = 0; identIdx < ident.length; identIdx++) { 450 for (final 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 (var idx = result.length - 1; idx >= 0; idx--) { 488 for (final 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/parser.dart ('k') | utils/css/tool.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698