66use Sabberworm \CSS \Parsing \ParserState ;
77use Sabberworm \CSS \Parsing \SourceException ;
88use Sabberworm \CSS \Parsing \UnexpectedTokenException ;
9+ use Sabberworm \CSS \Parsing \UnexpectedEOFException ;
910use Sabberworm \CSS \Property \AtRule ;
1011use Sabberworm \CSS \Property \Charset ;
1112use Sabberworm \CSS \Property \CSSNamespace ;
@@ -97,7 +98,7 @@ private static function parseListItem(ParserState $oParserState, CSSList $oList)
9798 }
9899 }
99100 } else {
100- return DeclarationBlock::parse ($ oParserState );
101+ return DeclarationBlock::parse ($ oParserState, $ oList );
101102 }
102103 }
103104
@@ -111,14 +112,14 @@ private static function parseAtRule(ParserState $oParserState) {
111112 $ oParserState ->consumeWhiteSpace ();
112113 $ sMediaQuery = null ;
113114 if (!$ oParserState ->comes ('; ' )) {
114- $ sMediaQuery = $ oParserState ->consumeUntil ('; ' );
115+ $ sMediaQuery = trim ( $ oParserState ->consumeUntil (array ( '; ' , ParserState:: EOF )) );
115116 }
116- $ oParserState ->consume ( '; ' );
117- return new Import ($ oLocation , $ sMediaQuery , $ iIdentifierLineNum );
117+ $ oParserState ->consumeUntil ( array ( '; ' , ParserState:: EOF ), true , true );
118+ return new Import ($ oLocation , $ sMediaQuery ? $ sMediaQuery : null , $ iIdentifierLineNum );
118119 } else if ($ sIdentifier === 'charset ' ) {
119120 $ sCharset = CSSString::parse ($ oParserState );
120121 $ oParserState ->consumeWhiteSpace ();
121- $ oParserState ->consume ( '; ' );
122+ $ oParserState ->consumeUntil ( array ( '; ' , ParserState:: EOF ), true , true );
122123 return new Charset ($ sCharset , $ iIdentifierLineNum );
123124 } else if (self ::identifierIs ($ sIdentifier , 'keyframes ' )) {
124125 $ oResult = new KeyFrame ($ iIdentifierLineNum );
@@ -136,7 +137,7 @@ private static function parseAtRule(ParserState $oParserState) {
136137 $ sPrefix = $ mUrl ;
137138 $ mUrl = Value::parsePrimitiveValue ($ oParserState );
138139 }
139- $ oParserState ->consume ( '; ' );
140+ $ oParserState ->consumeUntil ( array ( '; ' , ParserState:: EOF ), true , true );
140141 if ($ sPrefix !== null && !is_string ($ sPrefix )) {
141142 throw new UnexpectedTokenException ('Wrong namespace prefix ' , $ sPrefix , 'custom ' , $ iIdentifierLineNum );
142143 }
@@ -238,10 +239,14 @@ public function remove($oItemToRemove) {
238239 * Replaces an item from the CSS list.
239240 * @param RuleSet|Import|Charset|CSSList $oItemToRemove May be a RuleSet (most likely a DeclarationBlock), a Import, a Charset or another CSSList (most likely a MediaQuery)
240241 */
241- public function replace ($ oOldItem , $ oNewItem ) {
242+ public function replace ($ oOldItem , $ mNewItem ) {
242243 $ iKey = array_search ($ oOldItem , $ this ->aContents , true );
243244 if ($ iKey !== false ) {
244- array_splice ($ this ->aContents , $ iKey , 1 , $ oNewItem );
245+ if (is_array ($ mNewItem )) {
246+ array_splice ($ this ->aContents , $ iKey , 1 , $ mNewItem );
247+ } else {
248+ array_splice ($ this ->aContents , $ iKey , 1 , array ($ mNewItem ));
249+ }
245250 return true ;
246251 }
247252 return false ;
0 commit comments