Esempio n. 1
0
 public function visit(Element $element, &$handle = null, $eldnah = null)
 {
     if (null !== ($value = $element->getValue())) {
         return $this->visitToken($value['token'], $value['value']);
     }
     return $this->visitNode($element);
 }
Esempio n. 2
0
 /**
  * Visit an element.
  *
  * @param   \Hoa\Visitor\Element  $element    Element to visit.
  * @param   mixed                 &$handle    Handle (reference).
  * @param   mixed                 $eldnah     Handle (not reference).
  * @return  string
  */
 public function visit(Visitor\Element $element, &$handle = null, $eldnah = null)
 {
     $pre = null;
     $in = '> ' . str_repeat('  ', $this->_i) . $element->getValue() . "\n";
     $post = null;
     $childs = $element->getChilds();
     $i = 0;
     $max = floor(count($childs) / 2);
     ++$this->_i;
     foreach ($childs as $id => $child) {
         if ($i++ < $max) {
             $pre .= $child->accept($this, $handle, $eldnah);
         } else {
             $post .= $child->accept($this, $handle, $eldnah);
         }
     }
     --$this->_i;
     switch ($this->getOrder()) {
         case parent::IN_ORDER:
             return $in . $pre . $post;
         case parent::POST_ORDER:
             return $post . $in . $pre;
         default:
             return $pre . $in . $post;
     }
 }
Esempio n. 3
0
 /**
  * Visit an element.
  *
  * @param   \Hoa\Visitor\Element  $element    Element to visit.
  * @param   mixed                &$handle     Handle (reference).
  * @param   mixed                 $eldnah     Handle (not reference).
  * @return  string
  */
 public function visit(Visitor\Element $element, &$handle = null, $eldnah = null)
 {
     $ou = null;
     $t = null;
     if ($this->_i == 0) {
         $ou = 'digraph {' . "\n";
         $t = '}' . "\n";
     }
     $foo = $element->getValue();
     $bar = null;
     ++$this->_i;
     if (null == $eldnah) {
         $eldnah = $foo;
         $ou .= '    "' . md5($foo) . '" [label = "' . $foo . '"];' . "\n";
     }
     foreach ($element->getChilds() as $child) {
         $left = md5($eldnah);
         $right = md5($eldnah . '.' . $child->getValue());
         $ou .= '    "' . $left . '" -> "' . $right . '";' . "\n" . '    "' . $right . '" [label = "' . str_replace('\\', '\\\\', $child->getValue()) . '"];' . "\n";
         $bar .= $child->accept($this, $handle, $eldnah . '.' . $child->getValue());
     }
     $ou .= $bar;
     --$this->_i;
     return $ou . $t;
 }
Esempio n. 4
0
 /**
  * Visit an element.
  *
  * @param   \Hoa\Visitor\Element  $element    Element to visit.
  * @param   mixed                 &$handle    Handle (reference).
  * @param   mixed                 $eldnah     Handle (not reference).
  * @return  mixed
  */
 public function visit(Visitor\Element $element, &$handle = null, $eldnah = null)
 {
     ++self::$_i;
     $out = str_repeat('>  ', self::$_i) . $element->getId();
     if (null !== ($value = $element->getValue())) {
         $out .= '(' . ('default' !== $value['namespace'] ? $value['namespace'] . ':' : '') . $value['token'] . ', ' . $value['value'] . ')';
     }
     $data = $element->getData();
     if (!empty($data)) {
         $out .= ' ' . $this->dumpData($data);
     }
     $out .= "\n";
     foreach ($element->getChildren() as $child) {
         $out .= $child->accept($this, $handle, $eldnah);
     }
     --self::$_i;
     return $out;
 }
