Skip to content

Commit ab76ec2

Browse files
committed
accept decimal fractions without a leading zero
1 parent d267901 commit ab76ec2

File tree

2 files changed

+36
-35
lines changed

2 files changed

+36
-35
lines changed

parser.jison

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,44 @@
33
/* lexical grammar */
44
%lex
55
%%
6-
\s+ /* skip whitespace */
7-
"*" return 'MUL';
8-
"/" return 'DIV';
9-
"+" return 'ADD';
10-
"-" return 'SUB';
6+
\s+ /* skip whitespace */
7+
"*" return 'MUL';
8+
"/" return 'DIV';
9+
"+" return 'ADD';
10+
"-" return 'SUB';
1111

12-
[0-9]+("."[0-9]+)?px\b return 'LENGTH';
13-
[0-9]+("."[0-9]+)?cm\b return 'LENGTH';
14-
[0-9]+("."[0-9]+)?mm\b return 'LENGTH';
15-
[0-9]+("."[0-9]+)?in\b return 'LENGTH';
16-
[0-9]+("."[0-9]+)?pt\b return 'LENGTH';
17-
[0-9]+("."[0-9]+)?pc\b return 'LENGTH';
18-
[0-9]+("."[0-9]+)?deg\b return 'ANGLE';
19-
[0-9]+("."[0-9]+)?grad\b return 'ANGLE';
20-
[0-9]+("."[0-9]+)?rad\b return 'ANGLE';
21-
[0-9]+("."[0-9]+)?turn\b return 'ANGLE';
22-
[0-9]+("."[0-9]+)?s\b return 'TIME';
23-
[0-9]+("."[0-9]+)?ms\b return 'TIME';
24-
[0-9]+("."[0-9]+)?Hz\b return 'FREQ';
25-
[0-9]+("."[0-9]+)?kHz\b return 'FREQ';
26-
[0-9]+("."[0-9]+)?dpi\b return 'RES';
27-
[0-9]+("."[0-9]+)?dpcm\b return 'RES';
28-
[0-9]+("."[0-9]+)?dppx\b return 'RES';
29-
[0-9]+("."[0-9]+)?em\b return 'EMS';
30-
[0-9]+("."[0-9]+)?ex\b return 'EXS';
31-
[0-9]+("."[0-9]+)?ch\b return 'CHS';
32-
[0-9]+("."[0-9]+)?rem\b return 'REMS';
33-
[0-9]+("."[0-9]+)?vw\b return 'VWS';
34-
[0-9]+("."[0-9]+)?vh\b return 'VHS';
35-
[0-9]+("."[0-9]+)?vmin\b return 'VMINS';
36-
[0-9]+("."[0-9]+)?vmax\b return 'VMAXS';
37-
[0-9]+("."[0-9]+)?\% return 'PERCENTAGE';
38-
[0-9]+("."[0-9]+)?\b return 'NUMBER';
12+
([0-9]+("."[0-9]+)?|"."[0-9]+)px\b return 'LENGTH';
13+
([0-9]+("."[0-9]+)?|"."[0-9]+)cm\b return 'LENGTH';
14+
([0-9]+("."[0-9]+)?|"."[0-9]+)mm\b return 'LENGTH';
15+
([0-9]+("."[0-9]+)?|"."[0-9]+)in\b return 'LENGTH';
16+
([0-9]+("."[0-9]+)?|"."[0-9]+)pt\b return 'LENGTH';
17+
([0-9]+("."[0-9]+)?|"."[0-9]+)pc\b return 'LENGTH';
18+
([0-9]+("."[0-9]+)?|"."[0-9]+)deg\b return 'ANGLE';
19+
([0-9]+("."[0-9]+)?|"."[0-9]+)grad\b return 'ANGLE';
20+
([0-9]+("."[0-9]+)?|"."[0-9]+)rad\b return 'ANGLE';
21+
([0-9]+("."[0-9]+)?|"."[0-9]+)turn\b return 'ANGLE';
22+
([0-9]+("."[0-9]+)?|"."[0-9]+)s\b return 'TIME';
23+
([0-9]+("."[0-9]+)?|"."[0-9]+)ms\b return 'TIME';
24+
([0-9]+("."[0-9]+)?|"."[0-9]+)Hz\b return 'FREQ';
25+
([0-9]+("."[0-9]+)?|"."[0-9]+)kHz\b return 'FREQ';
26+
([0-9]+("."[0-9]+)?|"."[0-9]+)dpi\b return 'RES';
27+
([0-9]+("."[0-9]+)?|"."[0-9]+)dpcm\b return 'RES';
28+
([0-9]+("."[0-9]+)?|"."[0-9]+)dppx\b return 'RES';
29+
([0-9]+("."[0-9]+)?|"."[0-9]+)em\b return 'EMS';
30+
([0-9]+("."[0-9]+)?|"."[0-9]+)ex\b return 'EXS';
31+
([0-9]+("."[0-9]+)?|"."[0-9]+)ch\b return 'CHS';
32+
([0-9]+("."[0-9]+)?|"."[0-9]+)rem\b return 'REMS';
33+
([0-9]+("."[0-9]+)?|"."[0-9]+)vw\b return 'VWS';
34+
([0-9]+("."[0-9]+)?|"."[0-9]+)vh\b return 'VHS';
35+
([0-9]+("."[0-9]+)?|"."[0-9]+)vmin\b return 'VMINS';
36+
([0-9]+("."[0-9]+)?|"."[0-9]+)vmax\b return 'VMAXS';
37+
([0-9]+("."[0-9]+)?|"."[0-9]+)\% return 'PERCENTAGE';
38+
([0-9]+("."[0-9]+)?|"."[0-9]+)\b return 'NUMBER';
3939

40-
"(" return 'LPAREN';
41-
")" return 'RPAREN';
40+
"(" return 'LPAREN';
41+
")" return 'RPAREN';
4242

43-
<<EOF>> return 'EOF';
43+
<<EOF>> return 'EOF';
4444

4545
/lex
4646

src/tests/test.es6

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ test('div[data-size="calc(3*3)"]{}', 'div[data-size="9"]{}', { selectors: true})
3535
test('div:nth-child(2n + calc(3*3)){}', 'div:nth-child(2n + 9){}', { selectors: true});
3636
test('foo{bar:calc(1rem * 1.5)}', 'foo{bar:1.5rem;bar:calc(1rem * 1.5)}', { preserve: true });
3737
test('foo:nth-child(2n + $var-calc){}', 'foo:nth-child(2n + $var-calc){}');
38+
test('foo{margin:calc(2rem - .14285em)}', 'foo{margin:calc(2rem - 0.14285em)}');
3839
assert.equal(0, test(
3940
'foo{bar:calc(500px - 0px)}',
4041
'foo{bar:500px}',

0 commit comments

Comments
 (0)