@@ -132,7 +132,7 @@ protected function makeOutputBlock($type, $selectors = null) {
132132 return $ out ;
133133 }
134134
135- protected function matchExtendsSingle ($ single , &$ out_origin, & $ out_rem ) {
135+ protected function matchExtendsSingle ($ single , &$ out_origin ) {
136136 $ counts = array ();
137137 foreach ($ single as $ part ) {
138138 if (!is_string ($ part )) return false ; // hmm
@@ -145,20 +145,30 @@ protected function matchExtendsSingle($single, &$out_origin, &$out_rem) {
145145 }
146146 }
147147
148+ $ out_origin = array ();
149+ $ found = false ;
150+
148151 foreach ($ counts as $ idx => $ count ) {
149152 list ($ target , $ origin ) = $ this ->extends [$ idx ];
153+
150154 // check count
151155 if ($ count != count ($ target )) continue ;
156+
152157 // check if target is subset of single
153158 if (array_diff (array_intersect ($ single , $ target ), $ target )) continue ;
154159
155- $ out_origin = $ origin ;
156- $ out_rem = array_diff ($ single , $ target );
160+ $ rem = array_diff ($ single , $ target );
157161
158- return true ;
162+ foreach ($ origin as $ j => $ new ) {
163+ $ origin [$ j ][count ($ origin [$ j ]) - 1 ] = $ this ->combineSelectorSingle (end ($ new ), $ rem );
164+ }
165+
166+ $ out_origin = array_merge ($ out_origin , $ origin );
167+
168+ $ found = true ;
159169 }
160170
161- return false ;
171+ return $ found ;
162172 }
163173
164174 protected function combineSelectorSingle ($ base , $ other ) {
@@ -167,7 +177,7 @@ protected function combineSelectorSingle($base, $other) {
167177
168178 foreach (array ($ base , $ other ) as $ single ) {
169179 foreach ($ single as $ part ) {
170- if (preg_match ('/^[^.#:]/ ' , $ part )) {
180+ if (preg_match ('/^[^\[ .#:]/ ' , $ part )) {
171181 $ tag = $ part ;
172182 } else {
173183 $ out [] = $ part ;
@@ -186,15 +196,13 @@ protected function matchExtends($selector, &$out, $from = 0, $initial=true) {
186196 foreach ($ selector as $ i => $ part ) {
187197 if ($ i < $ from ) continue ;
188198
189- if ($ this ->matchExtendsSingle ($ part , $ origin, $ rem )) {
199+ if ($ this ->matchExtendsSingle ($ part , $ origin )) {
190200 $ before = array_slice ($ selector , 0 , $ i );
191201 $ after = array_slice ($ selector , $ i + 1 );
192202
193203 foreach ($ origin as $ new ) {
194- $ new [count ($ new ) - 1 ] =
195- $ this ->combineSelectorSingle (end ($ new ), $ rem );
196-
197204 $ k = 0 ;
205+
198206 // remove shared parts
199207 if ($ initial ) {
200208 foreach ($ before as $ k => $ val ) {
@@ -332,7 +340,7 @@ protected function flattenSelectorSingle($single) {
332340 foreach ($ single as $ part ) {
333341 if (empty ($ joined ) ||
334342 !is_string ($ part ) ||
335- preg_match ('/[.:#%]/ ' , $ part ))
343+ preg_match ('/[\[ .:#%]/ ' , $ part ))
336344 {
337345 $ joined [] = $ part ;
338346 continue ;
@@ -1572,7 +1580,7 @@ protected function coerceString($value) {
15721580
15731581 protected function assertList ($ value ) {
15741582 if ($ value [0 ] != "list " )
1575- throw new exception ("expecting list " );
1583+ throw new Exception ("expecting list " );
15761584 return $ value ;
15771585 }
15781586
@@ -3988,7 +3996,7 @@ public function serve() {
39883996 if ($ this ->needsCompile ($ input , $ output )) {
39893997 try {
39903998 echo $ this ->compile ($ input , $ output );
3991- } catch (exception $ e ) {
3999+ } catch (Exception $ e ) {
39924000 header ('HTTP/1.1 500 Internal Server Error ' );
39934001 echo "Parse error: " . $ e ->getMessage () . "\n" ;
39944002 }
0 commit comments