Skip to content

Commit a8722de

Browse files
committed
Fixed issues with the pattern matchers for tokenising.
Enabled value class to understand how to parse and compile arithmetic operators.
1 parent e8e3b9f commit a8722de

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/cssdoc/cssdoc.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class cssdoc {
1111
'whitespace' => '\s++',
1212
'comment' => '\\/\\*[\d\D]*?\\*\\/',
1313
'quotes' => '(?<!\\\\)("(?:[^"\\\\]++|\\\\.)*+"|\'(?:[^\'\\\\]++|\\\\.)*+\')',
14-
'join' => '[>+~]',
1514
'comparison' => '[\^*$<>]?=', // comparison operators for media queries or attribute selectors
15+
'join' => '[>+~*\\/-]',
1616
'curlyopen' => '{',
1717
'curlyclose' => '}',
1818
'squareopen' => '\[',
@@ -23,7 +23,7 @@ class cssdoc {
2323
'colon' => ':',
2424
'semicolon' => ';',
2525
'directive' => '@[a-z-]++',
26-
'string' => '!?[^\[\]{}\(\):;,>+~\^$!" \n\r\t]++'
26+
'string' => '!?[^\[\]{}\(\):;,>+~\^$!" \n\r\t\/]++'
2727
];
2828

2929
/**

src/cssdoc/tokens/selector.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public function parse(array &$tokens) : bool {
4040
$join = ' ';
4141
}
4242
break;
43+
case 'join':
44+
if ($token['value'] != '*') {
45+
$join = $token['value'];
46+
break;
47+
}
4348
case 'string':
4449
$this->selectors[] = [
4550
'selector' => $token['value'],
@@ -102,9 +107,6 @@ public function parse(array &$tokens) : bool {
102107
case 'comma':
103108
prev($tokens);
104109
break 2;
105-
case 'join':
106-
$join = $token['value'];
107-
break;
108110
}
109111
} while (($token = next($tokens)) !== false);
110112
return !empty($this->selectors);

src/cssdoc/tokens/value.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function parse(array &$tokens) : bool {
3636
do {
3737
switch ($token['type']) {
3838
case 'string':
39+
case 'join':
3940
if ($token['value'] == '!important') {
4041
prev($tokens);
4142
break 2;
@@ -130,7 +131,7 @@ public function compile(array $options) : string {
130131
}
131132
$css .= '('.$item->compile($options).')';
132133
$join = ' ';
133-
} elseif ($item == ':') {
134+
} elseif (in_array($item, [':', '-', '+'])) {
134135
$css .= $item;
135136
$join = '';
136137
} else {

0 commit comments

Comments
 (0)