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

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

Issue 10010009: Calculator App for ChromeOS with fixes for templates/CSS to support this application. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Mininimal templates and more text node tests. Created 8 years, 8 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
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 3
4 /** 4 /**
5 * A simple recursive descent parser for CSS. 5 * A simple recursive descent parser for CSS.
6 */ 6 */
7 class Parser { 7 class Parser {
8 Tokenizer tokenizer; 8 Tokenizer tokenizer;
9 9
10 var _fs; // If non-null filesystem to read files. 10 var _fs; // If non-null filesystem to read files.
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 case TokenKind.HASH: 561 case TokenKind.HASH:
562 _eat(TokenKind.HASH); 562 _eat(TokenKind.HASH);
563 return new IdSelector(identifier(), _makeSpan(start)); 563 return new IdSelector(identifier(), _makeSpan(start));
564 case TokenKind.DOT: 564 case TokenKind.DOT:
565 _eat(TokenKind.DOT); 565 _eat(TokenKind.DOT);
566 return new ClassSelector(identifier(), _makeSpan(start)); 566 return new ClassSelector(identifier(), _makeSpan(start));
567 case TokenKind.COLON: 567 case TokenKind.COLON:
568 // :pseudo-class ::pseudo-element 568 // :pseudo-class ::pseudo-element
569 // TODO(terry): '::' should be token. 569 // TODO(terry): '::' should be token.
570 _eat(TokenKind.COLON); 570 _eat(TokenKind.COLON);
571 bool pseudoClass = _peek() != TokenKind.COLON; 571 bool pseudoElement = _maybeEat(TokenKind.COLON);
572 var name = identifier(); 572 var name = identifier();
573 // TODO(terry): Need to handle specific pseudo class/element name and 573 // TODO(terry): Need to handle specific pseudo class/element name and
574 // backward compatible names that are : as well as :: as well as 574 // backward compatible names that are : as well as :: as well as
575 // parameters. 575 // parameters.
576 return pseudoClass ? 576 return pseudoElement ?
577 new PseudoClassSelector(name, _makeSpan(start)) : 577 new PseudoElementSelector(name, _makeSpan(start)) :
578 new PseudoElementSelector(name, _makeSpan(start)); 578 new PseudoClassSelector(name, _makeSpan(start));
579 case TokenKind.LBRACK: 579 case TokenKind.LBRACK:
580 return processAttribute(); 580 return processAttribute();
581 } 581 }
582 } 582 }
583 583
584 // Attribute grammar: 584 // Attribute grammar:
585 // 585 //
586 // attributes : 586 // attributes :
587 // '[' S* IDENT S* [ ATTRIB_MATCHES S* [ IDENT | STRING ] S* ]? ']' 587 // '[' S* IDENT S* [ ATTRIB_MATCHES S* [ IDENT | STRING ] S* ]? ']'
588 // 588 //
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 if (nameValue.name == 'from') { 810 if (nameValue.name == 'from') {
811 return new LiteralTerm(nameValue, nameValue.name, _makeSpan(start)); 811 return new LiteralTerm(nameValue, nameValue.name, _makeSpan(start));
812 } 812 }
813 813
814 // What kind of identifier is it? 814 // What kind of identifier is it?
815 try { 815 try {
816 // Named color? 816 // Named color?
817 int colorValue = TokenKind.matchColorName(nameValue.name); 817 int colorValue = TokenKind.matchColorName(nameValue.name);
818 818
819 // Yes, process the color as an RGB value. 819 // Yes, process the color as an RGB value.
820 String rgbColor = TokenKind.decimalToHex(colorValue); 820 String rgbColor = TokenKind.decimalToHex(colorValue, 3);
821 try { 821 try {
822 colorValue = parseHex(rgbColor); 822 colorValue = parseHex(rgbColor);
823 } catch (HexNumberException hne) { 823 } catch (HexNumberException hne) {
824 _error('Bad hex number', _makeSpan(start)); 824 _error('Bad hex number', _makeSpan(start));
825 } 825 }
826 return new HexColorTerm(colorValue, rgbColor, _makeSpan(start)); 826 return new HexColorTerm(colorValue, rgbColor, _makeSpan(start));
827 } catch (final error) { 827 } catch (final error) {
828 if (error is NoColorMatchException) { 828 if (error is NoColorMatchException) {
829 // TODO(terry): Other named things to match with validator? 829 // TODO(terry): Other named things to match with validator?
830 830
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 1008
1009 return result; 1009 return result;
1010 } 1010 }
1011 } 1011 }
1012 1012
1013 /** Not a hex number. */ 1013 /** Not a hex number. */
1014 class HexNumberException implements Exception { 1014 class HexNumberException implements Exception {
1015 HexNumberException(); 1015 HexNumberException();
1016 } 1016 }
1017 1017
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698