3 class CssLanguage extends HyperLanguage {
4 public function __construct() {
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'
15 $this->setExtensions(array('css'));
17 // The following does not conform to the specs but it is necessary
18 // else numbers wouldn't be recognized any more.
20 $nmchar = '[a-z0-9-]';
22 list($string, $strmod) = preg_strip(Rule::STRING);
23 $strmod = implode('', $strmod);
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'),
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/',
52 $this->addMappings(array(
53 'element' => 'keyword',
54 'id' => 'keyword type',
55 'class' => 'keyword builtin',
56 'pseudoclass' => 'preprocessor',