Esempio n. 5
0
 /**
  * Visit an element.
  *
  * @access  public
  * @param   \Hoa\Visitor\Element  $element    Element to visit.
  * @param   mixed                 &$handle    Handle (reference).
  * @param   mixed                 $eldnah     Handle (not reference).
  * @return  mixed
  */
 public function visit(\Hoa\Visitor\Element $element, &$handle = null, $eldnah = null)
 {
     $graphic = null;
     $id = str_replace('#', '', $element->getId());
     #$graphicCreator = \Hoathis\GraphicTools\SvgCreator::getInstance();
     switch ($id) {
         case 'expression':
             $graphic = $this->graphicCreator->createExpression();
             break;
         case 'quantification':
             $graphic = $this->graphicCreator->createQuantification();
             break;
         case 'alternation':
             $graphic = $this->graphicCreator->createAlternation();
             break;
         case 'concatenation':
             $graphic = $this->graphicCreator->createConcatenation();
             break;
         case 'class':
             $graphic = $this->graphicCreator->createClass();
             break;
         case 'negativeclass':
             $graphic = $this->graphicCreator->createNegativeClass();
             break;
         case 'range':
             $graphic = $this->graphicCreator->createRange();
             break;
         case 'token':
             $value = $element->getValue();
             $graphic = $this->graphicCreator->createToken($value['token'], $value['value']);
             break;
         case 'lookahead':
             $graphic = $this->graphicCreator->createLookahead();
             break;
         case 'negativelookahead':
             $graphic = $this->graphicCreator->createNegativeLookahead();
             break;
         case 'lookbehind':
             $graphic = $this->graphicCreator->createLookbehind();
             break;
         case 'negativelookbehind':
             $graphic = $this->graphicCreator->createNegativeLookbehind();
             break;
         case 'absolutecondition':
             // Still under construction
             throw new \Exception(' \\Hoathis\\Regex\\Visitor\\Visualization exception : Unhandled element "#' . $id . '" ');
             //$graphic = $this->graphicCreator->createAbsoluteCondition();
             break;
         default:
             throw new \Exception(' \\Hoathis\\Regex\\Visitor\\Visualization exception : Unhandled element "#' . $id . '" ');
     }
     $graphic->setAttribute("class", $id);
     foreach ($element->getChildren() as $child) {
         $childGraphic = $child->accept($this, $handle, $eldnah);
         $graphic->addChild($childGraphic);
     }
     if ($id == 'expression') {
         return $graphic->build();
     } else {
         return $graphic;
     }
 }
Esempio n. 6
0
 /**
  * Visit an element.
  *
  * @param   \Hoa\Visitor\Element  $element    Element to visit.
  * @param   mixed                 &$handle    Handle (reference).
  * @param   mixed                 $eldnah     Handle (not reference).
  * @return  mixed
  */
 public function visit(Visitor\Element $element, &$handle = null, $eldnah = null)
 {
     $out = null;
     $_ = str_repeat('    ', $this->_indentation);
     if ($element instanceof Ruler\Model) {
         $this->_indentation = 1;
         $out = '$model = new \\Hoa\\Ruler\\Model();' . "\n" . '$model->expression =' . "\n" . $element->getExpression()->accept($this, $handle, $eldnah) . ';';
     } elseif ($element instanceof Ruler\Model\Operator) {
         $out = $_ . '$model->';
         $name = $element->getName();
         $_handle = [];
         if (false === $element->isFunction()) {
             if (true === Core\Consistency::isIdentifier($name)) {
                 $out .= $name;
             } else {
                 $out .= '{\'' . $name . '\'}';
             }
             $out .= '(' . "\n";
         } else {
             $out .= 'func(' . "\n" . $_ . '    ';
             $_handle[] = '\'' . $name . '\'';
         }
         ++$this->_indentation;
         foreach ($element->getArguments() as $argument) {
             $_handle[] = $argument->accept($this, $handle, $eldnah);
         }
         --$this->_indentation;
         $out .= implode(',' . "\n", $_handle) . "\n" . $_ . ')';
     } elseif ($element instanceof Ruler\Model\Bag\Scalar) {
         $value = $element->getValue();
         $out = $_;
         if (true === $value) {
             $out .= 'true';
         } elseif (false === $value) {
             $out .= 'false';
         } elseif (null === $value) {
             $out .= 'null';
         } elseif (is_numeric($value)) {
             $out .= (string) $value;
         } else {
             $out .= '\'' . str_replace('\\', '\\\'', $value) . '\'';
         }
     } elseif ($element instanceof Ruler\Model\Bag\RulerArray) {
         $values = [];
         ++$this->_indentation;
         foreach ($element->getArray() as $value) {
             $values[] = $value->accept($this, $handle, $eldnah);
         }
         --$this->_indentation;
         $out = $_ . '[' . "\n" . implode(',' . "\n", $values) . "\n" . $_ . ']';
     } elseif ($element instanceof Ruler\Model\Bag\Context) {
         $out = $_ . '$model->variable(\'' . $element->getId() . '\')';
         $this->_indentation += 2;
         foreach ($element->getDimensions() as $dimension) {
             $value = $dimension[Ruler\Model\Bag\Context::ACCESS_VALUE];
             $out .= "\n" . $_ . '    ->';
             switch ($dimension[Ruler\Model\Bag\Context::ACCESS_TYPE]) {
                 case Ruler\Model\Bag\Context::ARRAY_ACCESS:
                     $out .= 'index(' . "\n" . $value->accept($this, $handle, $eldnah) . "\n" . $_ . '    )';
                     break;
                 case Ruler\Model\Bag\Context::ATTRIBUTE_ACCESS:
                     $out .= 'attribute(\'' . $value . '\')';
                     break;
                 case Ruler\Model\Bag\Context::METHOD_ACCESS:
                     $out .= 'call(' . "\n" . $value->accept($this, $handle, $eldnah) . "\n" . $_ . '    )';
                     break;
             }
         }
         $this->_indentation -= 2;
     }
     return $out;
 }
