File: PropertyParser.pm

package info (click to toggle)
libcss-dom-perl 0.15-1%2Bdeb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 716 kB
  • ctags: 249
  • sloc: perl: 7,310; makefile: 2
file content (2062 lines) | stat: -rw-r--r-- 62,511 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
package CSS::DOM::PropertyParser;

$VERSION = '0.15';

use warnings; no warnings qw 'utf8 parenthesis';
use strict;

use constant 1.03 (); # multiple
use CSS::DOM'Constants ':primitive', ':value';
use CSS'DOM'Util<unescape unescape_str unescape_url>;

use constant old_perl => $] < 5.01;
{ no strict 'refs'; delete ${__PACKAGE__.'::'}{old_perl} }

# perl 5.10.0 has a bug affecting $^N (perl bug #56194; not the initial
# report, but regressions in 5.10; read the whole ticket for details). We
# have a workaround, but it requires more CPU, so we only enable it for
# this perl version.
use constant naughty_perl => 0+$] eq 5.01;
{ no strict 'refs'; delete ${__PACKAGE__.'::'}{naughty_perl} }

*s2c = *CSS'DOM'Constants'SuffixToConst;
our %s2c;

our %compiled; # compiled formats
our %subcompiled; # compiled sub-formats
# We use ‘our’ instead of ‘my’, because re-evals that are compiled at run
# time can be a bit buggy when they refer to ‘my’ variables.

sub new {
 bless{}, shift
}

sub add_property {
 $_[0]{$_[1]}=$_[2]
}

sub get_property {
 exists $_[0]{$_[1]} ? $_[0]{$_[1]} : ()
}

sub delete_property {
 delete $_[0]{$_[1]} or ()
}

sub property_names {
 sort keys %{$_[0]};
}

sub subproperty_names {
 exists $_[0]{$_[1]} or return;
 my $p = $_[0]{$_[1]};
 my @p = $p->{format} =~ /'([^']+)'/g;
 exists $p->{properties} && $p->{properties} and
    push @p, keys %{$p->{properties}};
 @p;
}

sub clone {
# exists &dclone or require Storable, "Storable"->import('dclone');
# return dclone($_[0]);
 require Clone;
 return Clone'clone($_[0]);
}

#  Declare the variables that the re-evals use. Some nasty hacker went and
# ‘fixed’ run-time re-evals to propagate hints, so now we have to do this
#  as of perl 5.13.8.
our(
 @match,@list,@valtypes,$prepped,$alt_types,@List,%Match,%match,@Match,
 $tokens,$Self,$Fail
);

# The interface for match is documented in a POD comment further down
# (search for the second occurrence of ‘=item match’).
sub match { SUB: {
 my ($self,$property) = (shift,shift);
 return unless exists $self->{$property};

 # Prepare the value
 (my $types, local our ($tokens,$prepped,$alt_types)) = _prep_val(@_);
 # tokens is the actual tokens; $prepped is the tokens unescaped and lc'd
 # if they are ids; $alt_types contains single-char strings indicating pos-
 # sible datum types.
#use DDS; Dump $types if $property =~ /clip/;


 my @subproperties = $self->subproperty_names($property);
 my $shorthand = @subproperties;
 my $spec = $self->{$property};

 # Check for special values
 if(exists $spec->{special_values}
    && $types eq 'i'
    && exists $spec->{special_values}{$prepped->[0]}) {
  @_ = ($self,$property,$spec->{special_values}{$prepped->[0]});
  redo SUB;
 }

 # Check for inherit
 if($types eq 'i' and $prepped->[0] eq 'inherit') {
  my @arg_array = (
   $$tokens[0],'CSS::DOM::Value', type => CSS_INHERIT, css => $$tokens[0]
  );
  if($shorthand) {
   return { map +($_ => \@arg_array), @subproperties };
  }
  else { return @arg_array }
 }

 # Localise other vars used by the hairy regexps
 local our (@Match,%Match,@valtypes,@List);
 local our $Self = $self;

 # Compile the formats of the sub-properties,  something we  can’t  do
 # during the pattern match, as compilation requires regular expressions
 # and perl’s re engine is not reëntrant. This has to come before the for-
 # mat for this property,  in case it relies on  list-style-type.  We  use
 # (??{...}) to pick it up,  but that is too buggy in perl 5.8.x, so, for
 # old perls,  we compile it straight in.  Consequently we also have to
 # ‘un-cache’ any compiled format containing <counter>, in case it is
 #  shared with another parser object with another definition  for
 #  list-style-type.
 my $format = $$spec{format};
 for(
  @subproperties,
  $format =~ '<counter>'
   ? scalar(old_perl && delete $compiled{$format}, 'list-style-type')
   : ()
 ) {
  next unless exists $self->{$_};
  my $format = $self->{$_}{format}; 
  old_perl and $compiled{$format} and delete $compiled{$format};
  $compiled{$format} ||= _compile_format($format)
 }

 # Prepare this property’s format pattern
 my $pattern = $compiled{$format} ||= _compile_format($format);

 # Do the actual pattern matching
 $types =~ /^$pattern\z/ or return;

#use DDS; Dump $types,$tokens,\@valtypes;
#use DDS; Dump \%Match if $property =~ /clip/;
 # Get the values, convert them into CSSValue arg lists and return them
 if($shorthand) {
  my $retval = {%Match};
  my $subprops = exists $spec->{properties} ? $spec->{properties} : undef;

  # We record which captures have been turned into arg lists already,
  # since these are sometimes shared between properties.
  my @arglistified;

  for(@subproperties) {
   if(exists $retval->{$_}) {
    @{ $retval->{$_} } = _make_arg_list( @{ $retval->{$_} } );
   }
   else {
    my $set;
    if($subprops and exists $subprops->{$_}) {
     for my $c( @{ $subprops->{$_} } ) { # capture nums
      # find the first one that matched something
      if( $Match[$c] and length $Match[$c][0] ) {
       @{ $Match[$c] } = _make_arg_list( @{ $Match[$c] } )
        unless $arglistified[$c]++;
       ++$set;
       $retval->{$_} = $Match[$c];
       last;
      }
     }
    }
    if(!$set) {
     # use default value
# ~~~ Should we cache this? (If we do, we need to distinguish between
#    ‘content: Times New Roman’ and ‘font-family: Times New Roman’.)
     my $default = $self->{$_}{default};
     no warnings 'uninitialized';
     $retval->{$_} = length $default
      ? [
         $self->match($_, $default)
        ]
      : ""
    }
   }
  }
  $retval;
 }
 else { # simple
   my $css = join "", @{ (_space_out($types,$tokens))[1] };
#use DDS; Dump \@List  if exists $$spec{list} && $$spec{list};
   return _make_arg_list(
            $types, $tokens, 
            exists $$spec{list} && $$spec{list}
             ? \@List
             : (\@valtypes, $prepped)
          );
 }
}}

