public function hardcoreTreeProcess(ioptNode $node)
 {
     foreach ($node as $block) {
         $attributes = $block->getAttributes();
         if (!isset($attributes[3])) {
             $attributes[3] = '';
         }
         switch ($block->getType()) {
             case OPT_MASTER:
                 $this->compiler->out(str_repeat('.', $this->level) . 'MASTER: ' . $block->getName() . " (" . $attributes[3] . ")(" . $node->getName() . ")\r\n", true);
                 $this->level++;
                 break;
             case OPT_ENDER:
                 $this->level--;
                 $this->compiler->out(str_repeat('.', $this->level) . 'ENDER: ' . $block->getName() . " (" . $attributes[3] . ")(" . $node->getName() . ")\r\n", true);
                 break;
             case OPT_COMMAND:
                 $this->compiler->out(str_repeat('.', $this->level) . 'CMD: ' . $block->getName() . " (" . $attributes[3] . ")(" . $node->getName() . ")\r\n", true);
                 break;
             case OPT_ALT:
                 $this->compiler->out(str_repeat('.', $this->level - 1) . 'ALT: ' . $block->getName() . " (" . $attributes[3] . ")(" . $node->getName() . ")\r\n", true);
                 break;
         }
         foreach ($block as $subNode) {
             if ($node->getType() != OPT_TEXT) {
                 $this->hardcoreTreeProcess($subNode);
             }
         }
     }
 }
 public function debugNodeProcess(ioptNode $node)
 {
     echo '<ul>';
     switch ($node->getType()) {
         case OPT_ROOT:
             echo '<li>Root';
             $this->debugBlockProcess($node->getFirstBlock());
             echo '</li>';
             break;
         case OPT_TEXT:
             echo '<li>Text</li>';
             break;
         case OPT_EXPRESSION:
             echo '<li>Expression: ' . $node->getFirstBlock()->getAttributes() . '</li>';
             break;
         case OPT_ATTRIBUTE:
             echo '<li>Attribute: ' . $node->getName() . '(' . $node->getFirstBlock()->getAttributes() . ')</li>';
             break;
         case OPT_INSTRUCTION:
             echo '<li>Instruction: ' . $node->getName();
             foreach ($node as $block) {
                 $this->debugBlockProcess($block);
             }
             echo '</li>';
             break;
         case OPT_COMPONENT:
             echo '<li>Component: ' . $node->getName();
             foreach ($node as $block) {
                 $this->debugBlockProcess($block);
             }
             echo '</li>';
             break;
         case OPT_UNKNOWN:
             echo '<li>Unknown: ' . $node->getName();
             foreach ($node as $block) {
                 $this->debugBlockProcess($block);
             }
             echo '</li>';
             break;
     }
     echo '</ul>';
 }
 public function instructionNodeProcess(ioptNode $node)
 {
     static $cid;
     if ($cid == NULL) {
         $cid = 0;
     }
     // we always use the first block in this case
     $block = $node->getFirstBlock();
     $condBegin = 0;
     $componentLink = '';
     // do we have an undefined component?
     if ($block->getName() == 'component') {
         $params = array('id' => array(OPT_PARAM_REQUIRED, OPT_PARAM_EXPRESSION), 'datasource' => array(OPT_PARAM_OPTIONAL, OPT_PARAM_EXPRESSION, NULL), '__UNKNOWN__' => array(OPT_PARAM_OPTIONAL, OPT_PARAM_EXPRESSION, NULL));
         $args = $this->compiler->parametrize($node->getName(), $block->getAttributes(), $params);
         $code = ' if(' . $params['id'] . ' instanceof ioptComponent){ ';
         $componentLink = $params['id'];
         $condBegin = 1;
     } else {
         $params = array('datasource' => array(OPT_PARAM_OPTIONAL, OPT_PARAM_EXPRESSION, NULL), '__UNKNOWN__' => array(OPT_PARAM_OPTIONAL, OPT_PARAM_EXPRESSION, NULL));
         $args = $this->compiler->parametrize($block->getName(), $block->getAttributes(), $params);
         if (isset($args['name'])) {
             $code = ' $__component_' . $cid . ' = new ' . $block->getName() . '(' . $args['name'] . '); ';
         } else {
             $code = ' $__component_' . $cid . ' = new ' . $block->getName() . '(); ';
         }
         if ($params['datasource'] != NULL) {
             $code .= ' $__component_' . $cid . ' -> setDatasource(' . $params['datasource'] . '); ';
         }
         $componentLink = '$__component_' . $cid;
     }
     $code .= $componentLink . ' -> setOptInstance($this); ';
     foreach ($args as $name => $value) {
         $code .= $componentLink . ' -> set(\'' . $name . '\', ' . $value . '); ';
     }
     // let's see, what do we have inside the block
     // event table
     $events = array(0 => array(), array(), array());
     foreach ($block as $node) {
         switch ($node->getName()) {
             case 'param':
                 // parameters
                 $params = array('name' => array(OPT_PARAM_REQUIRED, OPT_PARAM_ID), 'value' => array(OPT_PARAM_REQUIRED, OPT_PARAM_EXPRESSION));
                 $this->compiler->parametrize('component parameter', $node->getFirstBlock()->getAttributes(), $params);
                 $code .= $componentLink . ' -> set(\'' . $params['name'] . '\', ' . $params['value'] . '); ';
                 break;
             case 'listItem':
                 // list items
                 $params = array('name' => array(OPT_PARAM_REQUIRED, OPT_PARAM_ID), 'value' => array(OPT_PARAM_REQUIRED, OPT_PARAM_EXPRESSION), 'selected' => array(OPT_PARAM_OPTIONAL, OPT_PARAM_EXPRESSION, 0));
                 $this->compiler->parametrize('component list element', $node->getFirstBlock()->getAttributes(), $params);
                 $code .= $componentLink . ' -> push(\'' . $params['name'] . '\', ' . $params['value'] . ', ' . $params['selected'] . '); ';
                 break;
             case 'load':
                 $params = array('event' => array(OPT_PARAM_REQUIRED, OPT_PARAM_ID));
                 $this->compiler->parametrize('event loader', $node->getFirstBlock()->getAttributes(), $params);
                 if (isset($this->compiler->genericBuffer['bindEvent'][$params['event']])) {
                     $info = $this->compiler->genericBuffer['bindEvent'][$params['event']];
                     switch ($info['position']) {
                         case 'up':
                             $events[0][$info['name']] = array(0 => $info['tree'], $info['message']);
                             break;
                         case 'mid':
                             $events[1][$info['name']] = array(0 => $info['tree'], $info['message']);
                             break;
                         case 'down':
                         default:
                             $events[2][$info['name']] = array(0 => $info['tree'], $info['message']);
                             break;
                     }
                 }
                 break;
             default:
                 if ($node->getType() == OPT_UNKNOWN) {
                     // events
                     $params = array('message' => array(OPT_PARAM_REQUIRED, OPT_PARAM_ID), 'position' => array(OPT_PARAM_OPTIONAL, OPT_PARAM_ID, 0));
                     $this->compiler->parametrize('component event', $node->getFirstBlock()->getAttributes(), $params);
                     switch ($params['position']) {
                         case 'up':
                             $events[0][$node->getName()] = array(0 => $node, $params['message']);
                             break;
                         case 'mid':
                             $events[1][$node->getName()] = array(0 => $node, $params['message']);
                             break;
                         case 'down':
                         default:
                             $events[2][$node->getName()] = array(0 => $node, $params['message']);
                             break;
                     }
                 }
         }
     }
     $this->compiler->out($code);
     // ok, now we put the events in the correct order
     foreach ($events[0] as $name => $nodeData) {
         $this->compileEvent($name, $componentLink, $nodeData);
     }
     $this->compiler->out(' ' . $componentLink . ' -> begin(); ');
     foreach ($events[1] as $name => $nodeData) {
         $this->compileEvent($name, $componentLink, $nodeData);
     }
     $this->compiler->out(' ' . $componentLink . ' -> end(); ');
     foreach ($events[2] as $name => $nodeData) {
         $this->compileEvent($name, $componentLink, $nodeData);
     }
     // terminate the processing
     if ($condBegin == 1) {
         $this->compiler->out(' } ');
     }
 }
    public function instructionNodeProcess(ioptNode $node)
    {
        $block = $node->getFirstBlock();
        $params = array('event' => array(OPT_PARAM_REQUIRED, OPT_PARAM_ID), 'for' => array(OPT_PARAM_REQUIRED, OPT_PARAM_ID));
        $variables = $this->compiler->parametrize('opf:call', $block->getAttributes(), $params);
        if (isset($this->compiler->genericBuffer['bindEvent'][$params['event']])) {
            $info = $this->compiler->genericBuffer['bindEvent'][$params['event']];
            $this->compiler->out('if(isset($this -> data[$formName] -> errorMessages[\'' . $params['for'] . '\']))
				{ $this->vars[\'' . $info['message'] . '\'] = $this -> data[$formName] -> errorMessages[\'' . $params['for'] . '\']; ');
            foreach ($info['tree'] as $block) {
                $this->defaultTreeProcess($block);
            }
            $this->compiler->out(' } ');
        }
    }