Esempio n. 7
0
 /**
  * Visit an element.
  *
  * @param   \Hoa\Visitor\Element  $element    Element to visit.
  * @param   mixed                 &$handle    Handle (reference).
  * @param   mixed                 $eldnah     Handle (not reference).
  * @return  mixed
  */
 public function visit(Visitor\Element $element, &$handle = null, $eldnah = null)
 {
     $out = null;
     if ($element instanceof Ruler\Model) {
         $out .= $element->getExpression()->accept($this, $handle, $eldnah);
     } elseif ($element instanceof Ruler\Model\Operator) {
         $name = $element->getName();
         $arguments = [];
         foreach ($element->getArguments() as $argument) {
             $arguments[] = $argument->accept($this, $handle, $eldnah);
         }
         if (true === $element->isFunction()) {
             $out .= $name . '(' . implode(', ', $arguments) . ')';
         } else {
             if (!isset($arguments[1])) {
                 $_out = $name . ' ' . $arguments[0];
             } else {
                 $_out = $arguments[0] . ' ' . $name . ' ' . $arguments[1];
             }
             if (false === Ruler\Model\Operator::isToken($name)) {
                 $_out = '(' . $_out . ')';
             }
             $out .= $_out;
         }
     } elseif ($element instanceof Ruler\Model\Bag\Scalar) {
         $value = $element->getValue();
         if (true === $value) {
             $out .= 'true';
         } elseif (false === $value) {
             $out .= 'false';
         } elseif (null === $value) {
             $out .= 'null';
         } elseif (is_numeric($value)) {
             $out .= (string) $value;
         } else {
             $out .= '\'' . str_replace('\\', '\\\'', $value) . '\'';
         }
     } elseif ($element instanceof Ruler\Model\Bag\RulerArray) {
         $values = [];
         foreach ($element->getArray() as $value) {
             $values[] = $value->accept($this, $handle, $eldnah);
         }
         $out .= '[' . implode(', ', $values) . ']';
     } elseif ($element instanceof Ruler\Model\Bag\Context) {
         $out .= $element->getId();
         foreach ($element->getDimensions() as $dimension) {
             $value = $dimension[Ruler\Model\Bag\Context::ACCESS_VALUE];
             switch ($dimension[Ruler\Model\Bag\Context::ACCESS_TYPE]) {
                 case Ruler\Model\Bag\Context::ARRAY_ACCESS:
                     $out .= '[' . $value->accept($this, $handle, $eldnah) . ']';
                     break;
                 case Ruler\Model\Bag\Context::ATTRIBUTE_ACCESS:
                     $out .= '.' . $value;
                     break;
                 case Ruler\Model\Bag\Context::METHOD_ACCESS:
                     $out .= '.' . $value->accept($this, $handle, $eldnah);
                     break;
             }
         }
     }
     return $out;
 }