Chromium Code Reviews| Index: pkg/csslib/lib/parser.dart |
| diff --git a/pkg/csslib/lib/parser.dart b/pkg/csslib/lib/parser.dart |
| index 92f16524e751c5f935ff140dd38a23798393be39..39e3fd74a68d7b4e65bae042c0004f39d8cd7ad5 100644 |
| --- a/pkg/csslib/lib/parser.dart |
| +++ b/pkg/csslib/lib/parser.dart |
| @@ -30,7 +30,7 @@ class ParserState extends TokenizerState { |
| : super(tokenizer); |
| } |
| -void _createMessages({List errors, List options}) { |
| +void _createMessages({List<Message> errors, List<String> options}) { |
| if (errors == null) errors = []; |
| if (options == null) { |
| @@ -45,8 +45,11 @@ bool get isChecked => messages.options.checked; |
| // TODO(terry): Remove nested name parameter. |
| /** Parse and analyze the CSS file. */ |
| -StyleSheet compile(var input, {List errors, List options, bool nested: true, |
| - bool polyfill: false, List<StyleSheet> includes: null}) { |
| +StyleSheet compile(var input, {List<Message> errors, List<String> options, |
| + bool nested: true, |
| + bool polyfill: false, |
| + List<StyleSheet> includes: null}) { |
| + |
| if (includes == null) { |
| includes = []; |
| } |
| @@ -70,7 +73,9 @@ StyleSheet compile(var input, {List errors, List options, bool nested: true, |
| } |
| /** Analyze the CSS file. */ |
| -void analyze(List<StyleSheet> styleSheets, {List errors, List options}) { |
| +void analyze(List<StyleSheet> styleSheets, |
| + {List<Message> errors, List<String> options}) { |
| + |
| _createMessages(errors: errors, options: options); |
| new Analyzer(styleSheets, messages).run(); |
| } |
| @@ -80,7 +85,7 @@ void analyze(List<StyleSheet> styleSheets, {List errors, List options}) { |
| * or [List<int>] of bytes and returns a [StyleSheet] AST. The optional |
| * [errors] list will contain each error/warning as a [Message]. |
| */ |
| -StyleSheet parse(var input, {List errors, List options}) { |
| +StyleSheet parse(var input, {List<Message> errors, List<String> options}) { |
| var source = _inputAsString(input); |
| _createMessages(errors: errors, options: options); |
| @@ -95,7 +100,7 @@ StyleSheet parse(var input, {List errors, List options}) { |
| * or [List<int>] of bytes and returns a [StyleSheet] AST. The optional |
| * [errors] list will contain each error/warning as a [Message]. |
| */ |
| -StyleSheet selector(var input, {List errors}) { |
| +StyleSheet selector(var input, {List<Message> errors}) { |
| var source = _inputAsString(input); |
| _createMessages(errors: errors); |
| @@ -150,7 +155,7 @@ class Parser { |
| /** A simple recursive descent parser for CSS. */ |
| class _Parser { |
| - Tokenizer tokenizer; |
| + final Tokenizer tokenizer; |
| /** Base url of CSS file. */ |
| final String _baseUrl; |
| @@ -933,7 +938,7 @@ class _Parser { |
| name = identifier(); |
| } |
| - var params = []; |
| + List<TreeNode> params = []; |
|
terry
2013/11/07 18:11:22
Should stay as var.
|
| // Any parameters? Parameters can be multiple terms per argument e.g., |
| // 3px solid yellow, green is two parameters: |
| @@ -941,7 +946,7 @@ class _Parser { |
| // 2. green |
| // the first has 3 terms and the second has 1 term. |
| if (_maybeEat(TokenKind.LPAREN)) { |
| - var terms = []; |
| + List terms = []; |
|
terry
2013/11/07 18:11:22
Should stay as var.
|
| var expr; |
| var keepGoing = true; |
| while (keepGoing && (expr = processTerm()) != null) { |
| @@ -950,12 +955,12 @@ class _Parser { |
| keepGoing = !_peekKind(TokenKind.RPAREN); |
| if (keepGoing) { |
| if (_maybeEat(TokenKind.COMMA)) { |
| - params.add(terms); |
| + params.addAll(terms); |
| terms = []; |
| } |
| } |
| } |
| - params.add(terms); |
| + params.addAll(terms); |
| _maybeEat(TokenKind.RPAREN); |
| } |
| @@ -1184,7 +1189,7 @@ class _Parser { |
| /** |
| * Return list of selectors |
| */ |
| - processSelector() { |
| + Selector processSelector() { |
| List<SimpleSelectorSequence> simpleSequences = []; |
| int start = _peekToken.start; |
| while (true) { |
| @@ -1539,7 +1544,7 @@ class _Parser { |
| // SUBSTRMATCH: '*=' |
| // |
| // |
| - processAttribute() { |
| + AttributeSelector processAttribute() { |
| int start = _peekToken.start; |
| if (_maybeEat(TokenKind.LBRACK)) { |
| @@ -1593,7 +1598,7 @@ class _Parser { |
| // *IDENT - IE7 or below |
| // _IDENT - IE6 property (automatically a valid ident) |
| // |
| - processDeclaration(List dartStyles) { |
| + Declaration processDeclaration(List dartStyles) { |
| Declaration decl; |
| int start = _peekToken.start; |
| @@ -1730,13 +1735,9 @@ class _Parser { |
| 'normal' : FontWeight.normal |
| }; |
| - static _findStyle(String styleName) { |
| - if (_stylesToDart.containsKey(styleName)) { |
| - return _stylesToDart[styleName]; |
| - } |
| - } |
| + static _findStyle(String styleName) => _stylesToDart[styleName]; |
| - _styleForDart(Identifier property, Expressions exprs, List dartStyles) { |
| + DartStyleExpression _styleForDart(Identifier property, Expressions exprs, List dartStyles) { |
| int styleType = _findStyle(property.name.toLowerCase()); |
| if (styleType != null) { |
| return buildDartStyleNode(styleType, exprs, dartStyles); |
| @@ -1754,7 +1755,9 @@ class _Parser { |
| return fontExpr; |
| } |
| - buildDartStyleNode(int styleType, Expressions exprs, List dartStyles) { |
| + DartStyleExpression buildDartStyleNode(int styleType, Expressions exprs, |
| + List dartStyles) { |
| + |
| switch (styleType) { |
| /* |
| * Properties in order: |
| @@ -1897,7 +1900,7 @@ class _Parser { |
| // TODO(terry): Look at handling width of thin, thick, etc. any none numbers |
| // to convert to a number. |
| - processOneNumber(Expressions exprs, int part) { |
| + DartStyleExpression processOneNumber(Expressions exprs, int part) { |
| var value = marginValue(exprs.expressions[0]); |
| if (value != null) { |
| switch (part) { |
| @@ -1947,7 +1950,7 @@ class _Parser { |
| * |
| * The values of the margins can be a unit or unitless or auto. |
| */ |
| - processFourNums(Expressions exprs) { |
| + BoxEdge processFourNums(Expressions exprs) { |
| num top; |
| num right; |
| num bottom; |
| @@ -2000,7 +2003,7 @@ class _Parser { |
| // operator: '/' | ',' |
| // term: (see processTerm) |
| // |
| - processExpr([bool ieFilter = false]) { |
| + Expression processExpr([bool ieFilter = false]) { |
| int start = _peekToken.start; |
| Expressions expressions = new Expressions(_makeSpan(start)); |
| @@ -2061,7 +2064,7 @@ class _Parser { |
| return expressions; |
| } |
| - static int MAX_UNICODE = int.parse('0x10FFFF'); |
| + static final int MAX_UNICODE = int.parse('0x10FFFF'); |
| // Term grammar: |
| // |
| @@ -2248,8 +2251,8 @@ class _Parser { |
| } |
| /** Process all dimension units. */ |
| - processDimension(Token t, var value, Span span) { |
| - var term; |
| + LiteralTerm processDimension(Token t, var value, Span span) { |
| + LiteralTerm term; |
| var unitType = this._peek(); |
| switch (unitType) { |
| @@ -2328,7 +2331,7 @@ class _Parser { |
| return term; |
| } |
| - processQuotedString([bool urlString = false]) { |
| + String processQuotedString([bool urlString = false]) { |
| int start = _peekToken.start; |
| // URI term sucks up everything inside of quotes(' or ") or between parens |
| @@ -2470,7 +2473,7 @@ class _Parser { |
| return null; |
| } |
| - identifier() { |
| + Identifier identifier() { |
| var tok = _next(); |
| if (!TokenKind.isIdentifier(tok.kind) && |
| @@ -2535,7 +2538,7 @@ class ExpressionsProcessor { |
| ExpressionsProcessor(this._exprs); |
| // TODO(terry): Only handles ##px unit. |
| - processFontSize() { |
| + FontExpression processFontSize() { |
| /* font-size[/line-height] |
| * |
| * Possible size values: |
| @@ -2580,7 +2583,7 @@ class ExpressionsProcessor { |
| return new FontExpression(_exprs.span, size: size, lineHeight: lineHt); |
| } |
| - processFontFamily() { |
| + FontExpression processFontFamily() { |
| final List<String> family = <String>[]; |
| /* Possible family values: |
| @@ -2609,7 +2612,7 @@ class ExpressionsProcessor { |
| return new FontExpression(_exprs.span, family: family); |
| } |
| - processFont() { |
| + FontExpression processFont() { |
| var family; |
| // Process all parts of the font expression. |