File tree 3 files changed +18
-7
lines changed
3 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -220,18 +220,26 @@ public function parseCharacter($bIsForIdentifier)
220
220
}
221
221
222
222
/**
223
- * @return array<int, Comment>|void
223
+ * Consumes whitespace and comments and returns the comments.
224
+ * If $withoutComment is true, only whitespace is consumed.
225
+ *
226
+ * @param bool $withoutComment Do not consume comments, only whitespace.
227
+ *
228
+ * @return array<int, Comment>|void List of comments.
224
229
*
225
230
* @throws UnexpectedEOFException
226
231
* @throws UnexpectedTokenException
227
232
*/
228
- public function consumeWhiteSpace (): array
233
+ public function consumeWhiteSpace (bool $ withoutComment = false ): array
229
234
{
230
235
$ aComments = [];
231
236
do {
232
237
while (\preg_match ('/ \\s/isSu ' , $ this ->peek ()) === 1 ) {
233
238
$ this ->consume (1 );
234
239
}
240
+ if ($ withoutComment ) {
241
+ break ;
242
+ }
235
243
if ($ this ->oParserSettings ->bLenientParsing ) {
236
244
try {
237
245
$ oComment = $ this ->consumeComment ();
Original file line number Diff line number Diff line change @@ -105,7 +105,7 @@ public static function parse(ParserState $oParserState): Rule
105
105
while ($ oParserState ->comes ('; ' )) {
106
106
$ oParserState ->consume ('; ' );
107
107
}
108
- $ oParserState ->consumeWhiteSpace ();
108
+ $ oParserState ->consumeWhiteSpace (true );
109
109
110
110
return $ oRule ;
111
111
}
Original file line number Diff line number Diff line change @@ -1161,13 +1161,16 @@ public function commentExtracting(): void
1161
1161
*/
1162
1162
public function flatCommentExtracting (): void
1163
1163
{
1164
- $ parser = new Parser ('div {/*Find Me!*/left:10px; text-align:left;} ' );
1164
+ $ parser = new Parser ('div {/*Find Me!*/left:10px; /*Find Me Too!*/ text-align:left;} ' );
1165
1165
$ doc = $ parser ->parse ();
1166
1166
$ contents = $ doc ->getContents ();
1167
1167
$ divRules = $ contents [0 ]->getRules ();
1168
- $ comments = $ divRules [0 ]->getComments ();
1169
- self ::assertCount (1 , $ comments );
1170
- self ::assertSame ('Find Me! ' , $ comments [0 ]->getComment ());
1168
+ $ rule1Comments = $ divRules [0 ]->getComments ();
1169
+ $ rule2Comments = $ divRules [1 ]->getComments ();
1170
+ self ::assertCount (1 , $ rule1Comments );
1171
+ self ::assertCount (1 , $ rule2Comments );
1172
+ self ::assertEquals ('Find Me! ' , $ rule1Comments [0 ]->getComment ());
1173
+ self ::assertEquals ('Find Me Too! ' , $ rule2Comments [0 ]->getComment ());
1171
1174
}
1172
1175
1173
1176
/**
You can’t perform that action at this time.
0 commit comments