Exemplo n.º 1
0
 function enterSnipCaller(SnipCaller $node)
 {
     while (($next = $node->getNextSibling()) instanceof PlaceholderValue) {
         $node->addChild($next);
     }
     $mustValueType = false;
     if ($node->hasChilds()) {
         foreach ($node->getChilds() as $child) {
             if ($child instanceof PlaceholderValue) {
                 $mustValueType = true;
             } else {
                 if ($mustValueType) {
                     throw new SyntaxErrorException('if one placeholdervalue child exists, all children of SnipCaller must be placeholdervalue');
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 protected function parseSnipCallerAttributes(SnipCaller $node)
 {
     $normal_attributes = array();
     $named_attributes = array();
     foreach ($node->getAttributes() as $attr) {
         $name = $attr->getName();
         if ($name instanceof Text) {
             // (n=3)  -> n
             // (title)  -> title
             $name_content = $name->getContent();
         } elseif ($name instanceof InterpolatedString) {
             // @title{"desc"=>"text snip"}
             $name_content = $this->parseInterpolatedString($name);
         } elseif (is_null($name)) {
             // (#{1+1})  this is value of type Insert
             // {"abc"} this is value of InterpolatedString
         } else {
             throw new SnipCallerAttriSyntaxException(sprintf('attri value should be must be an instance of InterpolatedString or Text or be ignored , instance of %s given', get_class($value)));
         }
         $value = $attr->getValue();
         if (is_null($value)) {
             $normal_attributes[] = $name_content;
             continue;
         } elseif ($value instanceof InterpolatedString) {
             // (number="3") (class="ord-#{1+1}")  {"ok"}
             $value_content = $this->parseInterpolatedString($value);
             if (is_null($name)) {
                 $normal_attributes[] = $value_content;
                 continue;
             }
         } else {
             throw new SnipCallerAttriSyntaxException(sprintf('attri value should be must be an instance of InterpolatedString  , instance of %s given', get_class($value)));
         }
         $named_attributes[$name_content] = $value_content;
     }
     return array($normal_attributes, $named_attributes);
 }
Exemplo n.º 3
0
 protected function parseSnipCaller($buf)
 {
     $regex = '/
         @(?P<snip_name>\\w+)  # snip name ( @snipname )
         /xA';
     if ($buf->match($regex, $match)) {
         $snip_name = $match['snip_name'];
         $attributes = $this->parseSnipCallerAttributes($buf);
         $node = new SnipCaller($match['pos'][0], $snip_name, $this->env->currentMoreEnv, $attributes);
         $buf->skipWs();
         if (null !== ($nested = $this->parseStatement($buf))) {
             $node->setContent($nested);
         }
         return $node;
     }
 }