sub _make_arg_list {
 my($types, $tokens) = (shift,shift);
 my($stypes,$stokens) = _space_out($types, $tokens);
 my $css = join "", @$stokens;
 if(@_ == 1) { # list property
  my $list = shift @'_;
  my $sep = @$list <= 1 ? '' : do {
   my $range_start = $$list[0][4];
   my $range_end = $$list[1][4] - length($$list[1][4]) - 1;
   my(undef,$stokens) = _space_out(
    substr($types, $range_start-1, $range_end-$range_start+3),
    [@$tokens[$range_start-1...$range_end+1]]
   );
   join "", @$stokens[1...$#$stokens-1];
  };
  return $css, "CSS::DOM::Value::List",
   separator => $sep, css => $css,
   values => [ map {
    my @args = _make_arg_list(
                   @$_[0...3]
    );
    shift @args, shift @args;
    \@args
   } @$list ];
 }
 else{
  my($valtypes, $prepped) = @_;
  my @valtypes = grep defined, @$valtypes;
  if(@valtypes != 1 and
     $valtypes[0] != CSS_COUNTER || do { # The code in this block is to
      no warnings 'uninitialized';       # distinguish between counter(id,
      my $found;                         # id) (which is a CSS_COUNTER) and
      for(@valtypes[1...$#valtypes-1]) { # counter(id) id (CSS_CUSTOM).
       $_ == -1 and ++$found, last; # -1 is a special marker for the end of
      }                             #  a counter
      $found
     }) {
   return $css => "CSS::DOM::Value", type => CSS_CUSTOM, value => $css;
  }
  my $type = shift @valtypes;
  return $css, "CSS::DOM::Value::Primitive",
   type => $type, css => $css,
   value =>
      $type == CSS_NUMBER || $type == CSS_PERCENTAGE || $type == CSS_EMS ||
      $type == CSS_EXS || $type == CSS_PX || $type == CSS_CM ||
      $type == CSS_MM || $type == CSS_IN || $type == CSS_PT ||
      $type == CSS_PC || $type == CSS_DEG || $type == CSS_RAD ||
      $type == CSS_GRAD || $type == CSS_MS || $type == CSS_S ||
      $type == CSS_HZ || $type == CSS_KHZ
       ? $css
    : $type == CSS_STRING
       ? unescape_str $css
    : $type == CSS_IDENT
       ? unescape $css
    : $type == CSS_URI
       ? unescape_url $css
    : $type == CSS_COUNTER
       ? [
          $$prepped[$types =~ /i/, $-[0]],
          $types =~ /'/ ? $$prepped[$-[0]] : undef,
          $types =~ /i.*?i/ ? $$prepped[$+[0]-1] : undef,
         ]
    : $type == CSS_RGBCOLOR
       ? substr $types, 0, 1, eq '#'
         ? $$prepped[0]
         : do{
            my @vals;
            while($types =~ /([%D1])/g) {
             push @vals, [
              type =>
                 $1 eq '%' ? CSS_PERCENTAGE
               : $1 eq 'D' ? $s2c{unescape do{
                              ($$tokens[$-[1]] =~ '(\D+)')[0]
                             }}
               :             CSS_NUMBER,
              value => $1,
              css => $1,
             ]
            }
            \@vals
           }
    : $type == CSS_ATTR
       ? $$prepped[$types =~ /i/, $-[0]]
    : $type == CSS_RECT
       ? [
          map scalar(
           $types =~ /\G.*?(d?([D1])|i)/g,
           $1 eq 'i'
            ? [type => CSS_IDENT, value => 'auto'] #$$prepped[$-[1]]]
            : [
               type =>
                $2 eq 'D'
                 ? $s2c{unescape do{($$tokens[$-[2]] =~ '(\D+)')[0]}}
                 : CSS_NUMBER,
               value => join "", @$tokens[$-[1]...$+[1]-1]
              ]
          ), 1...4
         ]
    : die __PACKAGE__ . " internal error: unknown type: $type"
 }
}

sub _space_out {
 my($types,$tokens) = @_;
Carp'cluck() if ref $tokens ne 'ARRAY';
 $tokens = [@$tokens];
 my @posses;
 $types =~ s/(?<=[^(f])(?![),]|\z)/
  if($tokens->[-1+pos $types] =~ m=^[+-]\z=) {
   ''
  }
  else {
   push @posses, pos $types; 's'
  }
 /ge;
 splice @$tokens, $_, 0, ' ' for reverse @posses;
 return $types, $tokens;
}

# Defined further down, to keep the hairiness out of the way.
my($colour_names_re, $system_colour_names_re);

sub _prep_val {
 defined &unescape or
  require CSS::DOM::Util, 'CSS::DOM::Util'->import('unescape');
 my($types,$tokens);
 if(@_ > 1) {
  ($types,$tokens)= @_;
 }
 else {
  require CSS::DOM::Parser;
  ($types, $tokens) = CSS::DOM::Parser'tokenise($_[0]);
 }

 # strip out all whitespace tokens
 {
  my @posses;
  $tokens = [@$tokens]; # We have to copy it as it may be referenced
  $types =~ s/s/push @posses,pos$types;''/gem;  #  elsewhere.
  splice@$tokens,$_,1 for reverse @posses;
 }
 
 my @prepped;
 my @alt_type;
 for(0..$#$tokens) {
  my $type = substr $types, $_, 1;
  my $thing;
  if($type =~ /[if#]/) {
   $thing = lc unescape($$tokens[$_]);
   if($type eq 'i') {
    if($thing =~ /^$colour_names_re\z/o) { $alt_type[$_] = 'c' }
    elsif($thing =~ /^$system_colour_names_re\z/o) { $alt_type[$_] = 's' }
   }
   elsif($type eq '#') {
    $thing =~ /^#(?:[0-9a-f]{3}){1,2}\z/ and $alt_type[$_] = 'c';#olour
# ~~~ What about escapes?
   }
  }
  elsif($type eq 'D') { # dimension
    ($thing = $$tokens[$_]) =~ s/^[.0-9]+//;
    $thing = lc unescape($thing);
    if($thing =~ /^(?:deg|g?rad)\z/) { $alt_type[$_] = 'a'}#ngle
    elsif($thing =~ /^(?:e[mx]|p[xtc]|in|[cm]m)\z/) {
     $alt_type[$_] = 'l'#ength
    }
  }
  elsif($type eq '1') { # number
    $thing = 0+$$tokens[$_];  # change 0.000 to 0, etc.
  }
  elsif($type eq 'd') { # delimiter
    $alt_type[$_] = '+' if $$tokens[$_] =~ /^[+-]\z/;
  }
  defined $alt_type[$_] or $alt_type[$_] = '';
  push @prepped, $thing;
 }

 return ($types,$tokens,\@prepped,\@alt_type);
}


# Various bits and pieces for _compile_format’s use

$Fail = qr/(?!)/; # avoid recompiling the same sub-regexp doz-
                      # ens of times

# This optionally matches a sign
my $sign = '(?:d(?(?{$$alt_types[pos()-1]eq"+"})|(?!)))?';

# These $type_ expressions save the current value type in @valtypes.
my $type_is_ # generic one to stick inside (?{...})
 =  '$valtypes[$#valtypes='
              . (naughty_perl ? '$pos[-1]' : 'pos()-length$^N')
  . ']=';
my $type_is_dim_or_number
 = '(?{
     $valtypes[
      $#valtypes=' . (naughty_perl ? '$pos[-1]' : 'pos()-length$^N') . '
     ]
      = $$prepped[pos()-1] ? $s2c{ $$prepped[pos()-1] } : CSS_NUMBER
    })';

# Constants defined in _compile_format and only used there get deleted at
# run time.
{ no strict 'refs'; delete @{__PACKAGE__.'::'}{cap_start=>cap_end=>} }

sub _compile_format {
 my $format = shift;
 my $no_match_stuff = shift; # Leave out the @%match localisation stuff

 # The types of transmogrifications we need to make:

 # Whitespace is ignored.
 #
 # [] is simply (?:).
 #
 # () is itself, except we record the captures manually with (?{}).
 #
 # The chars ? * + | are left as is (except when | is doubled).
 #
 # <...>  thingies are replaced with simple regexps that  match  the  type
 # and then check with a re-eval to see whether the token matches.  Then we
 # have another re-eval that records the type of match in @valtypes,  so we
 # can distinguish between ‘red’ matched by  <ident>  (counter-reset: red),
 # ‘red’ matched by <colour> (color: red) and ‘red’ matched by <str/words>
 # (font-family: red).
 #
 # Identifiers are treated similarly.
 #
 # '...' references are turned into complicated re-evals that look up the
 # format for the other property and add it to the %match hash if
 # it matches.
 # 
 # || causes the innermost enclosing group to be transformed into a per-
 # mutation-matching pattern.  Since at least  one  is  required,  we
 # put question marks after all sub-patterns except the  first  in
 # each alternate. For example, a||b||c (where the letters rep-
 # resent sub-patterns, not actual chars in  the  format)
 # becomes a(?:bc?|cb?)?|b(?:ac?|ca?)?|c(?:ab?|ba?)?.

 # Concerning the [@%][Mm]atch variables:
 #
 # All captures are saved separately  in  an  array  during  matching.  To
 # account for backtracking,  we have to localise every  assignment.  Since
 # the localisations will be undone when the re exits, we have to save them
 # in separate variables. The lc vars are used during matching; the capita-
 # lised variables afterwards.  Since we  may  be  parsing  sub-properties
 # (with their own sets of captures), we need a second localisation mechan-
 # ism that restores the previous set of captured values when a sub-proper-
 # ty’s re exits. (We can’t use Perl’s, because the rest of the outer pat-
 # tern is called recursively  from  within  the  inner  pattern.)  So:
 #
 # @match holds arrays of captures, $match[-1] being the current array.
 # When the re exits, @{ $match[-1] } is copied into @Match. Subpatterns
 # push onto @match upon entry and pop it on exit.
# ~~~ Actually, it seems we don’t currently pop it, but all tests pass. Why
#     is this?
 #
 # @list is similar to @match, but it holds all captured matches in the
 # order they matched, skipping those that did not match. It includes mul-
 # tiple elements for quantified captures (that is,  if they matched multi-
 # ple times).  @match,  on the other hand,  is indexed by capture  number,
 # like @-, et al.  In other words, if we match ‘'rhext' 'scled'’ against
 # ‘(<ident>)? (<string>)+’, we have:
 #   @match:  undef (elem 0 is always undef), undef, 'scled'
 #   @list:  'rhext', 'scled'
 #
 # %match holds named captures (sub-properties) directly (no extra locali-
 # sation necessary), which are then copied to %Match afterwards.
 #
 # In perl 5.10.0 (see the definition of naughty_perl, above).  We work
 # around the unreliability of $^N by pushing the current pos onto  @pos
 # before a sub-pattern or capture,  and popping it afterwards.  We  use
 # $pos[-1] instead of pos()-length$^N (for the beginning of the capture).

 my $pattern = $no_match_stuff
  ? '' : '(?{local @match=(@match,[]); local @list=(@list,[])})(?:';
                        # We add (?: to account for top-level alternations.

 my @group_start = length $pattern; # holds the position within $pattern of
                                    # the last group start
 my @permut_marker = []; # where a || occurs (array of arrays; each group
                         # has its own array on this stack)
 my @capture_nums;
 my $last_capture = 0;

 # For each piece of the format, add to the pattern.
 while(
  $format =~ /(\s+)|(\|\|)|<([^>]+)>|([a-z-]+)|([0-9]+)|'([^']+)'|(.)/g
 ) {
  next if $1;  # ignore whitespace

  # cygwin hack:
  use constant {  # re-evals for before and after captures
   cap_start => naughty_perl ? '(?{local @pos=(@pos,pos)})' : '',
   cap_end   => naughty_perl ? '(?{local @pos=@pos; --$#pos})' : '',
  };

  if($2) { # ||
   push @{ $permut_marker[-1] }, length $pattern;
  }
  elsif($3) { # <...>
   # We have to wrap most of these in (?:...) in case they get quantified.
   # (‘ab’ has to become ‘(?:ab)’ so that ‘ab?’ becomes ‘(?:ab)?’.)
   $pattern .=
     $3 eq 'angle'      ?
      "(?:($sign\[D1])" . cap_start . '(?(?{
        $$alt_types[pos()-1]eq"a"||$$prepped[pos()-1]eq 0
       })|(?!))' . $type_is_dim_or_number . cap_end .")"
   : $3 eq 'attr'       ?
      '(?x:' . cap_start . '(
         f(?(?{$$prepped[pos()-1]eq"attr("})|(?!))i\)
       )' . "(?{ $type_is_ CSS_ATTR })" . cap_end . ")"
   : $3 =~ /^colou?r\z/ ?
      "(?x:" . cap_start . "(?:
        ([i#](?(?{
          \$\$alt_types[pos()-1]eq 'c'||\$\$alt_types[pos()-1]eq 's'
        })|(?!))) (?{ $type_is_ (
                   \$\$alt_types[pos()-1]eq 'c' ? CSS_RGBCOLOR : CSS_IDENT
                  ) })
         |
        (f
          (?:
           (?(?{\$\$prepped[pos()-1]eq 'rgb('})|(?!))
           (?: $sign 1(?:,$sign 1){2} | $sign%(?:,$sign%){2} )
            |
           (?(?{\$\$prepped[pos()-1]eq 'rgba('})|(?!))
           (?: $sign 1(?:,$sign 1){2} | $sign%(?:,$sign%){2} ),$sign 1
          )
        \\)) (?{ $type_is_ CSS_RGBCOLOR })
       )" . cap_end . ")"

   # <counter> represents the following four:
   #  counter(<identifier>)
   #  counter(<identifier>,'list-style-type')
   #  counters(<identifier>,<string>)
   #  counters(<identifier>,<string>,'list-style-type')
   : $3 eq 'counter'    ? do {
      our $Self;
      my $list_style_type = old_perl
       ? exists $$Self{"list-style-type"}
         ? $compiled{$$Self{"list-style-type"}{format}}
            ||= _compile_format($$Self{"list-style-type"}{format})
         : '(?!)'
       : '(??{
             exists $$Self{"list-style-type"}
             ? $compiled{$$Self{"list-style-type"}{format}}
             : $Fail
            })'
      ;
      q*(?x:* . cap_start . q*(f(?{$$prepped[pos()-1]})
          (?(?{$^R eq "counter("})
            i(?:,* . $list_style_type . q*)?
             |
            (?(?{$^R eq "counters("})
              i,'(?:,* . $list_style_type . q*)?
               |
              (?!)
            )
          )
        \))*
        . "(?{ $type_is_ CSS_COUNTER;"
           . ' $valtypes[$#valtypes=pos()-1] = -1})' # -1 is a special
           . cap_end . ')'                           # marker for the end
     }                                               # of a counter
   : $3 eq 'frequency'  ?
      '(?:' . cap_start . '((?:d(?(?{
         $$tokens[pos()-1]eq"+"||$$tokens[-1+pos]eq"-"&&$$tokens[pos]eq 0
       })|(?!)))?[D1](?(?{
        my$p=$$prepped[pos()-1];$p eq"hz"||$p eq"khz"||$p eq 0
       })|(?!)))' . $type_is_dim_or_number . cap_end . ")"
   : $3 eq 'identifier' ?
      "(?:" . cap_start . "(i)(?{ $type_is_ CSS_IDENT })" . cap_end . ")"
   : $3 eq 'integer'    ?
      '(?:' . cap_start . '(1(?(?{index$$tokens[pos()-1],".",==-1})|(?!)))'
      . "(?{ $type_is_ CSS_NUMBER })" . cap_end . ")"
   : $3 eq 'length'     ?
      "(?:" . cap_start . "($sign\[D1])" . '(?(?{
        $$alt_types[pos()-1]eq"l"||$$prepped[pos()-1]eq 0
       })|(?!))' . $type_is_dim_or_number . cap_end . ")"
   : $3 eq 'number'     ?
      "(?:" . cap_start . "(1)(?{ $type_is_ CSS_NUMBER })" . cap_end . ")"
   : $3 eq 'percentage' ?
       "(?:" . cap_start
        . "($sign%)(?{ $type_is_ CSS_PERCENTAGE })"
      . cap_end . ")"
   : $3 eq 'shape'      ?
      q*(?x:* . cap_start . q*(f
          (?(?{$$prepped[pos()-1] eq "rect("})
            (?:
             (?:
              (?:d(?(?{$$alt_types[pos()-1]eq"+"})|(?!)))?[D1](?(?{
               $$alt_types[pos()-1]eq"l"||$$prepped[pos()-1] eq 0
              })|(?!))
               |
              i(?(?{$$prepped[pos()-1]eq"auto"})|(?!))
             ),?
            ){4}
             |
            (?!)
          )
        \))* . "(?{ $type_is_ CSS_RECT })" . cap_end . ")"
   : $3 eq 'string'     ?
      "(?:" . cap_start . "(')(?{ $type_is_ CSS_STRING })" . cap_end . ")"
   : $3 eq 'str/words'  ?
        "(?:" . cap_start
        . "('|i+)(?{ $type_is_ CSS_STRING })"
      . cap_end . ")"
   : $3 eq 'time'       ?
      "(?:" . cap_start . "($sign\[D1])" . '(?(?{
        my$p=$$prepped[pos()-1];$p eq"ms"||$p eq"s"||$p eq 0
       })|(?!))' . $type_is_dim_or_number . cap_end . ")"
   : $3 eq 'url'        ?
      "(?:" . cap_start . "(u)(?{ $type_is_ CSS_URI })" . cap_end . ")"
   : die "Unrecognised data type in property format: <$3>";
  }
  elsif($4) { # identifier
   $pattern .=
     '(?:' . cap_start
       . '(i)(?(?{$$prepped[-1+pos]eq"' . $4 . '"})|(?!))'
       . "(?{ $type_is_ CSS_IDENT })"
    . cap_end . ")";
  }
  elsif($5) { # number
   $pattern .=
     '(?:' . cap_start
             . '(1)(?(?{$$tokens[-1+pos]eq"' . $5 . '"})|(?!))'
             . "(?{ $type_is_ CSS_NUMBER })"
    . cap_end . ")";
  }
  elsif($6) { # '...' reference
   $pattern .=
    '(?:' # again, we use (?: ... ) in case a question mark is added
   .  cap_start
   . '((??{
               exists $$Self{"' . $6 . '"}
               ? $compiled{$$Self{"' . $6 . '"}{format}}
               : $Fail;
      }))'
   . '(?{
       # We have a do-block here because a re-eval’s lexical pad is very
       # buggy and must not be used. (See perl bug #65150.)
       local$match{"'.$6.'"}=do{
         my @range
          = ' . (naughty_perl ? '$pos[-1]' : 'pos()-length$^N') . '
              ...-1+pos;
         [
          '.(
             naughty_perl ? 'substr($_,$pos[-1],pos()-$pos[-1])' : '$^N'
            ).',
           [@$tokens[@range]],[@valtypes[@range]],[@$prepped[@range]]
         ];
       }
      })'
   .  cap_end
   .')'
              
  }
  elsif(do{$7 =~ /^[]|[()]\z/}) { # group or alternation
   # For non-capturing groups, we use (?: ... ).
   # For capturing groups, since they may be quantified, and since we have
   # to put a re-eval after them to capture the value, we use an extra non-
   # capturing group: (?:( ... )(?{...}))
   # Since || is stronger than |, we have to treat | a bit like ][

   if(do{$7 =~ /^[])|]\z/}) { # end of a group
    my $markers = pop @permut_marker;
    if(@$markers) { # Oh no!
     unshift @$markers, $group_start[-1];
     _make_permutations($pattern, $markers);
    }
    pop @group_start;
    $pattern .=
       $7 eq '|' ? '|'
     : $7 eq ']' ? ')'
     : ')(?{
          (
           local $match[-1][' . pop(@capture_nums) . '],
           local $list[-1]
          ) = do {
           my @range
            = '.(naughty_perl ? '$pos[-1]' : 'pos()-length$^N').'...-1+pos;
           my @a = (
            '.(
               naughty_perl
                ? 'substr($_,$pos[-1],pos()-$pos[-1])'
                : '$^N'
              ).',
             [@$tokens[@range]],[@valtypes[@range]],[@$prepped[@range]],
             pos
           );
           \@a, [@{$list[-1]}, \@a]
          }
        })' . cap_end . ')';
     # We have to intertwine these assignments in this convoluted way
     # because of the lexical-in-re-eval bug [perl #65150].
   }
   if(do{$7 =~ /^[[(|]\z/}) { # start of a group
    $pattern
     .= '(?:'
      . (cap_start.'(')
          x ($7 eq '(')
     unless $7 eq '|';
    push @group_start, length $pattern;
    push @permut_marker, [];
    $7 eq '(' and push @capture_nums, ++$last_capture;
   }
  }
  else {
   $pattern .= do{$7 =~ /^[?*+]\z/}   ? $7
             : do{$7 =~ /^[;{},:]\z/} ? quotemeta $7
             :  '(?:d(?(?{$$tokens[-1+pos]eq"' .quotemeta($7) .'"})|(?!)))'
             ;
  }
 }

 # There may be top-level ‘||’ things, so we check for those.
 if(@{$permut_marker[0]}) {
    unshift @{ $permut_marker[0] }, $group_start[0];
    _make_permutations($pattern, $permut_marker[0]);
 }

 # Deal with the match vars
 $pattern .= ')(?{@Match=@{$match[-1]};@List=@{$list[-1]};%Match=%match})'
  unless $no_match_stuff;

 use re 'eval';
 return qr/$pattern/;
}

