File tree Expand file tree Collapse file tree 3 files changed +18
-7
lines changed Expand file tree Collapse file tree 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)
220220 }
221221
222222 /**
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.
224229 *
225230 * @throws UnexpectedEOFException
226231 * @throws UnexpectedTokenException
227232 */
228- public function consumeWhiteSpace (): array
233+ public function consumeWhiteSpace (bool $ withoutComment = false ): array
229234 {
230235 $ aComments = [];
231236 do {
232237 while (\preg_match ('/ \\s/isSu ' , $ this ->peek ()) === 1 ) {
233238 $ this ->consume (1 );
234239 }
240+ if ($ withoutComment ) {
241+ break ;
242+ }
235243 if ($ this ->oParserSettings ->bLenientParsing ) {
236244 try {
237245 $ oComment = $ this ->consumeComment ();
Original file line number Diff line number Diff line change @@ -105,7 +105,7 @@ public static function parse(ParserState $oParserState): Rule
105105 while ($ oParserState ->comes ('; ' )) {
106106 $ oParserState ->consume ('; ' );
107107 }
108- $ oParserState ->consumeWhiteSpace ();
108+ $ oParserState ->consumeWhiteSpace (true );
109109
110110 return $ oRule ;
111111 }
Original file line number Diff line number Diff line change @@ -1161,13 +1161,16 @@ public function commentExtracting(): void
11611161 */
11621162 public function flatCommentExtracting (): void
11631163 {
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;} ' );
11651165 $ doc = $ parser ->parse ();
11661166 $ contents = $ doc ->getContents ();
11671167 $ 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+ $ this ->assertCount (1 , $ rule1Comments );
1171+ $ this ->assertCount (1 , $ rule2Comments );
1172+ $ this ->assertEquals ("Find Me! " , $ rule1Comments [0 ]->getComment ());
1173+ $ this ->assertEquals ("Find Me Too! " , $ rule2Comments [0 ]->getComment ());
11711174 }
11721175
11731176 /**
You can’t perform that action at this time.
0 commit comments