Joey Mazzarelli avatar Joey Mazzarelli committed f445ab3

pseudos without tests

Comments (0)

Files changed (17)

src/php/Trekel/Evaluator.php

     $matches->append($this->root);
     $node = $this->tree;
     do {
+      $total = count($matches);
       $staging = new Trekel_List();
       foreach ($matches as $idx => $match) {
-        $staging->appendAll($node->reduce($match, $idx));
+        $staging->appendAll($node->reduce($match, $idx, $total));
       }
       $matches = $staging;
     } while (null !== ($node = $node->getChild()));

src/php/Trekel/Node.php

     return $this->getChild();
   }
 
-  abstract public function reduce ($node, $idx);
+  abstract public function reduce ($node, $idx, $total);
 
   private $matches = null;
 
     }
   }
 
+  protected function matchNode ($node) {
+    $this->matches->append($node);
+  }
+
   protected function getMatches () {
     return $this->matches;
   }
 
-  //protected function getChildren ($node) {
-    //if (!$node) {
-      //return array();
-    //}
-    //return array($node->getChild());
-  //}
-
   protected function getParent ($node) {
     return $node->getParent();
   }

src/php/Trekel/Node/Attribute/Contains.php

 <?php
 
 class Trekel_Node_Attribute_Contains extends Trekel_Node_Attribute {
-  public function reduce ($node, $idx) { return array(); }
+  public function reduce ($node, $idx, $total) { return array(); }
 }// end Trekel_Node_Attribute_Contains

src/php/Trekel/Node/Attribute/EndsWith.php

 <?php
 
 class Trekel_Node_Attribute_EndsWith extends Trekel_Node_Attribute {
-  public function reduce ($node, $idx) { return array(); }
+  public function reduce ($node, $idx, $total) { return array(); }
 }// end Trekel_Node_Attribute_EndsWith

src/php/Trekel/Node/Attribute/Equals.php

 <?php
 
 class Trekel_Node_Attribute_Equals extends Trekel_Node_Attribute {
-  public function reduce ($node, $idx) { return array(); }
+  public function reduce ($node, $idx, $total) { return array(); }
 }// end Trekel_Node_Attribute_Equals

src/php/Trekel/Node/Attribute/Exists.php

 <?php
 
 class Trekel_Node_Attribute_Exists extends Trekel_Node_Attribute {
-  public function reduce ($node, $idx) { return array(); }
+  public function reduce ($node, $idx, $total) { return array(); }
 }// end Trekel_Node_Attribute_Exists

src/php/Trekel/Node/Attribute/NotEquals.php

 <?php
 
 class Trekel_Node_Attribute_NotEquals extends Trekel_Node_Attribute {
-  public function reduce ($node, $idx) { return array(); }
+  public function reduce ($node, $idx, $total) { return array(); }
 }// end Trekel_Node_Attribute_NotEquals

src/php/Trekel/Node/Attribute/StartsWith.php

 <?php
 
 class Trekel_Node_Attribute_StartsWith extends Trekel_Node_Attribute {
-  public function reduce ($node, $idx) { return array(); }
+  public function reduce ($node, $idx, $total) { return array(); }
 }// end Trekel_Node_Attribute_StartsWith

src/php/Trekel/Node/Pseudo.php

     }
   }
 
+  protected function matchValue ($actual, $expected, $node) {
+    $this->initMatches();
+    if ($actual === $expected) {
+      $this->matchNode($node);
+    }
+    return $this->getMatches();
+  }
+
 } // end Trekel_Node_Pseudo

src/php/Trekel/Node/Pseudo/Even.php

+
+<?php
+
+class Trekel_Node_Pseudo_Even extends Trekel_Node_Pseudo {
+  public function reduce ($node, $idx, $total) {
+    return $this->matchValue(!($idx%2), false, $node);
+  }
+}

src/php/Trekel/Node/Pseudo/First.php

 <?php
 
 class Trekel_Node_Pseudo_First extends Trekel_Node_Pseudo {
-  public function reduce ($node, $idx) { return array(); }
+  public function reduce ($node, $idx, $total) {
+    return $this->matchValue($idx, 0, $node);
+  }
 }

src/php/Trekel/Node/Pseudo/Last.php

 <?php
 
 class Trekel_Node_Pseudo_Last extends Trekel_Node_Pseudo {
-  public function reduce ($node, $idx) { return array(); }
+  public function reduce ($node, $idx, $total) {
+    return $this->matchValue($idx, $total-1, $node);
+  }
 }

src/php/Trekel/Node/Pseudo/Odd.php

+<?php
+
+class Trekel_Node_Pseudo_Odd extends Trekel_Node_Pseudo {
+  public function reduce ($node, $idx, $total) {
+    return $this->matchValue(!($idx%2), true, $node);
+  }
+}

src/php/Trekel/Node/Selector/Adjacent.php

  */
 class Trekel_Node_Selector_Adjacent extends Trekel_Node_Selector {
 
-  public function reduce ($node, $idx) {
+  public function reduce ($node, $idx, $total) {
     $this->initMatches();
     if ($parent = $node->getParent()) {
       $children = $parent->getChildren();

src/php/Trekel/Node/Selector/Child.php

 
 class Trekel_Node_Selector_Child extends Trekel_Node_Selector {
 
-  public function reduce ($node, $idx) {
+  public function reduce ($node, $idx, $total) {
     //echo "reducing: " . get_class($node) . "\n";
     //echo "ident: " . $this->getIdentifier() . "\n";
     $type = $this->getIdentifier();

src/php/Trekel/Node/Selector/Descendant.php

 
 class Trekel_Node_Selector_Descendant extends Trekel_Node_Selector {
 
-  public function reduce ($node, $idx) {
+  public function reduce ($node, $idx, $total) {
     $this->initMatches();
     $this->initQueue($node->getChildren());
     while ($node = $this->dequeue()) {

src/php/Trekel/Node/Selector/Sibling.php

 
 class Trekel_Node_Selector_Sibling extends Trekel_Node_Selector {
 
-  public function reduce ($node, $idx) {
+  public function reduce ($node, $idx, $total) {
     $this->initMatches();
     if ($parent = $node->getParent()) {
       $children = $parent->getChildren();
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.