@@ -92,7 +92,7 @@ private function parseAtRule() {
92
92
}
93
93
}
94
94
95
- private function parseIdentifier () {
95
+ private function parseIdentifier ($ bAllowFunctions = true ) {
96
96
$ sResult = $ this ->parseCharacter (true );
97
97
if ($ sResult === null ) {
98
98
throw new Exception ("Identifier expected, got {$ this ->peek (5 )}" );
@@ -101,6 +101,11 @@ private function parseIdentifier() {
101
101
while (($ sCharacter = $ this ->parseCharacter (true )) !== null ) {
102
102
$ sResult .= $ sCharacter ;
103
103
}
104
+ if ($ bAllowFunctions && $ this ->comes ('( ' )) {
105
+ $ this ->consume ('( ' );
106
+ $ sResult = new CSSFunction ($ sResult , $ this ->parseValue ());
107
+ $ this ->consume (') ' );
108
+ }
104
109
return $ sResult ;
105
110
}
106
111
@@ -297,13 +302,13 @@ private function parseColorValue() {
297
302
$ aColor = array ();
298
303
if ($ this ->comes ('# ' )) {
299
304
$ this ->consume ('# ' );
300
- $ sValue = $ this ->parseIdentifier ();
305
+ $ sValue = $ this ->parseIdentifier (false );
301
306
if (mb_strlen ($ sValue , $ this ->sCharset ) === 3 ) {
302
307
$ sValue = $ sValue [0 ].$ sValue [0 ].$ sValue [1 ].$ sValue [1 ].$ sValue [2 ].$ sValue [2 ];
303
308
}
304
309
$ aColor = array ('r ' => new CSSSize (intval ($ sValue [0 ].$ sValue [1 ], 16 )), 'g ' => new CSSSize (intval ($ sValue [2 ].$ sValue [3 ], 16 )), 'b ' => new CSSSize (intval ($ sValue [4 ].$ sValue [5 ], 16 )));
305
310
} else {
306
- $ sColorMode = $ this ->parseIdentifier ();
311
+ $ sColorMode = $ this ->parseIdentifier (false );
307
312
$ this ->consumeWhiteSpace ();
308
313
$ this ->consume ('( ' );
309
314
$ iLength = mb_strlen ($ sColorMode , $ this ->sCharset );
@@ -1034,3 +1039,26 @@ public function __toString() {
1034
1039
return "$ oValue1/ $ oValue2 " ;
1035
1040
}
1036
1041
}
1042
+
1043
+ class CSSFunction extends CSSValue {
1044
+ private $ sName ;
1045
+ private $ aContents ;
1046
+
1047
+ public function __construct ($ sName , $ aContents ) {
1048
+ $ this ->sName = $ sName ;
1049
+ $ this ->aContents = $ aContents ;
1050
+ }
1051
+
1052
+ public function getName () {
1053
+ return $ this ->sName ;
1054
+ }
1055
+
1056
+ public function getContents () {
1057
+ return $ this ->aContents ;
1058
+ }
1059
+
1060
+ public function __toString () {
1061
+ $ sContents = implode (', ' , $ this ->aContents );
1062
+ return "{$ this ->sName }( {$ sContents }) " ;
1063
+ }
1064
+ }
0 commit comments