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 csslib.parser; | 5 library csslib.parser; |
6 | 6 |
7 import 'dart:math' as math; | 7 import 'dart:math' as math; |
8 | 8 |
9 import 'package:source_span/source_span.dart'; | 9 import 'package:source_span/source_span.dart'; |
10 | 10 |
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 | 805 |
806 var start = _peekToken.span; | 806 var start = _peekToken.span; |
807 while (!_maybeEat(TokenKind.END_OF_FILE)) { | 807 while (!_maybeEat(TokenKind.END_OF_FILE)) { |
808 var directive = processDirective(); | 808 var directive = processDirective(); |
809 if (directive != null) { | 809 if (directive != null) { |
810 productions.add(directive); | 810 productions.add(directive); |
811 continue; | 811 continue; |
812 } | 812 } |
813 | 813 |
814 var declGroup = processDeclarations(checkBrace: false); | 814 var declGroup = processDeclarations(checkBrace: false); |
815 var decls = []; | |
816 if (declGroup.declarations.any((decl) { | 815 if (declGroup.declarations.any((decl) { |
817 return decl is Declaration && decl is! IncludeMixinAtDeclaration; | 816 return decl is Declaration && decl is! IncludeMixinAtDeclaration; |
818 })) { | 817 })) { |
819 var newDecls = []; | 818 var newDecls = []; |
820 productions.forEach((include) { | 819 productions.forEach((include) { |
821 // If declGroup has items that are declarations then we assume | 820 // If declGroup has items that are declarations then we assume |
822 // this mixin is a declaration mixin not a top-level mixin. | 821 // this mixin is a declaration mixin not a top-level mixin. |
823 if (include is IncludeDirective) { | 822 if (include is IncludeDirective) { |
824 newDecls.add(new IncludeMixinAtDeclaration(include, include.span)); | 823 newDecls.add(new IncludeMixinAtDeclaration(include, include.span)); |
825 } else { | 824 } else { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 * return the token id of a directive or -1 if neither. | 873 * return the token id of a directive or -1 if neither. |
875 */ | 874 */ |
876 processVariableOrDirective({bool mixinParameter: false}) { | 875 processVariableOrDirective({bool mixinParameter: false}) { |
877 var start = _peekToken.span; | 876 var start = _peekToken.span; |
878 | 877 |
879 var tokId = _peek(); | 878 var tokId = _peek(); |
880 // Handle case for @ directive (where there's a whitespace between the @ | 879 // Handle case for @ directive (where there's a whitespace between the @ |
881 // sign and the directive name. Technically, it's not valid grammar but | 880 // sign and the directive name. Technically, it's not valid grammar but |
882 // a number of CSS tests test for whitespace between @ and name. | 881 // a number of CSS tests test for whitespace between @ and name. |
883 if (tokId == TokenKind.AT) { | 882 if (tokId == TokenKind.AT) { |
884 Token tok = _next(); | 883 _next(); |
885 tokId = _peek(); | 884 tokId = _peek(); |
886 if (_peekIdentifier()) { | 885 if (_peekIdentifier()) { |
887 // Is it a directive? | 886 // Is it a directive? |
888 var directive = _peekToken.text; | 887 var directive = _peekToken.text; |
889 var directiveLen = directive.length; | 888 var directiveLen = directive.length; |
890 tokId = TokenKind.matchDirectives(directive, 0, directiveLen); | 889 tokId = TokenKind.matchDirectives(directive, 0, directiveLen); |
891 if (tokId == -1) { | 890 if (tokId == -1) { |
892 tokId = TokenKind.matchMarginDirectives(directive, 0, directiveLen); | 891 tokId = TokenKind.matchMarginDirectives(directive, 0, directiveLen); |
893 } | 892 } |
894 } | 893 } |
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1840 return _mergeFontStyles(fontExpr, dartStyles); | 1839 return _mergeFontStyles(fontExpr, dartStyles); |
1841 } else if (expr is LiteralTerm) { | 1840 } else if (expr is LiteralTerm) { |
1842 int weight = _nameToFontWeight[expr.value.toString()]; | 1841 int weight = _nameToFontWeight[expr.value.toString()]; |
1843 if (weight != null) { | 1842 if (weight != null) { |
1844 var fontExpr = new FontExpression(expr.span, weight: weight); | 1843 var fontExpr = new FontExpression(expr.span, weight: weight); |
1845 return _mergeFontStyles(fontExpr, dartStyles); | 1844 return _mergeFontStyles(fontExpr, dartStyles); |
1846 } | 1845 } |
1847 } | 1846 } |
1848 break; | 1847 break; |
1849 case _lineHeightPart: | 1848 case _lineHeightPart: |
1850 num lineHeight; | |
1851 if (exprs.expressions.length == 1) { | 1849 if (exprs.expressions.length == 1) { |
1852 var expr = exprs.expressions[0]; | 1850 var expr = exprs.expressions[0]; |
1853 if (expr is UnitTerm) { | 1851 if (expr is UnitTerm) { |
1854 UnitTerm unitTerm = expr; | 1852 UnitTerm unitTerm = expr; |
1855 // TODO(terry): Need to handle other units and LiteralTerm normal | 1853 // TODO(terry): Need to handle other units and LiteralTerm normal |
1856 // See https://github.com/dart-lang/csslib/issues/2. | 1854 // See https://github.com/dart-lang/csslib/issues/2. |
1857 if (unitTerm.unit == TokenKind.UNIT_LENGTH_PX || | 1855 if (unitTerm.unit == TokenKind.UNIT_LENGTH_PX || |
1858 unitTerm.unit == TokenKind.UNIT_LENGTH_PT) { | 1856 unitTerm.unit == TokenKind.UNIT_LENGTH_PT) { |
1859 var fontExpr = new FontExpression(expr.span, | 1857 var fontExpr = new FontExpression(expr.span, |
1860 lineHeight: new LineHeight(expr.value, inPixels: true)); | 1858 lineHeight: new LineHeight(expr.value, inPixels: true)); |
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2638 moreFamilies = true; | 2636 moreFamilies = true; |
2639 } else { | 2637 } else { |
2640 break; | 2638 break; |
2641 } | 2639 } |
2642 } | 2640 } |
2643 | 2641 |
2644 return new FontExpression(_exprs.span, family: family); | 2642 return new FontExpression(_exprs.span, family: family); |
2645 } | 2643 } |
2646 | 2644 |
2647 FontExpression processFont() { | 2645 FontExpression processFont() { |
2648 List<String> family; | |
2649 | |
2650 // Process all parts of the font expression. | 2646 // Process all parts of the font expression. |
2651 FontExpression fontSize; | 2647 FontExpression fontSize; |
2652 FontExpression fontFamily; | 2648 FontExpression fontFamily; |
2653 for (; _index < _exprs.expressions.length; _index++) { | 2649 for (; _index < _exprs.expressions.length; _index++) { |
2654 var expr = _exprs.expressions[_index]; | |
2655 // Order is font-size font-family | 2650 // Order is font-size font-family |
2656 if (fontSize == null) { | 2651 if (fontSize == null) { |
2657 fontSize = processFontSize(); | 2652 fontSize = processFontSize(); |
2658 } | 2653 } |
2659 if (fontFamily == null) { | 2654 if (fontFamily == null) { |
2660 fontFamily = processFontFamily(); | 2655 fontFamily = processFontFamily(); |
2661 } | 2656 } |
2662 //TODO(terry): Handle font-weight, font-style, and font-variant. See | 2657 //TODO(terry): Handle font-weight, font-style, and font-variant. See |
2663 // https://github.com/dart-lang/csslib/issues/3 | 2658 // https://github.com/dart-lang/csslib/issues/3 |
2664 // https://github.com/dart-lang/csslib/issues/4 | 2659 // https://github.com/dart-lang/csslib/issues/4 |
(...skipping 28 matching lines...) Expand all Loading... |
2693 | 2688 |
2694 if (replace != null && result == null) { | 2689 if (replace != null && result == null) { |
2695 result = new StringBuffer(text.substring(0, i)); | 2690 result = new StringBuffer(text.substring(0, i)); |
2696 } | 2691 } |
2697 | 2692 |
2698 if (result != null) result.write(replace != null ? replace : text[i]); | 2693 if (result != null) result.write(replace != null ? replace : text[i]); |
2699 } | 2694 } |
2700 | 2695 |
2701 return result == null ? text : result.toString(); | 2696 return result == null ? text : result.toString(); |
2702 } | 2697 } |
OLD | NEW |