/**
  * Converts the string into it's original representation without converting
  * the special character combinations.
  *
  * This method is overridden from the original Zend Pretty Printer because
  * the original returns the strings as interpreted by PHP-Parser.
  * Since we do not want such conversions we take the original that is
  * injected by our own custom Lexer.
  *
  * @param String $node The node to return a string
  *     representation of.
  *
  * @see Lexer where the originalValue is injected.
  *
  * @return string
  */
 public function pScalar_String(String_ $node)
 {
     if (method_exists($this, 'pSafe')) {
         return $this->pSafe($node->getAttribute('originalValue'));
     }
     return $this->pNoIndent($node->getAttribute('originalValue'));
 }
Exemple #2
0
 public function pScalar_String(Scalar\String_ $node)
 {
     $kind = $node->getAttribute('kind', Scalar\String_::KIND_SINGLE_QUOTED);
     switch ($kind) {
         case Scalar\String_::KIND_NOWDOC:
             $label = $node->getAttribute('docLabel');
             if ($label && !$this->containsEndLabel($node->value, $label)) {
                 if ($node->value === '') {
                     return $this->pNoIndent("<<<'{$label}'\n{$label}") . $this->docStringEndToken;
                 }
                 return $this->pNoIndent("<<<'{$label}'\n{$node->value}\n{$label}") . $this->docStringEndToken;
             }
             /* break missing intentionally */
         /* break missing intentionally */
         case Scalar\String_::KIND_SINGLE_QUOTED:
             return '\'' . $this->pNoIndent(addcslashes($node->value, '\'\\')) . '\'';
         case Scalar\String_::KIND_HEREDOC:
             $label = $node->getAttribute('docLabel');
             if ($label && !$this->containsEndLabel($node->value, $label)) {
                 if ($node->value === '') {
                     return $this->pNoIndent("<<<{$label}\n{$label}") . $this->docStringEndToken;
                 }
                 $escaped = $this->escapeString($node->value, null);
                 return $this->pNoIndent("<<<{$label}\n" . $escaped . "\n{$label}") . $this->docStringEndToken;
             }
             /* break missing intentionally */
         /* break missing intentionally */
         case Scalar\String_::KIND_DOUBLE_QUOTED:
             return '"' . $this->escapeString($node->value, '"') . '"';
     }
     throw new \Exception('Invalid string kind');
 }
 /**
  * @param Scalar\String_ $node
  *
  * @return string
  */
 public function pScalar_String(Scalar\String_ $node)
 {
     if ($node->hasAttribute('originalValue')) {
         $string = $node->getAttribute('originalValue');
     } else {
         $string = '\'' . $this->pNoIndent(addcslashes($node->value, '\'\\')) . '\'';
     }
     return $this->color($string, SyntaxHighlighterConfig::TYPE_STRING);
 }
 protected function reduceRule379()
 {
     foreach ($this->semStack[$this->stackPos - (3 - 2)] as &$s) {
         if (is_string($s)) {
             $s = Node\Scalar\String_::parseEscapeSequences($s, null);
         }
     }
     $s = preg_replace('~(\\r\\n|\\n|\\r)\\z~', '', $s);
     if ('' === $s) {
         array_pop($this->semStack[$this->stackPos - (3 - 2)]);
     }
     $this->semValue = new Scalar\Encapsed($this->semStack[$this->stackPos - (3 - 2)], $this->startAttributeStack[$this->stackPos - (3 - 1)] + $this->endAttributes);
 }
 protected function reduceRule333()
 {
     $this->semValue = new Scalar\String_(Scalar\String_::parseDocString($this->semStack[$this->stackPos - (3 - 1)], $this->semStack[$this->stackPos - (3 - 2)]), $this->startAttributeStack[$this->stackPos - (3 - 1)] + $this->endAttributes);
 }
Exemple #6
0
 protected function reduceRule463()
 {
     foreach ($this->semStack[$this->stackPos - (3 - 2)] as $s) {
         if ($s instanceof Node\Scalar\EncapsedStringPart) {
             $s->value = Node\Scalar\String_::parseEscapeSequences($s->value, null, false);
         }
     }
     $s->value = preg_replace('~(\\r\\n|\\n|\\r)\\z~', '', $s->value);
     if ('' === $s->value) {
         array_pop($this->semStack[$this->stackPos - (3 - 2)]);
     }
     $this->semValue = new Scalar\Encapsed($this->semStack[$this->stackPos - (3 - 2)], $this->startAttributeStack[$this->stackPos - (3 - 1)] + $this->endAttributes);
 }
Exemple #7
0
 protected function reduceRule477() {
      $attrs = $this->startAttributeStack[$this->stackPos-(3-1)] + $this->endAttributes; $attrs['kind'] = strpos($this->semStack[$this->stackPos-(3-1)], "'") === false ? Scalar\String_::KIND_HEREDOC : Scalar\String_::KIND_NOWDOC; preg_match('/\A[bB]?<<<[ \t]*[\'"]?([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)[\'"]?(?:\r\n|\n|\r)\z/', $this->semStack[$this->stackPos-(3-1)], $matches); $attrs['docLabel'] = $matches[1];;
         foreach ($this->semStack[$this->stackPos-(3-2)] as $s) { if ($s instanceof Node\Scalar\EncapsedStringPart) { $s->value = Node\Scalar\String_::parseEscapeSequences($s->value, null, true); } } $s->value = preg_replace('~(\r\n|\n|\r)\z~', '', $s->value); if ('' === $s->value) array_pop($this->semStack[$this->stackPos-(3-2)]);; $this->semValue = new Scalar\Encapsed($this->semStack[$this->stackPos-(3-2)], $attrs);
 }
Exemple #8
0
 public function pScalar_String(Scalar\String_ $node)
 {
     // Cowardly refuse to touch people's multiline strings
     // It is 100% impossible for us to guarantee unchanged semantics
     // and keep single strings otherwise. How do you know they don't want
     // those 8 tabs to stay instead of them being used for indentation?
     // You don't, so...keep it. gofmt seems to refuse to touch strings as
     // well
     return $node->getAttribute('originalValue');
 }
Exemple #9
0
 public function pScalar_String(Node\Scalar\String_ $node)
 {
     $kind = $node->getAttribute('kind', Node\Scalar\String_::KIND_SINGLE_QUOTED);
     if ($kind === Node\Scalar\String_::KIND_HEREDOC || $kind === Node\Scalar\String_::KIND_NOWDOC) {
         return parent::pScalar_String($node);
     }
     return $this->pNoIndent($node->getAttribute('originalValue'));
 }