Skip to content
This repository was archived by the owner on Jul 15, 2019. It is now read-only.

Commit 4c0fc00

Browse files
committed
update the numeric lexical definition of css3.0
1 parent 593a95f commit 4c0fc00

File tree

4 files changed

+33
-20
lines changed

4 files changed

+33
-20
lines changed

src/css-parser.3.js

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/l/css.21.l

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ ident \-?{nmstart}{nmchar}* /* escaped - */
3636
vendor [\-_]{h}"-"{h}
3737
name {nmchar}+
3838
num [0-9]+(\.[0-9]+)?|"."[0-9]+ /* num [0-9]+|[0-9]*"."[0-9]+ */
39-
// num [0-9]+(\.[0-9]+)?([eE][+\-][0-9])?|"."[0-9]+([eE][+\-][0-9])?
4039
string {string1}|{string2}
4140
badstring {badstring1}|{badstring2}
4241
badcomment {badcomment1}|{badcomment2}

src/l/css.3.l

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ comment \/\*[^*]*\*+([^/*][^*]*\*+)*\/
3636
ident \-?{nmstart}{nmchar}* /* escaped - */
3737
vendor [\-_]{h}"-"{h}
3838
name {nmchar}+
39-
/* TODO: the <number-token> pattern has been changed in CSS 3.0 */
40-
num [0-9]+(\.[0-9]+)?|"."[0-9]+ /* num [0-9]+|[0-9]*"."[0-9]+ */
39+
num [0-9]+(\.[0-9]+)?([eE][+\-][0-9])?|"."[0-9]+([eE][+\-][0-9])?
4140
string {string1}|{string2}
4241
badstring {badstring1}|{badstring2}
4342
badcomment {badcomment1}|{badcomment2}
@@ -112,6 +111,10 @@ Z "Z"|"z"|\\"0"{0,4}("5a"|"7a")(\r\n|[ \t\r\n\f])?|\\[z]
112111
113112
"#"{name} {return 'HASH';}
114113
114+
// this is very tricky, as we support DIMENSION in the term production
115+
// it takes precedence before all other numeric definition.
116+
{num}{ident} {return 'DIMENSION';}
117+
115118
{num}{E}{M} {return 'EMS';}
116119
{num}{E}{X} {return 'EXS';}
117120
{num}{P}{X} {return 'LENGTH';}
@@ -127,7 +130,6 @@ Z "Z"|"z"|\\"0"{0,4}("5a"|"7a")(\r\n|[ \t\r\n\f])?|\\[z]
127130
{num}{S} {return 'TIME';}
128131
{num}{H}{Z} {return 'FREQ';}
129132
{num}{K}{H}{Z} {return 'FREQ';}
130-
{num}{ident} {return 'DIMENSION';}
131133
132134
{num}"%" {return 'PERCENTAGE';}
133135
{num} {return 'NUMBER';}

tests/test-patterns.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,6 @@ var css21TestPatterns = [
117117
result: { rulesets: [ { selector: 'e', declaration: [ { key: 'border', value: "1.0" } ] } ] } },
118118
{ css: "e { border: .3; }",
119119
result: { rulesets: [ { selector: 'e', declaration: [ { key: 'border', value: ".3" } ] } ] } },
120-
/* TODO: need to support scientific notation
121-
{ css: "e { border: 1e+1; }",
122-
result: { rulesets: [ { selector: 'e', declaration: [ { key: 'border', value: "1e+1" } ] } ] } },
123-
*/
124120
{ css: "e { border: +1; }",
125121
result: { rulesets: [ { selector: 'e', declaration: [ { key: 'border', value: "+1" } ] } ] } },
126122
{ css: "e { border: -1; }",
@@ -271,10 +267,6 @@ var css21TestPatterns = [
271267
result: { rulesets: [ { selector: 'e', declaration: [ { key: '-moz-opacity', value: '0.6' },
272268
{ key: '-khtml-opacity', value: '0.6' },
273269
{ key: 'opacity', value: '0.6' } ] } ] } },
274-
/*
275-
{ css: "e { border: 1-ident; }",
276-
result: { rulesets: [ { selector: 'e', declaration: [ { key: 'border', value: '1 -ident' } ] } ] } },
277-
*/
278270
];
279271
exports.css21TestPatterns = css21TestPatterns;
280272

@@ -295,12 +287,15 @@ var css21InvalidTestPatterns = [
295287
{ css: "element: ident { color: red; text-align: center; }" }, /* no space between element_name and ident */
296288

297289
{ css: "e { border: 1ident; }" },
290+
{ css: "e { border: 1-ident; }" },
298291
{ css: "e { color: function(); }" }, /* function must have expr as argument */
299292

300293
/* {escape} \\[^\r\n\f0-9a-fA-F] */
301294
{ css: "\\\r { color: red; text-align: center; }" },
302295
{ css: "\\\n { color: red; text-align: center; }" },
303296
{ css: "\\\f { color: red; text-align: center; }" },
297+
298+
{ css: "e { border: 1e+1; }" },
304299
];
305300
exports.css21InvalidTestPatterns = css21InvalidTestPatterns;
306301

@@ -532,6 +527,23 @@ var css3TestPatterns = [
532527
] } ] } ] } },
533528
*/
534529

530+
{ css: "e { border: 1; }",
531+
result: { rulesets: [ { selector: 'e', declaration: [ { key: 'border', value: "1" } ] } ] } },
532+
{ css: "e { border: 1.0; }",
533+
result: { rulesets: [ { selector: 'e', declaration: [ { key: 'border', value: "1.0" } ] } ] } },
534+
{ css: "e { border: .3; }",
535+
result: { rulesets: [ { selector: 'e', declaration: [ { key: 'border', value: ".3" } ] } ] } },
536+
{ css: "e { border: +1; }",
537+
result: { rulesets: [ { selector: 'e', declaration: [ { key: 'border', value: "+1" } ] } ] } },
538+
{ css: "e { border: -1; }",
539+
result: { rulesets: [ { selector: 'e', declaration: [ { key: 'border', value: "-1" } ] } ] } },
540+
{ css: "e { border: 1ident; }",
541+
result: { rulesets: [ { selector: 'e', declaration: [ { key: 'border', value: '1ident' } ] } ] } },
542+
/* TODO: bug?
543+
{ css: "e { border: 1-ident; }",
544+
result: { rulesets: [ { selector: 'e', declaration: [ { key: 'border', value: '1-ident' } ] } ] } },
545+
*/
546+
535547
{ css: "@media screen { p { font-family: verdana, sans-serif; font-size: 17px; } }",
536548
result: { medias: { mediaqueries: [ { prefix: '', media_type: 'screen', expression: '' } ], rulesets: [ { "selector": "p", "declaration": [ { key: "font-family", value: "verdana ,sans-serif" }, { key: "font-size", value: "17px" } ] } ] }, } },
537549
{ css: "@media screen, tv { p { font-family: verdana, sans-serif; font-size: 17px; } }",

0 commit comments

Comments
 (0)