import
[web.mtrack] / inc / hyperlight / css.php
1 <?php
2
3 class CssLanguage extends HyperLanguage {
4     public function __construct() {
5         $this->setInfo(array(
6             parent::NAME => 'CSS',
7             parent::VERSION => '0.8',
8             parent::AUTHOR => array(
9                 parent::NAME => 'Konrad Rudolph',
10                 parent::WEBSITE => 'madrat.net',
11                 parent::EMAIL => 'konrad_rudolph@madrat.net'
12             )
13         ));
14
15         $this->setExtensions(array('css'));
16
17         // The following does not conform to the specs but it is necessary
18         // else numbers wouldn't be recognized any more.
19         $nmstart = '-?[a-z]';
20         $nmchar = '[a-z0-9-]';
21         $hex = '[0-9a-f]';
22         list($string, $strmod) = preg_strip(Rule::STRING);
23         $strmod = implode('', $strmod);
24
25         $this->addStates(array(
26             'init' => array('comment', 'uri', 'meta', 'id', 'class', 'pseudoclass', 'element', 'block', 'constraint', 'string'),
27             'block' => array('comment', 'attribute', 'value'),
28             'constraint' => array('identifier', 'string'),
29             'value' => array('comment', 'string', 'color', 'number', 'uri', 'identifier', 'important'),
30         ));
31
32         $this->addRules(array(
33             'attribute' => "/$nmstart$nmchar*/i",
34             'value' => new Rule('/:/', '/;|(?=\})/'),
35             'comment' => Rule::C_MULTILINECOMMENT,
36             'meta' => "/@$nmstart$nmchar*/i",
37             'id' => "/#$nmstart$nmchar*/i",
38             'class' => "/\.$nmstart$nmchar*/",
39             // Pay attention not to match rules such as ::selection!
40             'pseudoclass' => "/(?<!:):$nmstart$nmchar*/",
41             'element' => "/$nmstart$nmchar*/i",
42             'block' => new Rule('/\{/', '/\}/'),
43             'constraint' => new Rule('/\[/', '/\]/'),
44             'number' => '/[+-]?(?:\d+(\.\d+)?|\d*\.\d+)(%|em|ex|px|pt|in|cm|mm|pc|deg|g?rad|m?s|k?Hz)?/',
45             'uri' => "/url\(\s*(?:$string|[^\)]*)\s*\)/$strmod",
46             'identifier' => "/$nmstart$nmchar*/i",
47             'string' => "/$string/$strmod",
48             'color' => "/#$hex{3}(?:$hex{3})?/i",
49             'important' => '/!\s*important/',
50         ));
51
52         $this->addMappings(array(
53             'element' => 'keyword',
54             'id' => 'keyword type',
55             'class' => 'keyword builtin',
56             'pseudoclass' => 'preprocessor',
57             'block' => '',
58             'constraint' => '',
59             'value' => '',
60             'color' => 'string',
61             'uri' => 'char',
62             'meta' => 'keyword',
63         ));
64     }
65 }
66
67 ?>