Skip to content

Commit 0ae63a5

Browse files
author
Nicholas C. Zakas
committed
Updated parser (fixes #49)
1 parent bd2ac62 commit 0ae63a5

File tree

10 files changed

+83
-138
lines changed

10 files changed

+83
-138
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Next (not yet released)
22

3+
* Updated parser (fixes #49)
34
* Added rule for compatible vendor prefixes (pull #78)
45
* Added rule for duplicate properties (fixes #51)
56
* Updated error message for display:inline used with float (fixes #16)

build/csslint-node.js

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
THE SOFTWARE.
2222
2323
*/
24-
/* Build time: 5-July-2011 02:38:28 */
24+
/* Build time: 5-July-2011 03:16:53 */
2525
/*!
2626
Parser-Lib
2727
Copyright (c) 2009-2011 Nicholas C. Zakas. All rights reserved.
@@ -45,7 +45,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
4545
THE SOFTWARE.
4646
4747
*/
48-
/* Build time: 28-June-2011 09:12:00 */
48+
/* Build time: 5-July-2011 03:12:40 */
4949
var parserlib = {};
5050
(function(){
5151

@@ -910,7 +910,6 @@ TokenStreamBase.prototype = {
910910
};
911911

912912

913-
914913
parserlib.util = {
915914
StringReader: StringReader,
916915
SyntaxError : SyntaxError,
@@ -919,7 +918,6 @@ EventTarget : EventTarget,
919918
TokenStreamBase : TokenStreamBase
920919
};
921920
})();
922-
923921
/*
924922
Parser-Lib
925923
Copyright (c) 2009-2011 Nicholas C. Zakas. All rights reserved.
@@ -943,7 +941,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
943941
THE SOFTWARE.
944942
945943
*/
946-
/* Build time: 28-June-2011 09:12:00 */
944+
/* Build time: 5-July-2011 03:12:40 */
947945
(function(){
948946
var EventTarget = parserlib.util.EventTarget,
949947
TokenStreamBase = parserlib.util.TokenStreamBase,
@@ -1131,7 +1129,6 @@ Combinator.prototype = new SyntaxUnit();
11311129
Combinator.prototype.constructor = Combinator;
11321130

11331131

1134-
11351132
var Level1Properties = {
11361133

11371134
"background": 1,
@@ -1338,7 +1335,6 @@ function MediaFeature(name, value){
13381335
MediaFeature.prototype = new SyntaxUnit();
13391336
MediaFeature.prototype.constructor = MediaFeature;
13401337

1341-
13421338
/**
13431339
* Represents an individual media query.
13441340
* @namespace parserlib.css
@@ -1381,7 +1377,6 @@ function MediaQuery(modifier, mediaType, features, line, col){
13811377
MediaQuery.prototype = new SyntaxUnit();
13821378
MediaQuery.prototype.constructor = MediaQuery;
13831379

1384-
13851380
/**
13861381
* A CSS3 parser.
13871382
* @namespace parserlib.css
@@ -1679,7 +1674,13 @@ Parser.prototype = function(){
16791674
col: col
16801675
});
16811676

1682-
while(this._ruleset()){}
1677+
while(true) {
1678+
if (tokenStream.peek() == Tokens.PAGE_SYM){
1679+
this._page();
1680+
} else if (!this._ruleset()){
1681+
break;
1682+
}
1683+
}
16831684

16841685
tokenStream.mustMatch(Tokens.RBRACE);
16851686
this._readWhitespace();
@@ -1706,7 +1707,7 @@ Parser.prototype = function(){
17061707

17071708
this._readWhitespace();
17081709

1709-
if (tokenStream.peek() == Tokens.IDENT){
1710+
if (tokenStream.peek() == Tokens.IDENT || tokenStream.peek() == Tokens.LPAREN){
17101711
mediaList.push(this._media_query());
17111712
}
17121713

@@ -3338,7 +3339,6 @@ function PropertyName(text, hack, line, col){
33383339
PropertyName.prototype = new SyntaxUnit();
33393340
PropertyName.prototype.constructor = PropertyName;
33403341

3341-
33423342
/**
33433343
* Represents a single part of a CSS property value, meaning that it represents
33443344
* just everything single part between ":" and ";". If there are multiple values
@@ -3367,7 +3367,6 @@ function PropertyValue(parts, line, col){
33673367
PropertyValue.prototype = new SyntaxUnit();
33683368
PropertyValue.prototype.constructor = PropertyValue;
33693369

3370-
33713370
/**
33723371
* Represents a single part of a CSS property value, meaning that it represents
33733372
* just one part of the data between ":" and ";".
@@ -3539,7 +3538,6 @@ function Selector(parts, line, col){
35393538
Selector.prototype = new SyntaxUnit();
35403539
Selector.prototype.constructor = Selector;
35413540

3542-
35433541
/**
35443542
* Represents a single part of a selector string, meaning a single set of
35453543
* element name and modifiers. This does not include combinators such as
@@ -3581,7 +3579,6 @@ function SelectorPart(elementName, modifiers, text, line, col){
35813579
SelectorPart.prototype = new SyntaxUnit();
35823580
SelectorPart.prototype.constructor = SelectorPart;
35833581

3584-
35853582
/**
35863583
* Represents a selector modifier string, meaning a class name, element name,
35873584
* element ID, pseudo rule, etc.
@@ -3618,7 +3615,6 @@ SelectorSubPart.prototype = new SyntaxUnit();
36183615
SelectorSubPart.prototype.constructor = SelectorSubPart;
36193616

36203617

3621-
36223618

36233619
var h = /^[0-9a-fA-F]$/,
36243620
nonascii = /^[\u0080-\uFFFF]$/,
@@ -4261,11 +4257,7 @@ TokenStream.prototype = mix(new TokenStreamBase(), {
42614257
ident = this.readName(reader.read());
42624258
value += ident;
42634259

4264-
if (/em/i.test(ident)){
4265-
tt = Tokens.EMS;
4266-
} else if (/ex/i.test(ident)){
4267-
tt = Tokens.EXS;
4268-
} else if (/px|cm|mm|in|pt|pc/i.test(ident)){
4260+
if (/em|ex|px|gd|rem|vw|vh|vm|ch|cm|mm|in|pt|pc/i.test(ident)){
42694261
tt = Tokens.LENGTH;
42704262
} else if (/deg|rad|grad/i.test(ident)){
42714263
tt = Tokens.ANGLE;
@@ -4595,7 +4587,6 @@ TokenStream.prototype = mix(new TokenStreamBase(), {
45954587

45964588
});
45974589

4598-
45994590
var Tokens = [
46004591

46014592
/*
@@ -4796,7 +4787,6 @@ var Tokens = [
47964787

47974788

47984789

4799-
48004790
parserlib.css = {
48014791
Colors :Colors,
48024792
Combinator :Combinator,
@@ -4813,7 +4803,6 @@ TokenStream :TokenStream,
48134803
Tokens :Tokens
48144804
};
48154805
})();
4816-
48174806
/**
48184807
* YUI Test Framework
48194808
* @module yuitest

build/csslint-rhino.js

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
THE SOFTWARE.
2222
2323
*/
24-
/* Build time: 5-July-2011 02:38:28 */
24+
/* Build time: 5-July-2011 03:16:53 */
2525
var CSSLint = (function(){
2626
/*!
2727
Parser-Lib
@@ -46,7 +46,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
4646
THE SOFTWARE.
4747
4848
*/
49-
/* Build time: 28-June-2011 09:12:00 */
49+
/* Build time: 5-July-2011 03:12:40 */
5050
var parserlib = {};
5151
(function(){
5252

@@ -911,7 +911,6 @@ TokenStreamBase.prototype = {
911911
};
912912

913913

914-
915914
parserlib.util = {
916915
StringReader: StringReader,
917916
SyntaxError : SyntaxError,
@@ -920,7 +919,6 @@ EventTarget : EventTarget,
920919
TokenStreamBase : TokenStreamBase
921920
};
922921
})();
923-
924922
/*
925923
Parser-Lib
926924
Copyright (c) 2009-2011 Nicholas C. Zakas. All rights reserved.
@@ -944,7 +942,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
944942
THE SOFTWARE.
945943
946944
*/
947-
/* Build time: 28-June-2011 09:12:00 */
945+
/* Build time: 5-July-2011 03:12:40 */
948946
(function(){
949947
var EventTarget = parserlib.util.EventTarget,
950948
TokenStreamBase = parserlib.util.TokenStreamBase,
@@ -1132,7 +1130,6 @@ Combinator.prototype = new SyntaxUnit();
11321130
Combinator.prototype.constructor = Combinator;
11331131

11341132

1135-
11361133
var Level1Properties = {
11371134

11381135
"background": 1,
@@ -1339,7 +1336,6 @@ function MediaFeature(name, value){
13391336
MediaFeature.prototype = new SyntaxUnit();
13401337
MediaFeature.prototype.constructor = MediaFeature;
13411338

1342-
13431339
/**
13441340
* Represents an individual media query.
13451341
* @namespace parserlib.css
@@ -1382,7 +1378,6 @@ function MediaQuery(modifier, mediaType, features, line, col){
13821378
MediaQuery.prototype = new SyntaxUnit();
13831379
MediaQuery.prototype.constructor = MediaQuery;
13841380

1385-
13861381
/**
13871382
* A CSS3 parser.
13881383
* @namespace parserlib.css
@@ -1680,7 +1675,13 @@ Parser.prototype = function(){
16801675
col: col
16811676
});
16821677

1683-
while(this._ruleset()){}
1678+
while(true) {
1679+
if (tokenStream.peek() == Tokens.PAGE_SYM){
1680+
this._page();
1681+
} else if (!this._ruleset()){
1682+
break;
1683+
}
1684+
}
16841685

16851686
tokenStream.mustMatch(Tokens.RBRACE);
16861687
this._readWhitespace();
@@ -1707,7 +1708,7 @@ Parser.prototype = function(){
17071708

17081709
this._readWhitespace();
17091710

1710-
if (tokenStream.peek() == Tokens.IDENT){
1711+
if (tokenStream.peek() == Tokens.IDENT || tokenStream.peek() == Tokens.LPAREN){
17111712
mediaList.push(this._media_query());
17121713
}
17131714

@@ -3339,7 +3340,6 @@ function PropertyName(text, hack, line, col){
33393340
PropertyName.prototype = new SyntaxUnit();
33403341
PropertyName.prototype.constructor = PropertyName;
33413342

3342-
33433343
/**
33443344
* Represents a single part of a CSS property value, meaning that it represents
33453345
* just everything single part between ":" and ";". If there are multiple values
@@ -3368,7 +3368,6 @@ function PropertyValue(parts, line, col){
33683368
PropertyValue.prototype = new SyntaxUnit();
33693369
PropertyValue.prototype.constructor = PropertyValue;
33703370

3371-
33723371
/**
33733372
* Represents a single part of a CSS property value, meaning that it represents
33743373
* just one part of the data between ":" and ";".
@@ -3540,7 +3539,6 @@ function Selector(parts, line, col){
35403539
Selector.prototype = new SyntaxUnit();
35413540
Selector.prototype.constructor = Selector;
35423541

3543-
35443542
/**
35453543
* Represents a single part of a selector string, meaning a single set of
35463544
* element name and modifiers. This does not include combinators such as
@@ -3582,7 +3580,6 @@ function SelectorPart(elementName, modifiers, text, line, col){
35823580
SelectorPart.prototype = new SyntaxUnit();
35833581
SelectorPart.prototype.constructor = SelectorPart;
35843582

3585-
35863583
/**
35873584
* Represents a selector modifier string, meaning a class name, element name,
35883585
* element ID, pseudo rule, etc.
@@ -3619,7 +3616,6 @@ SelectorSubPart.prototype = new SyntaxUnit();
36193616
SelectorSubPart.prototype.constructor = SelectorSubPart;
36203617

36213618

3622-
36233619

36243620
var h = /^[0-9a-fA-F]$/,
36253621
nonascii = /^[\u0080-\uFFFF]$/,
@@ -4262,11 +4258,7 @@ TokenStream.prototype = mix(new TokenStreamBase(), {
42624258
ident = this.readName(reader.read());
42634259
value += ident;
42644260

4265-
if (/em/i.test(ident)){
4266-
tt = Tokens.EMS;
4267-
} else if (/ex/i.test(ident)){
4268-
tt = Tokens.EXS;
4269-
} else if (/px|cm|mm|in|pt|pc/i.test(ident)){
4261+
if (/em|ex|px|gd|rem|vw|vh|vm|ch|cm|mm|in|pt|pc/i.test(ident)){
42704262
tt = Tokens.LENGTH;
42714263
} else if (/deg|rad|grad/i.test(ident)){
42724264
tt = Tokens.ANGLE;
@@ -4596,7 +4588,6 @@ TokenStream.prototype = mix(new TokenStreamBase(), {
45964588

45974589
});
45984590

4599-
46004591
var Tokens = [
46014592

46024593
/*
@@ -4797,7 +4788,6 @@ var Tokens = [
47974788

47984789

47994790

4800-
48014791
parserlib.css = {
48024792
Colors :Colors,
48034793
Combinator :Combinator,
@@ -4814,7 +4804,6 @@ TokenStream :TokenStream,
48144804
Tokens :Tokens
48154805
};
48164806
})();
4817-
48184807
/**
48194808
* YUI Test Framework
48204809
* @module yuitest

build/csslint-tests.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
"Adjoining classes should not cause an error": function(){
1111
var result = CSSLint.verify(".foo.bar{}", { });
1212
Assert.areEqual(0, result.messages.length);
13+
},
14+
15+
"@media (max-width:400px) should not cause an error": function(){
16+
var result = CSSLint.verify("@media (max-width:400px) {}", { });
17+
Assert.areEqual(0, result.messages.length);
1318
}
1419

1520
}));

0 commit comments

Comments
 (0)