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

Unified Diff: pkg/csslib/lib/parser.dart

Issue 60983003: pkg/csslib: fixed analysis error, more cleanup (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: nits Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/csslib/lib/src/analyzer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/csslib/lib/parser.dart
diff --git a/pkg/csslib/lib/parser.dart b/pkg/csslib/lib/parser.dart
index 92f16524e751c5f935ff140dd38a23798393be39..840b9f23998e72395f335368ebe735b73bdf2656 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;
@@ -1184,9 +1189,9 @@ class _Parser {
/**
* Return list of selectors
*/
- processSelector() {
- List<SimpleSelectorSequence> simpleSequences = [];
- int start = _peekToken.start;
+ Selector processSelector() {
+ var simpleSequences = <SimpleSelectorSequence>[];
+ var start = _peekToken.start;
while (true) {
// First item is never descendant make sure it's COMBINATOR_NONE.
var selectorItem = simpleSelectorSequence(simpleSequences.length == 0);
@@ -1344,12 +1349,12 @@ class _Parser {
*/
simpleSelectorTail() {
// Check for HASH | class | attrib | pseudo | negation
- int start = _peekToken.start;
+ var start = _peekToken.start;
switch (_peek()) {
case TokenKind.HASH:
_eat(TokenKind.HASH);
- bool hasWhiteSpace = false;
+ var hasWhiteSpace = false;
if (_anyWhiteSpaceBeforePeekToken(TokenKind.HASH)) {
_warning("Not a valid ID selector expected #id", _makeSpan(start));
hasWhiteSpace = true;
@@ -1395,7 +1400,7 @@ class _Parser {
// :pseudo-class ::pseudo-element
// TODO(terry): '::' should be token.
_eat(TokenKind.COLON);
- bool pseudoElement = _maybeEat(TokenKind.COLON);
+ var pseudoElement = _maybeEat(TokenKind.COLON);
// TODO(terry): If no identifier specified consider optimizing out the
// : or :: and making this a normal selector. For now,
@@ -1456,7 +1461,7 @@ class _Parser {
* NUMBER {num}
*/
processSelectorExpression() {
- int start = _peekToken.start;
+ var start = _peekToken.start;
var expression = new SelectorExpression(_makeSpan(start));
@@ -1467,7 +1472,7 @@ class _Parser {
// operator not identifier.
tokenizer.selectorExpression = true;
- bool keepParsing = true;
+ var keepParsing = true;
while (keepParsing) {
switch (_peek()) {
case TokenKind.PLUS:
@@ -1539,8 +1544,8 @@ class _Parser {
// SUBSTRMATCH: '*='
//
//
- processAttribute() {
- int start = _peekToken.start;
+ AttributeSelector processAttribute() {
+ var start = _peekToken.start;
if (_maybeEat(TokenKind.LBRACK)) {
var attrName = identifier();
@@ -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;
@@ -1637,7 +1642,7 @@ class _Parser {
var include = processInclude(span, eatSemiColon: false);
decl = new IncludeMixinAtDeclaration(include, span);
} else if (_peekToken.kind == TokenKind.DIRECTIVE_EXTEND) {
- List<SimpleSelectorSequence> simpleSequences = [];
+ var simpleSequences = <TreeNode>[];
_next();
var span = _makeSpan(start);
@@ -1730,14 +1735,11 @@ class _Parser {
'normal' : FontWeight.normal
};
- static _findStyle(String styleName) {
- if (_stylesToDart.containsKey(styleName)) {
- return _stylesToDart[styleName];
- }
- }
+ static int _findStyle(String styleName) => _stylesToDart[styleName];
- _styleForDart(Identifier property, Expressions exprs, List dartStyles) {
- int styleType = _findStyle(property.name.toLowerCase());
+ DartStyleExpression _styleForDart(Identifier property, Expressions exprs,
+ List dartStyles) {
+ var styleType = _findStyle(property.name.toLowerCase());
if (styleType != null) {
return buildDartStyleNode(styleType, exprs, dartStyles);
}
@@ -1754,7 +1756,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 +1901,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 +1951,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,16 +2004,16 @@ class _Parser {
// operator: '/' | ','
// term: (see processTerm)
//
- processExpr([bool ieFilter = false]) {
- int start = _peekToken.start;
- Expressions expressions = new Expressions(_makeSpan(start));
+ Expressions processExpr([bool ieFilter = false]) {
+ var start = _peekToken.start;
+ var expressions = new Expressions(_makeSpan(start));
- bool keepGoing = true;
+ var keepGoing = true;
var expr;
while (keepGoing && (expr = processTerm(ieFilter)) != null) {
var op;
- int opStart = _peekToken.start;
+ var opStart = _peekToken.start;
switch (_peek()) {
case TokenKind.SLASH:
@@ -2061,7 +2065,7 @@ class _Parser {
return expressions;
}
- static int MAX_UNICODE = int.parse('0x10FFFF');
+ static final int MAX_UNICODE = int.parse('0x10FFFF');
// Term grammar:
//
@@ -2085,7 +2089,7 @@ class _Parser {
// function: IDENT '(' expr ')'
//
processTerm([bool ieFilter = false]) {
- int start = _peekToken.start;
+ var start = _peekToken.start;
Token t; // token for term's value
var value; // value of term (numeric values)
@@ -2193,8 +2197,8 @@ class _Parser {
}
// Yes, process the color as an RGB value.
- String rgbColor = TokenKind.decimalToHex(
- TokenKind.colorValue(colorEntry), 6);
+ var rgbColor =
+ TokenKind.decimalToHex(TokenKind.colorValue(colorEntry), 6);
return _parseHex(rgbColor, _makeSpan(start));
case TokenKind.UNICODE_RANGE:
var first;
@@ -2248,8 +2252,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,11 +2332,11 @@ class _Parser {
return term;
}
- processQuotedString([bool urlString = false]) {
- int start = _peekToken.start;
+ String processQuotedString([bool urlString = false]) {
+ var start = _peekToken.start;
// URI term sucks up everything inside of quotes(' or ") or between parens
- int stopToken = urlString ? TokenKind.RPAREN : -1;
+ var stopToken = urlString ? TokenKind.RPAREN : -1;
switch (_peek()) {
case TokenKind.SINGLE_QUOTE:
stopToken = TokenKind.SINGLE_QUOTE;
@@ -2358,13 +2362,13 @@ class _Parser {
}
// Gobble up everything until we hit our stop token.
- int runningStart = _peekToken.start;
+ var runningStart = _peekToken.start;
while (_peek() != stopToken && _peek() != TokenKind.END_OF_FILE) {
var tok = _next();
}
// All characters between quotes is the string.
- int end = _peekToken.end;
+ var end = _peekToken.end;
var stringValue = (_peekToken.span as FileSpan).file.getText(start,
end - 1);
@@ -2386,7 +2390,7 @@ class _Parser {
* then parse to the right paren ignoring everything in between.
*/
processIEFilter(int startAfterProgidColon) {
- int parens = 0;
+ var parens = 0;
while (_peek() != TokenKind.END_OF_FILE) {
switch (_peek()) {
@@ -2413,14 +2417,14 @@ class _Parser {
// function: IDENT '(' expr ')'
//
processFunction(Identifier func) {
- int start = _peekToken.start;
+ var start = _peekToken.start;
- String name = func.name;
+ var name = func.name;
switch (name) {
case 'url':
// URI term sucks up everything inside of quotes(' or ") or between parens
- String urlParam = processQuotedString(true);
+ var urlParam = processQuotedString(true);
// TODO(terry): Better error messge and checking for mismatched quotes.
if (_peek() == TokenKind.END_OF_FILE) {
@@ -2470,7 +2474,7 @@ class _Parser {
return null;
}
- identifier() {
+ Identifier identifier() {
var tok = _next();
if (!TokenKind.isIdentifier(tok.kind) &&
@@ -2486,7 +2490,7 @@ class _Parser {
// TODO(terry): Move this to base <= 36 and into shared code.
static int _hexDigit(int c) {
- if(c >= 48/*0*/ && c <= 57/*9*/) {
+ if (c >= 48/*0*/ && c <= 57/*9*/) {
return c - 48;
} else if (c >= 97/*a*/ && c <= 102/*f*/) {
return c - 87;
@@ -2498,9 +2502,9 @@ class _Parser {
}
HexColorTerm _parseHex(String hexText, Span span) {
- int hexValue = 0;
+ var hexValue = 0;
- for (int i = 0; i < hexText.length; i++) {
+ for (var i = 0; i < hexText.length; i++) {
var digit = _hexDigit(hexText.codeUnitAt(i));
if (digit < 0) {
_warning('Bad hex number', span);
@@ -2535,7 +2539,7 @@ class ExpressionsProcessor {
ExpressionsProcessor(this._exprs);
// TODO(terry): Only handles ##px unit.
- processFontSize() {
+ FontExpression processFontSize() {
/* font-size[/line-height]
*
* Possible size values:
@@ -2553,7 +2557,7 @@ class ExpressionsProcessor {
*/
LengthTerm size;
LineHeight lineHt;
- bool nextIsLineHeight = false;
+ var nextIsLineHeight = false;
for (; _index < _exprs.expressions.length; _index++) {
var expr = _exprs.expressions[_index];
if (size == null && expr is LengthTerm) {
@@ -2580,14 +2584,14 @@ class ExpressionsProcessor {
return new FontExpression(_exprs.span, size: size, lineHeight: lineHt);
}
- processFontFamily() {
- final List<String> family = <String>[];
+ FontExpression processFontFamily() {
+ var family = <String>[];
/* Possible family values:
* font-family: arial, Times new roman ,Lucida Sans Unicode,Courier;
* font-family: "Times New Roman", arial, Lucida Sans Unicode, Courier;
*/
- bool moreFamilies = false;
+ var moreFamilies = false;
for (; _index < _exprs.expressions.length; _index++) {
Expression expr = _exprs.expressions[_index];
@@ -2609,8 +2613,8 @@ class ExpressionsProcessor {
return new FontExpression(_exprs.span, family: family);
}
- processFont() {
- var family;
+ FontExpression processFont() {
+ List<String> family;
// Process all parts of the font expression.
FontExpression fontSize;
@@ -2645,8 +2649,8 @@ String _escapeString(String text, {bool single: false}) {
StringBuffer result = null;
for (int i = 0; i < text.length; i++) {
- int code = text.codeUnitAt(i);
- var replace = null;
+ var code = text.codeUnitAt(i);
+ String replace = null;
switch (code) {
case 34/*'"'*/: if (!single) replace = r'\"'; break;
case 39/*"'"*/: if (single) replace = r"\'"; break;
« no previous file with comments | « no previous file | pkg/csslib/lib/src/analyzer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698