sub _make_permutations { # args: pattern, \@markers
                         # pattern is modified in-place
 my $markers = pop;
 for my $pattern($_[0]) {
    # Split up the end of the pattern back to the beginning of the inner-
    # most enclosing group, as specified by the markers. Put the separate
    # pieces into @alts.
    my @alts;
    for(reverse @$markers) {
     unshift @alts, substr $pattern, $_, length $pattern, '';
    }
    
    # Do the permutations
    $pattern .= _permute(@alts);
 }
}

sub _permute {
 if(@_ == 2) { return "(?:$_[0]$_[1]?|$_[1]$_[0]?)" }
 else {
  return
     "(?:"
   . join("|", map $_[$_] . _permute(@_[0..$_-1,$_+1...$#_]) . '?', 0..$#_)
   . ")"
 }
}


=begin comment

Colour names:

perl -MRegexp::Assemble -le 'my $ra = new Regexp::Assemble; $ra->add($_) for qw " transparent aliceblue antiquewhite aqua aquamarine azure beige bisque black blanchedalmond blue blueviolet brown burlywood cadetblue chartreuse chocolate coral cornflowerblue cornsilk crimson cyan darkblue darkcyan darkgoldenrod darkgray darkgreen darkgrey darkkhaki darkmagenta darkolivegreen darkorange darkorchid darkred darksalmon darkseagreen darkslateblue darkslategray darkslategrey darkturquoise darkviolet deeppink deepskyblue dimgray dimgrey dodgerblue firebrick floralwhite forestgreen fuchsia gainsboro ghostwhite gold goldenrod gray green greenyellow grey honeydew hotpink indianred indigo ivory khaki lavender lavenderblush lawngreen lemonchiffon lightblue lightcoral lightcyan lightgoldenrodyellow lightgray lightgreen lightgrey lightpink lightsalmon lightseagreen lightskyblue lightslategray lightslategrey lightsteelblue lightyellow lime limegreen linen magenta maroon mediumaquamarine mediumblue mediumorchid mediumpurple mediumseagreen mediumslateblue mediumspringgreen mediumturquoise mediumvioletred midnightblue mintcream mistyrose moccasin navajowhite navy oldlace olive olivedrab orange orangered orchid palegoldenrod palegreen paleturquoise palevioletred papayawhip peachpuff peru pink plum powderblue purple red rosybrown royalblue saddlebrown salmon sandybrown seagreen seashell sienna silver skyblue slateblue slategray slategrey snow springgreen steelblue tan teal thistle tomato turquoise violet wheat white whitesmoke yellow yellowgreen"; print $ra->re '

perl -MRegexp::Assemble -le 'my $ra = new Regexp::Assemble; $ra->add($_) for qw " activeborder activecaption appworkspace background buttonface buttonhighlight buttonshadow buttontext captiontext graytext highlight highlighttext inactiveborder inactivecaption incativecaptiontext infobackground infotext menu menutext scrollbar threeddarkshadow threedface threedhighlight threedlightshadow threedshadow window windowframe windowtext  "; print $ra->re '

=end comment

=cut

$colour_names_re = '(?:d(?:ark(?:s(?:late(?:gr[ae]y|blue)|(?:eagree|almo)n)|g(?:r(?:e(?:en|y)|ay)|oldenrod)|o(?:r(?:ange|chid)|livegreen)|(?:turquois|blu)e|magenta|violet|khaki|cyan|red)|eep(?:skyblue|pink)|imgr[ae]y|odgerblue)|l(?:i(?:ght(?:s(?:(?:eagree|almo)n|(?:teel|ky)blue|lategr[ae]y)|g(?:r(?:e(?:en|y)|ay)|oldenrodyellow)|c(?:oral|yan)|yellow|blue|pink)|me(?:green)?|nen)|a(?:vender(?:blush)?|wngreen)|emonchiffon)|m(?:edium(?:(?:aquamarin|turquois|purpl|blu)e|s(?:(?:pring|ea)green|lateblue)|(?:violetre|orchi)d)|i(?:(?:dnightblu|styros)e|ntcream)|a(?:genta|roon)|occasin)|s(?:(?:a(?:(?:ddle|ndy)brow|lmo)|pringgree)n|late(?:gr[ae]y|blue)|ea(?:green|shell)|(?:teel|ky)blue|i(?:enna|lver)|now)|p(?:a(?:le(?:g(?:oldenrod|reen)|turquoise|violetred)|payawhip)|(?:owderblu|urpl)e|e(?:achpuff|ru)|ink|lum)|c(?:(?:h(?:artreus|ocolat)|adetblu)e|or(?:n(?:flowerblue|silk)|al)|(?:rimso|ya)n)|b(?:l(?:a(?:nchedalmond|ck)|ue(?:violet)?)|(?:isqu|eig)e|urlywood|rown)|g(?:r(?:e(?:en(?:yellow)?|y)|ay)|ol(?:denro)?d|hostwhite|ainsboro)|o(?:l(?:ive(?:drab)?|dlace)|r(?:ange(?:red)?|chid))|a(?:(?:ntiquewhit|liceblu|zur)e|qua(?:marine)?)|t(?:(?:urquois|histl)e|ransparent|omato|eal|an)|f(?:loralwhite|orestgreen|irebrick|uchsia)|r(?:o(?:sybrown|yalblue)|ed)|i(?:ndi(?:anred|go)|vory)|wh(?:it(?:esmok)?e|eat)|ho(?:neydew|tpink)|nav(?:ajowhite|y)|yellow(?:green)?|violet|khaki)';

$system_colour_names_re = '(?:in(?:active(?:caption|border)|fo(?:background|text)|cativecaptiontext)|b(?:utton(?:(?:highligh|tex)t|shadow|face)|ackground)|threed(?:(?:light|dark)?shadow|highlight|face)|(?:(?:caption|gray)tex|highligh(?:ttex)?)t|a(?:ctive(?:caption|border)|ppworkspace)|window(?:frame|text)?|menu(?:text)?|scrollbar)';

=encoding utf8

=head1 NAME

CSS::DOM::PropertyParser - Parser for CSS property values

=head1 VERSION

Version 0.15

=head1 SYNOPSIS

  use CSS::DOM::PropertyParser;
  
  $spec = new CSS::DOM::PropertyParser; # empty
  # OR
  $spec = $CSS::DOM::PropertyParser::Default->clone;
  
  $spec->add_property(
   overflow => {
    format => 'visible|hidden|scroll|auto',
    default => 'visible',
    inherit => 0,
   }
  );
  
  $hashref = $spec->get_property('overflow');
  
  $hashref = $spec->delete_property('overflow');
  
  @names = $spec->property_names;

=head1 DESCRIPTION

Objects of this class provide lists of supported properties for L<CSS::DOM>
style sheets. They also describe the syntax and parsing of those 
properties' values.

Some CSS properties simply have their own values (e.g., overflow); some
are abbreviated forms of several other properties (e.g., font). These are
referred to in this documentation as 'simple' and 'shorthand' properties.

=head1 CONSTRUCTOR

C<$spec = new CSS::DOM::PropertyParser> returns an object that does not
recognise any properties, to which you
can add your own properties.

There are two parser objects that come with this module. These are
C<$CSS::DOM::PropertyParser::CSS21>, which contains all of CSS 2.1, and
C<$CSS::DOM::PropertyParser::Default>, which is currently identical to the
former, but to which parts of CSS 3 which eventually be added.

If one of the default specs will do, you don't need a constructor. Simply
pass it to the L<CSS::DOM> constructor. If you want to modify it, clone it
first, using the C<clone> method (as shown in the L</SYNOPSIS>). It is
often convenient to clone the C<$Default> spec and delete those properties
that are not supported.

=head1 METHODS

=for comment
=head2 Methods for Controlling Property Specifications

=over 4

=item clone

Returns a deep clone of the object. (It's deep so that you can modify the
hashes/arrays inside it without modifying the original.)

=item add_property ( $name, \%spec )

Adds the specification for the named property. See
L</HOW INDIVIDUAL PROPERTIES ARE SPECIFIED>, below.

=item get_property ( $name )

Returns the hashref passed to the previous method.

=item delete_property ( $name )

Deletes the property and returns the hash ref.

=item property_names

Returns a list of the names of supported properties.

=item subproperty_names ( $name )

Returns a list of the names of C<$name>'s sub-properties if it is a
shorthand property.

=item match

Currently for internal use only. See the source code for documentation.
Use at your own risk.

=back

=begin comment

Once I’ve made CSS::DOM::Parser’s tokenise routine public (after a bit of
polishing) (or broken it out into a separate module, CSS::Tokeniser), I’ll
add this to the docs. I also actually have to modify ‘match’ to use this
interface, of course.

=head2 Methods Used by L<CSS::DOM::Style>

If you are thinking of writing a subclass of PropertyParser, you need to be
aware of these methods.

Instead of writing a subclass, you can create your
own class that does not inherit from PropertyParser use that. It will need 
to
implement these methods here. The methods listed above can be omitted.

=over

=item match ( $property, $value )

=item match ( $property, $token_types, \@tokens )

This checks to see whether C<$value> is a valid value for the C<$property>,
parsing it if it is. C<$token_types> and C<@tokens> are the values returned
by C<CSS::DOM::Parser::tokenise>.

Return values are as follows:

If the value doesn't match: empty list.

If the property is a simple one: (0) the CSS 
code for the value (possibly normalised), (1) the class to which a value
object belongs, (2..) arguments to be passed to the constructor.

For a shorthand property, the return value is a single hash ref, the keys
being sub-property names and the values array refs containing what would be
returned for a simple property.

A custom class or subclass can return a L<CSS::DOM::Value> instead of the
class and constructor args, in which case the first return value can
simply be C<undef> (it should return C<(undef, $object)>).

Examples (return value starts on the line following each method call):

 # $prim stands for "CSS::DOM::Value::Primitive"
 # $list stands for "CSS::DOM::Value::List"
 
 $prop_parser->match('background-position','top left');
 'top left', 'CSS::DOM::Value', CSS_CUSTOM, 'top left'
 
 $prop_parser->match('background-position','inherit');
 'inherit', 'CSS::DOM::Value', CSS_INHERIT
 
 $prop_parser->match('top','1em');
 '1em', $prim, type => CSS_EMS, value => 1

 $prop_parser->match('content','"\66oo"');
 '"\66oo"', $prim, type => CSS_STRING, value => foo
 
 $prop_parser->match('clip','rect( 5px, 6px, 7px, 8px )');
 'rect(5px, 6px, 7px, 8px)', $prim,
   type => CSS_RECT,
   value => [ [ type => CSS_PX, value => 5 ],
              [ type => CSS_PX, value => 6 ],
              [ type => CSS_PX, value => 7 ],
              [ type => CSS_PX, value => 8 ] ]
 
 $prop_parser->match('color','#fff');
 '#fff', $prim, type => CSS_RGBCOLOR, value => '#fff'
 
 $prop_parser->match('color','rgba(255,0,0,.5)');
 'rgba(255, 0, 0, .5)', $prim, type => CSS_RGBCOLOR,
   value => [ [ type => CSS_NUMBER, value => 255 ],
              [ type => CSS_NUMBER, value => 0   ],
              [ type => CSS_NUMBER, value => 0   ],
              [ type => CSS_NUMBER, value => .5  ] ]
 
 $prop_parser->match('content','counter(foo,disc)');
 'counter(foo, disc)', $list,
   separator => ' ',
   values => [
    [
     type => CSS_COUNTER,
     value => [
      [ type => CSS_IDENT, value => 'foo' ],
      undef,
      [ type => CSS_IDENT, value => 'disc' ],
     ]
    ],
   ]
 
 $prop_parser->match('font-family','Lucida Grande');
 'Lucida Grande', $list,
   separator => ', ',
   values => [
    [ type => CSS_STRING, value => 'Lucida Grande' ],
   ]

 $prop_parser->match('counter-reset','Lucida Grande');
 'Lucida Grande', $list,
   separator => ' ',
   values => [
    [ type => CSS_IDENT, value => 'Lucida' ],
    [ type => CSS_IDENT, value => 'Grande' ],
   ]
 
 $prop_parser->match('font','bold 13px Lucida Grande');
 {
  'font-style' => [
    'normal', $prim, type => CSS_IDENT, value => 'normal'
   ],
  'font-variant' => [
    'normal', $prim, type => CSS_IDENT, value => 'normal'
   ],
  'font-weight' => [
    'bold', $prim, type => CSS_IDENT, value => 'bold'
   ],
  'font-size' => [ '13px', $prim, type => CSS_PX, value => 13 ],
  'line-height' => [
    'normal', $prim, type => CSS_IDENT, value => 'normal'
   ],
  'font-family' => [ 'Lucida Grande', $list,
    separator => ', ',
    values => [
     [ type => CSS_STRING, value => 'Lucida Grande' ],
    ]
   ]
 }

=item whatever

~~~ 
CSS::DOM::Style currently relies on the internal formatting of the hash
refs. I want to allow custom property parser classes to do away with hash 
refs
altogether, so I will need extra methods here that Style will use instead.

=back

=end comment

=head1 HOW INDIVIDUAL PROPERTIES ARE SPECIFIED

Before you read this the first time, look at the L</Example> below, and
then come back and use this for reference.

The specification for an individual property is a hash ref. There are
several keys that each hash ref can have:

=over

=item format

This is set to a string that describes the format of the property. The
syntax used is based on the CSS 2.1 spec, but is not exactly the same.
Unlike regular expressions, these formats are applied to properties on a
token-by-token basis, not one character at a time. (This means that
C<100|200> cannot be written as C<[1|2]00>, as that would mean
S<C<1 00 | 2 00>>.)

Whitespace is ignored in the format and in the CSS property except as a
token separator.

There are several metachars (in order of precedence):

 [...]      grouping (like (?:...) )
 (...)      capturing group (just like a regexp)
 ?          optional
 *          zero or more
 +          one or more
 ||         alternates that can come in any order and are optional,
            but at least one must be specified  (the order will be
            retained if possible)
 |          alternates, exactly one of which is required

In addition, the following datatypes can be specified in angle brackets:

 <angle>       A number with a 'deg', 'rad' or 'grad' suffix
 <attr>        attr(...)
 <colour>      (You can omit the 'u' if you want to.) One of CSS's
               predefined colour or system colour names, or a #
               followed by 3 or 6 hex digits, or the 'rgb(...)'
               format (rgba is supported, too)
 <counter>     counter(...)
 <frequency>   A unit of Hz or kHz
 <identifier>  An identifier token
 <integer>     An integer (really?!)
 <length>      Number followed by a length unit (em, ex, px, in, cm,
               mm, pt, pc)
 <number>      A number token
 <percentage>  Number followed by %
 <shape>       rect(...)
 <string>      A string token
 <str/words>   A sequence of identifiers or a single string (e.g., a
               font name)
 <time>        A unit of seconds or milliseconds
 <url>         A URL token

The format for a shorthand property can contain the name of a sub-property
in single ASCII quotes.

All other characters are understood verbatim.

It is not necessary to include the word 'inherit' in the format, since
every property supports that.

C<< <counter> >> makes use of the specification for the list-style-type
property. So if you modify the latter, it will affect C<< <counter> >> as
well.

=item default

The default value. This only applies to simple properties.

=item inherit

Whether the property is inherited.

=item special_values

A hash ref of values that are replaced with other values (e.g.,
S<C<< caption => '13px sans-serif' >>>.) The keys
are lowercase identifier names.

This feature only applies to single identifiers. In fact, it exists solely
for the font property's use.

=item list

Set to true if the property is a list of values. The capturing parentheses
in the format determine the individual values of the list.

This applies to simple properties only.

=item properties

For a shorthand property, list the sub-properties here. The keys are the
property names. The values are array refs. The elements within the arrays
are numbers indicating which captures in the format are to be used for the
sub-property's value. They are tried one after the other. Whichever is the
first that matches (null matches not counting) is used.

Sub-properties that are referenced in the C<format> need not be listed 
here.

=item serialise

For shorthand properties only. Set this to a subroutine that serialises the
property. It is called with a hashref of sub-properties as its sole 
argument. The values of the hash are blank for properties that are set to
their initial values. This sub is only called when all sub-properties are
set.

=back

=head2 Example

=cut

0&&q r

=for ;

  our $CSS21 = new CSS::DOM::PropertyParser;
  my %properties = (
    azimuth => {
     format => '<angle> |
                 [ left-side | far-left | left | center-left |
                   center | center-right | right | far-right |
                   right-inside ] || behind
                | leftwards | rightwards',
     default => '0',
     inherit => 1,
    },

   'background-attachment' => {
     format  => 'scroll | fixed',
     default => 'scroll',
     inherit => 0,
    },

   'background-color' => {
     format  => '<colour>',
     default => 'transparent',
     inherit => 0,
    },

   'background-image' => {
     format => '<url> | none',
     default => 'none',
     inherit => 0,
    },
    
   'background-position' => {
     format => '[<percentage>|<length>|left|right]
                 [<percentage>|<length>|top|center|bottom]? |
                [top|bottom] [left|center|right]? |
                center [<percentage>|<length>|left|right|top|bottom|
                        center]?',
     default => '0% 0%',
     inherit => 0,
    },
    
   'background-repeat' => {
     format => 'repeat | repeat-x | repeat-y | no-repeat',
     default => 'repeat',
     inherit => 0,
    },
    
    background => {
     format => "'background-color' || 'background-image' ||
                'background-repeat' || 'background-attachment' ||
                'background-position'",
     serialise => sub {
      my $p = shift;
      my $ret = '';
      for(qw/ background-color background-image background-repeat
              background-attachment background-position /) {
       length $p->{$_} and $ret .= "$p->{$_} ";
      }
      chop $ret;
      length $ret ? $ret : 'none'
     },
    },
    
   'border-collapse' => {
     format => 'collapse | separate',
     inherit => 1,
     default => 'separate',
    },
    
   'border-color' => {
     format => '(<colour>)[(<colour>)[(<colour>)(<colour>)?]?]?',
     properties => {
      'border-top-color' => [1],
      'border-right-color' => [2,1],
      'border-bottom-color' => [3,1],
      'border-left-color' => [4,2,1],
     },
     serialise => sub {
       my $p = shift;
       my @vals = map $p->{"border-$_-color"},
                      qw/top right bottom left/;
       $vals[3] eq $vals[1] and pop @vals,
       $vals[2] eq $vals[0] and pop @vals,
       $vals[1] eq $vals[0] and pop @vals;
       return join " ", @vals;
     },
    },
    
   'border-spacing' => {
     format => '<length> <length>?',
     default => '0',
     inherit => 1,
    },
    
   'border-style' => {
     format => "(none|hidden|dotted|dashed|solid|double|groove|ridge|
                 inset|outset)
                [ (none|hidden|dotted|dashed|solid|double|groove|
                   ridge|inset|outset)
                  [ (none|hidden|dotted|dashed|solid|double|groove|
                     ridge|inset|outset)
                    (none|hidden|dotted|dashed|solid|double|groove|
                     ridge|inset|outset)?
                  ]?
                ]?",
     properties => {
      'border-top-style' => [1],
      'border-right-style' => [2,1],
      'border-bottom-style' => [3,1],
      'border-left-style' => [4,2,1],
     },
     serialise => sub {
       my $p = shift;
       my @vals = map $p->{"border-$_-style"},
                      qw/top right bottom left/;
       $vals[3] eq $vals[1] and pop @vals,
       $vals[2] eq $vals[0] and pop @vals,
       $vals[1] eq $vals[0] and pop @vals;
       return join " ", map $_||'none', @vals;
     },
    },
    
   'border-top' => {
     format => "'border-top-width' || 'border-top-style' ||
                'border-top-color'",
     serialise => sub {
       my $p = shift;
       my $ret = '';
       for(qw/ width style color /) {
         length $p->{"border-top-$_"}
           and $ret .= $p->{"border-top-$_"}." ";
       }
       chop $ret;
       $ret
     },
    },
   'border-right' => {
     format => "'border-right-width' || 'border-right-style' ||
                'border-right-color'",
     serialise => sub {
       my $p = shift;
       my $ret = '';
       for(qw/ width style color /) {
         length $p->{"border-right-$_"}
           and $ret .= $p->{"border-right-$_"}." ";
       }
       chop $ret;
       $ret
     },
    },
   'border-bottom' => {
     format => "'border-bottom-width' || 'border-bottom-style' ||
                'border-bottom-color'",
     serialise => sub {
       my $p = shift;
       my $ret = '';
       for(qw/ width style color /) {
         length $p->{"border-bottom-$_"}
           and $ret .= $p->{"border-bottom-$_"}." ";
       }
       chop $ret;
       $ret
     },
    },
   'border-left' => {
     format => "'border-left-width' || 'border-left-style' ||
                'border-left-color'",
     serialise => sub {
       my $p = shift;
       my $ret = '';
       for(qw/ width style color /) {
         length $p->{"border-left-$_"}
           and $ret .= $p->{"border-left-$_"}." ";
       }
       chop $ret;
       $ret
     },
    },
    
   'border-top-color' => {
     format => '<colour>',
     default => "",
     inherit => 0,
    },
   'border-right-color' => {
     format => '<colour>',
     default => "",
     inherit => 0,
    },
   'border-bottom-color' => {
     format => '<colour>',
     default => "",
     inherit => 0,
    },
   'border-left-color' => {
     format => '<colour>',
     default => "",
     inherit => 0,
    },
    
   'border-top-style' => {
     format => 'none|hidden|dotted|dashed|solid|double|groove|ridge|
                inset|outset',
     default => 'none',
     inherit => 0,
    },
   'border-right-style' => {
     format => 'none|hidden|dotted|dashed|solid|double|groove|ridge|
                inset|outset',
     default => 'none',
     inherit => 0,
    },
   'border-bottom-style' => {
     format => 'none|hidden|dotted|dashed|solid|double|groove|ridge|
                inset|outset',
     default => 'none',
     inherit => 0,
    },
   'border-left-style' => {
     format => 'none|hidden|dotted|dashed|solid|double|groove|ridge|
                inset|outset',
     default => 'none',
     inherit => 0,
    },
    
   'border-top-width' => {
     format => '<length>|thin|thick|medium',
     default => 'medium',
     inherit => 0,
    },
   'border-right-width' => {
     format => '<length>|thin|thick|medium',
     default => 'medium',
     inherit => 0,
    },
   'border-bottom-width' => {
     format => '<length>|thin|thick|medium',
     default => 'medium',
     inherit => 0,
    },
   'border-left-width' => {
     format => '<length>|thin|thick|medium',
     default => 'medium',
     inherit => 0,
    },
    
   'border-width' => {
     format => "(<length>|thin|thick|medium)
                [ (<length>|thin|thick|medium)
                  [ (<length>|thin|thick|medium)
                    (<length>|thin|thick|medium)?
                  ]?
                ]?",
     properties => {
      'border-top-width' => [1],
      'border-right-width' => [2,1],
      'border-bottom-width' => [3,1],
      'border-left-width' => [4,2,1],
     },
     serialise => sub {
       my $p = shift;
       my @vals = map $p->{"border-$_-width"},
                      qw/top right bottom left/;
       $vals[3] eq $vals[1] and pop @vals,
       $vals[2] eq $vals[0] and pop @vals,
       $vals[1] eq $vals[0] and pop @vals;
       return join " ", map length $_ ? $_ : 'medium', @vals;
     },
    },
    
    border => {
     format => "(<length>|thin|thick|medium) ||
                (none|hidden|dotted|dashed|solid|double|groove|ridge|
                 inset|outset) || (<colour>)",
     properties => {
      'border-top-width' => [1],
      'border-right-width' => [1],
      'border-bottom-width' => [1],
      'border-left-width' => [1],
      'border-top-style' => [2],
      'border-right-style' => [2],
      'border-bottom-style' => [2],
      'border-left-style' => [2],
      'border-top-color' => [3],
      'border-right-color' => [3],
      'border-bottom-color' => [3],
      'border-left-color' => [3],
     },
     serialise => sub {
       my $p = shift;
       my $ret = '';
       for(qw/ width style color /) {
         my $temp = $p->{"border-top-$_"};
         for my $side(qw/ right bottom left /) {
           $temp eq $p->{"border-$side-$_"} or return "";
         }
         length $temp and $ret .= "$temp ";
       }
       chop $ret;
       $ret
     },
    },
    
    bottom => {
     format => '<length>|<percentage>|auto',
     default => 'auto',
     inherit => 0,
    },
    
   'caption-side' => {
     format => 'top|bottom',
     default => 'top',
     inherit => 1,
    },
    
    clear => {
     format => 'none|left|right|both',
     default => 'none',
     inherit => 0,
    },
    
    clip => {
     format => '<shape>|auto',
     default => 'auto',
     inherit => 0,
    },
    
    color => {
     format => '<colour>',
     default => 'rgba(0,0,0,1)',
     inherit => 1,
    },
    
    content => {
     format => '( normal|none|open-quote|close-quote|no-open-quote|
                  no-close-quote|<string>|<url>|<counter>|<attr> )+',
     default => 'normal',
     inherit => 0,
     list => 1,
    },
    
   'counter-increment' => {
     format => '[(<identifier>) (<integer>)? ]+ | none',
     default => 'none',
     inherit => 0,
     list => 1,
    },
   'counter-reset' => {
     format => '[(<identifier>) (<integer>)? ]+ | none',
     default => 'none',
     inherit => 0,
     list => 1,
    },
    
   'cue-after' => {
     format => '<url>|none',
     default => 'none',
     inherit => 0,
    },
   'cue-before' => {
     format => '<url>|none',
     default => 'none',
     inherit => 0,
    },
    
    cue =>{
     format => '(<url>|none) (<url>|none)?',
     properties => {
      'cue-before' => [1],
      'cue-after' => [2,1],
     },
     serialise => sub {
       my $p = shift;
       my @vals = @$p{"cue-before", "cue-after"};
       $vals[1] eq $vals[0] and pop @vals;
       return join " ", map length $_ ? $_ : 'none', @vals;
     },
    },
    
    cursor => {
     format => '[(<url>) ,]* 
                (auto|crosshair|default|pointer|move|e-resize|
                 ne-resize|nw-resize|n-resize|se-resize|sw-resize|
                 s-resize|w-resize|text|wait|help|progress)',
     default => 'auto',
     inherit => 1,
     list => 1,
    },
    
    direction => {
     format => 'ltr|rtl',
     default => 'ltr',
     inherit => 1,
    },
    
    display => {
     format => 'inline|block|list-item|run-in|inline-block|table|
                inline-table|table-row-group|table-header-group|
                table-footer-group|table-row|table-column-group|
                table-column|table-cell|table-caption|none',
     default => 'inline',
     inherit => 0,
    },
    
    elevation => {
     format => '<angle>|below|level|above|higher|lower',
     default => '0',
     inherit => 1,
    },
    
   'empty-cells' => {
     format => 'show|hide',
     default => 'show',
     inherit => 1,
    },
    
    float => {
     format => 'left|right|none',
     default => 'none',
     inherit => 0,
    },
    
   'font-family' => { # aka typeface
     format => '(serif|sans-serif|cursive|fantasy|monospace|
                 <str/words>)
                [,(serif|sans-serif|cursive|fantasy|monospace|
                   <str/words>)]*',
     default => 'Times, serif',
     inherit => 1,
     list => 1,
    },
    
   'font-size' => {
     format => 'xx-small|x-small|small|medium|large|x-large|xx-large|
                larger|smaller|<length>|<percentage>',
     default => 'medium',
     inherit => 1,
    },
    
   'font-style' => {
     format => 'normal|italic|oblique',
     default => 'normal',
     inherit => 1,
    },
    
   'font-variant' => {
     format => 'normal | small-caps',
     default => 'normal',
     inherit => 1,
    },
    
   'font-weight' => {
     format => 'normal|bold|bolder|lighter|
                100|200|300|400|500|600|700|800|900',
     default => 'normal',
     inherit => 1,
    },
    
    font => {
     format => "[ 'font-style' || 'font-variant' || 'font-weight' ]?
                'font-size' [ / 'line-height' ]? 'font-family'",
     special_values => {
       caption => '13px Lucida Grande, sans-serif',
       icon => '13px Lucida Grande, sans-serif',
       menu => '13px Lucida Grande, sans-serif',
      'message-box' => '13px Lucida Grande, sans-serif',
      'small-caption' => '11px Lucida Grande, sans-serif',
      'status-bar' => '10px Lucida Grande, sans-serif',
     },
     serialise => sub {
       my $p = shift;
       my $ret = '';
       for(qw/ style variant weight /) {
         length $p->{"font-$_"}
           and $ret .= $p->{"font-$_"}." ";
       }
       $ret .= length $p->{'font-size'}
               ? $p->{'font-size'}
               : 'medium';
       $ret .= "/$p->{'line-height'}" if length $p->{'line-height'};
       $ret .= " " . ($p->{'font-family'} || "Times, serif");
       $ret
     },
    },
    
    height => {
     format => '<length>|<percentage>|auto',
     default => 'auto',
     inherit => 0,
    },
    
    left => {
     format => '<length>|<percentage>|auto',
     default => 'auto',
     inherit => 0,
    },
    
   'letter-spacing' => { # aka tracking
     format => 'normal|<length>',
     default => 'normal',
     inherit => 1,
    },
    
   'line-height' => { # aka leading
     format => 'normal|<number>|<length>|<percentage>',
     default => "normal",
     inherit => 1,
    },
    
   'list-style-image' => {
     format => '<url>|none',
     default => 'none',
     inherit => 1,
    },
    
   'list-style-position' => {
     format => 'inside|outside',
     default => 'outside',
     inherit => 1,
    },
    
   'list-style-type' => {
     format => 'disc|circle|square|decimal|decimal-leading-zero|
                lower-roman|upper-roman|lower-greek|lower-latin|
                upper-latin|armenian|georgian|lower-alpha|
                upper-alpha',
     default => 'disc',
     inherit => 1,
    },
    
   'list-style' => {
     format => "'list-style-type'||'list-style-position'||
                'list-style-image'",
     serialise => sub {
       my $p = shift;
       my $ret = '';
       for(qw/ type position image /) {
         $p->{"list-style-$_"}
           and $ret .= $p->{"list-style-$_"}." ";
       }
       chop $ret;
       $ret || 'disc'
     },
    },
    
   'margin-right' => {
     format => '<length>|<percentage>|auto',
     default => '0',
     inherit => 0,
    },
   'margin-left' => {
     format => '<length>|<percentage>|auto',
     default => '0',
     inherit => 0,
    },
   'margin-top' => {
     format => '<length>|<percentage>|auto',
     default => '0',
     inherit => 0,
    },
   'margin-bottom' => {
     format => '<length>|<percentage>|auto',
     default => '0',
     inherit => 0,
    },
    
    margin => {
     format => "(<length>|<percentage>|auto)
                [ (<length>|<percentage>|auto)
                  [ (<length>|<percentage>|auto)
                    (<length>|<percentage>|auto)?
                  ]?
                ]?",
     properties => {
      'margin-top' => [1],
      'margin-right' => [2,1],
      'margin-bottom' => [3,1],
      'margin-left' => [4,2,1],
     },
     serialise => sub {
       my $p = shift;
       my @vals = map $p->{"margin-$_"},
                      qw/top right bottom left/;
       $vals[3] eq $vals[1] and pop @vals,
       $vals[2] eq $vals[0] and pop @vals,
       $vals[1] eq $vals[0] and pop @vals;
       return join " ", map $_ || 0, @vals;
     },
    },
    
   'max-height' => {
     format => '<length>|<percentage>|none',
     default => 'none',
     inherit => 0,
    },
   'max-width' => {
     format => '<length>|<percentage>|none',
     default => 'none',
     inherit => 0,
    },
   'min-height' => {
     format => '<length>|<percentage>|none',
     default => 'none',
     inherit => 0,
    },
   'min-width' => {
     format => '<length>|<percentage>|none',
     default => 'none',
     inherit => 0,
    },
    
    orphans => {
     format => '<integer>',
     default => 2,
     inherit => 1,
    },
    
   'outline-color' => {
     format => '<colour>|invert',
     default => 'invert',
     inherit => 0,
    },
    
   'outline-style' => {
     format => 'none|hidden|dotted|dashed|solid|double|groove|ridge|
                inset|outset',
     default => 'none',
     inherit => 0,
    },
    
   'outline-width' => {
     format => '<length>|thin|thick|medium',
     default => 'medium',
     inherit => 0,
    },
    
    outline => {
     format => "'outline-color'||'outline-style'||'outline-width'",
     serialise => sub {
       my $p = shift;
       my $ret = '';
       for(qw/ color style width /) {
         length $p->{"outline-$_"}
           and $ret .= $p->{"outline-$_"}." ";
       }
       chop $ret;
       length $ret ? $ret : 'invert';
     },
    },
    
    overflow => {
     format => 'visible|hidden|scroll|auto',
     default => 'visible',
     inherit => 0,
    },
    
   'padding-top' => {
     format => '<length>|<percentage>',
     default => 0,
     inherit => 0,
    },
   'padding-right' => {
     format => '<length>|<percentage>',
     default => 0,
     inherit => 0,
    },
   'padding-bottom' => {
     format => '<length>|<percentage>',
     default => 0,
     inherit => 0,
    },
   'padding-left' => {
     format => '<length>|<percentage>',
     default => 0,
     inherit => 0,
    },
    
    padding => {
     format => "(<length>|<percentage>)
                [ (<length>|<percentage>)
                  [ (<length>|<percentage>)
                    (<length>|<percentage>)?
                  ]?
                ]?",
     properties => {
      'padding-top' => [1],
      'padding-right' => [2,1],
      'padding-bottom' => [3,1],
      'padding-left' => [4,2,1],
     },
     serialise => sub {
       my $p = shift;
       my @vals = map $p->{"padding-$_"},
                      qw/top right bottom left/;
       $vals[3] eq $vals[1] and pop @vals,
       $vals[2] eq $vals[0] and pop @vals,
       $vals[1] eq $vals[0] and pop @vals;
       return join " ", map $_ || 0, @vals;
     },
    },
    
   'page-break-after' => {
     format => 'auto|always|avoid|left|right',
     default => 'auto',
     inherit => 0,
    },
   'page-break-before' => {
     format => 'auto|always|avoid|left|right',
     default => 'auto',
     inherit => 0,
    },
    
   'page-break-inside' => {
     format => 'avoid|auto',
     default => 'auto',
     inherit => 1,
    },
    
   'pause-after' => {
      format => '<time>|<percentage>',
      default => 0,
      inherit => 0,
    },
   'pause-before' => {
      format => '<time>|<percentage>',
      default => 0,
      inherit => 0,
    },
    
    pause => {
     format => '(<time>|<percentage>)(<time>|<percentage>)?',
     properties => {
      'pause-before' => [1],
      'pause-after' => [2,1],
     }
    },
    
   'pitch-range' => {
     format => '<number>',
     default => 50,
     inherit => 1,
    },
    
    pitch => {
     format => '<frequency>|x-low|low|medium|high|x-high',
     default => 'medium',
     inherit => 1,
    },
    
   'play-during' => {
      format => '<url> [ mix || repeat ]? | auto | none',
      default => 'auto',
      inherit => 0,
    },
    
    position => {
     format => 'static|relative|absolute|fixed',
     default => 'relative',
     inherit => 0,
    },
    
    quotes => {
     format => '[(<string>)(<string>)]+|none',
     default => 'none',
     inherit => 1,
     list => 1,
    },
    
    richness => {
     format => '<number>',
     default => 50,
     inherit => 1,
    },
    
    right => {
     format => '<length>|<percentage>|auto',
     default => 'auto',
     inherit => 0,
    },
    
   'speak-header' => {
     format => 'once|always',
     default => 'once',
     inherit => 1,
    },
    
   'speak-numeral' => {
     format => 'digits|continuous',
     default => 'continuous',
     inherit => 1,
    },
    
   'speak-punctuation' => {
     format => 'code|none',
     default => 'none',
     inherit => 1,
    },
    
    speak => {
     format => 'normal|none|spell-out',
     default => 'normal',
     inherit => 1,
    },
    
   'speech-rate' => {
     format => '<number>|x-slow|slow|medium|fast|x-fast|faster|slower',
     default => 'medium',
     inherit => 1,
    },
    
    stress => {
     format => '<number>',
     default => 50,
     inherit => 1,
    },
    
   'table-layout' => {
     format => 'auto|fixed',
     default => 'auto',
     inherit => 0,
    },
    
   'text-align' => {
     format => 'left|right|center|justify|auto',
     default => 'auto',
     inherit => 1,
    },
    
   'text-decoration' => {
     format => 'none | underline||overline||line-through||blink ',
     default => 'none',
     inherit => 0,
    },
    
   'text-indent' => {
     format => '<length>|<percentage>',
     default => 0,
     inherit => 1,
    },
    
   'text-transform' => {
     format => 'capitalize|uppercase|lowercase|none',
     default => 'none',
     inherit => 1,
    },
    
    top => {
     format => '<length>|<percentage>|auto',
     default => 'auto',
     inherit => 0,
    },
    
   'unicode-bidi' => {
     format => 'normal|embed|bidi-override',
     default => 'normal',
     inherit => 0,
    },
    
   'vertical-align' => {
     format => 'baseline|sub|super|top|text-top|middle|bottom|
                text-bottom|<percentage>|<length>',
     default => 'baseline',
     inherit => 0,
    },
    
    visibility => {
     format => 'visible|hidden|collapse',
     default => 'visible',
     inherit => 1,
    },
    
   'voice-family' => {
     format => '(male|female|child|<str/words>)
                [, (male|female|child|<str/words>) ]*',
     default => '',
     inherit => 1,
     list => 1,
    },
    
    volume => {
     format => '<number>|<percentage>|silent|x-soft|soft|medium|loud|
                x-loud',
     default => 'medium',
     inherit => 1,
    },
    
   'white-space' =>   {
     format => 'normal|pre|nowrap|pre-wrap|pre-line',
     default => 'normal',
     inherit => 1,
    },
    
    widows => {
     format => '<integer>',
     default => 2,
     inherit => 1,
    },
    
    width => {
     format => '<length>|<percentage>|auto',
     default => 'auto',
     inherit => 0,
    },
    
   'word-spacing' => {
     format => 'normal|<length>',
     default => 'normal',
     inherit => 1,
    },
    
   'z-index' => {
     format => 'auto|<integer>',
     default => 'auto',
     inherit => 0,
    },
  );
  $CSS21->add_property( $_ => $properties{$_} ) for keys %properties;

=pod

=cut

our $Default = $CSS21;

=head1 SEE ALSO

L<CSS::DOM>