Parse YAML contained in a PyString node.

@param \Behat\Gherkin\Node\PyStringNode $node
PyString containing text in YAML format.

@return array
Parsed YAML.
169087
public function parse(PyStringNode $node) {
    // Sanitize PyString test by removing initial indentation spaces.
    $strings = $node->getStrings();
    if ($strings) {
      preg_match('/^(\s+)/', $strings[0], $matches);
      $indentation_size = isset($matches[1]) ? strlen($matches[1]) : 0;
      foreach ($strings as $key => $string) {
        $strings[$key] = substr($string, $indentation_size);
      }
    }
    $raw = implode("\n", $strings);
    return Yaml::parse($raw);
  }
200647
public function dumpNode(BaseNode $node)
    {
        return '<?php'.PHP_EOL.PHP_EOL.'return ['.parent::dumpNode($node).PHP_EOL.'];'.PHP_EOL;
    }
107576
public function getParamTypeInfos(Node $node): array
    {
        if ($node->getDocComment() === null) {
            return [];
        }

        $phpDocInfo = $this->createPhpDocInfoFromNode($node);
        $types = $phpDocInfo->getParamTagValues();

        if ($types === []) {
            return [];
        }

        $fqnTypes = $phpDocInfo->getParamTagValues();

        $paramTypeInfos = [];
        /** @var AttributeAwareParamTagValueNode $paramTagValueNode */
        foreach ($types as $i => $paramTagValueNode) {
            $fqnParamTagValueNode = $fqnTypes[$i];

            $paramTypeInfo = new ParamTypeInfo(
                $paramTagValueNode->parameterName,
                $this->typeAnalyzer,
                $paramTagValueNode->getAttribute(Attribute::TYPE_AS_ARRAY),
                $fqnParamTagValueNode->getAttribute(Attribute::RESOLVED_NAMES)
            );

            $paramTypeInfos[$paramTypeInfo->getName()] = $paramTypeInfo;
        }

        return $paramTypeInfos;
    }
1356880
private function decodeObjectNode(\DOMNode $node): array
    {
        $data = [];
        foreach ($node->childNodes as $childNode) {
            if ($childNode instanceof \DOMText) {
                continue;
            }

            $data[$childNode->getAttribute('name')] = $this->decodeNode($childNode);
        }

        return $data;
    }
462668
private function collectDiagnostics($node)
    {
        // Get errors from the parser.
        if (($error = PhpParser\DiagnosticsProvider::checkDiagnostics($node)) !== null) {
            $range = PhpParser\PositionUtilities::getRangeFromPosition($error->start, $error->length, $this->sourceFileNode->fileContents);

            switch ($error->kind) {
                case PhpParser\DiagnosticKind::Error:
                    $severity = DiagnosticSeverity::ERROR;
                    break;
                case PhpParser\DiagnosticKind::Warning:
                default:
                    $severity = DiagnosticSeverity::WARNING;
                    break;
            }

            $this->diagnostics[] = new Diagnostic(
                $error->message,
                new Range(
                    new Position($range->start->line, $range->start->character),
                    new Position($range->end->line, $range->start->character)
                ),
                null,
                $severity,
                'php'
            );
        }

        // Check for invalid usage of $this.
        if ($node instanceof Node\Expression\Variable && $node->getName() === 'this') {
            // Find the first ancestor that's a class method. Return an error
            // if there is none, or if the method is static.
            $method = $node->getFirstAncestor(Node\MethodDeclaration::class);
            if ($method && $method->isStatic()) {
                $this->diagnostics[] = new Diagnostic(
                    "\$this can not be used in static methods.",
                    RangeFactory::fromNode($node),
                    null,
                    DiagnosticSeverity::ERROR,
                    'php'
                );
            }
        }
    }
538996
public function enterNode(Node $node)
    {
        if ($node instanceof ConstFetch || $node instanceof FuncCall) {
            $node->name = null;
        }

        if ($node instanceof FullyQualified) {
            $this->names[] = $node->toString();
        }

        return $node;
    }
1271682
public function enterNode(PhpParser\Node $node)
    {
        $attrs = $node->getAttributes();

        if ($cs = $node->getComments()) {
            $new_comments = [];

            foreach ($cs as $c) {
                if ($c instanceof PhpParser\Comment\Doc) {
                    $new_comments[] = new PhpParser\Comment\Doc(
                        $c->getText(),
                        $c->getLine() + $this->line_offset,
                        $c->getFilePos() + $this->file_offset
                    );
                } else {
                    $new_comments[] = new PhpParser\Comment(
                        $c->getText(),
                        $c->getLine() + $this->line_offset,
                        $c->getFilePos() + $this->file_offset
                    );
                }
            }

            $node->setAttribute('comments', $new_comments);
        }

        /** @psalm-suppress MixedOperand */
        $node->setAttribute('startFilePos', $attrs['startFilePos'] + $this->file_offset);
        /** @psalm-suppress MixedOperand */
        $node->setAttribute('endFilePos', $attrs['endFilePos'] + $this->file_offset);
        /** @psalm-suppress MixedOperand */
        $node->setAttribute('startLine', $attrs['startLine'] + $this->line_offset);
    }
225915
private function processNode(\SimpleXMLElement $node): array
    {
        $config = [];
        foreach ($node as $name => $value) {
            if (\preg_match('/^num__([0-9]+)$/', $name, $matches)) {
                $name = $matches[1];
            }
            if ($value->count() > 0) {
                $config[$name] = $this->processNode($value->children());
            } else {
                $value = (string)$value;
                $config[$name] = $value;

                if (\preg_match('/^[0-9]+$/', $value)) {
                    $config[$name] = (int)$value;
                } elseif (\preg_match('/^[0-9\.]+$/', $value)) {
                    $config[$name] = (float)$value;
                } elseif (\preg_match('/^true|false$/', $value)) {
                    $config[$name] = $value === 'true' ? true : false;
                }
            }
        }
        return $config;
    }
849123
protected function buildString($node) {
        $self=$this;

        return preg_replace_callback(
            '/\{\-(.+?)\-\}|\{\{(.+?)\}\}(\n+)?/s',
            function($expr) use($self) {
                if ($expr[1])
                    return $expr[1];
                $str=trim($self->token($expr[2]));
                if (preg_match('/^([^|]+?)\h*\|(\h*\w+(?:\h*[,;]\h*\w+)*)/',
                    $str,$parts)) {
                    $str=$parts[1];
                    foreach (Base::instance()->split($parts[2]) as $func)
                        $str=$self->filter($func).'('.$str.')';
                }
                return '<?php echo '.$str.'; ?>'.
                    (isset($expr[3])?$expr[3]."\n":'');
            },
            preg_replace_callback(
                '/\{~(.+?)~\}/s',
                function($expr) use($self) {
                    return '<?php '.$self->token($expr[1]).' ?>';
                },
                $node
            )
        );
    }
1214444
public function parseXml($node)
    {
        foreach ($node->childNodes as $item) {
            switch ($item->nodeName) {
                case "day_entry":
                    $this->_dayEntry = new DayEntry();
                    $this->_dayEntry->parseXml( $node );
                break;
                case "hours_for_previously_running_timer":
                    $this->_hoursForPrevious = $item->nodeValue;
                break;
                default:
                break;
            }
        }
    }
763281
public function parse($node, $command)
    {
        if ($node->command() === '+') {
            $topic = synapse()->memory->shortTerm()->get('topic') ?: 'random';
            $topic = synapse()->brain->topic($topic);
            $type  = $this->determineTriggerType($node->value());

            $data = [
                'type'      => $type,
                'responses' => [],
            ];

            $topic->triggers->put($node->value(), $data);

            $topic->triggers = $this->sortTriggers($topic->triggers);

            synapse()->memory->shortTerm()->put('trigger', $node->value());
        }
    }
498841
public function enterNode(Node $node): Node
    {
        if (false === ($node instanceof Const_)) {
            return $node;
        }

        foreach ($node->consts as $constant) {
            /** @var Node\Const_ $constant */
            $resolvedConstantName = $this->nameResolver->resolveName(
                new Name(
                    (string) $constant->name,
                    $node->getAttributes()
                )
            )->getName();

            if (false === $this->whitelist->isSymbolWhitelisted((string) $resolvedConstantName, true)) {
                continue;
            }

            if (count($node->consts) > 1) {
                throw new UnexpectedValueException(
                    'Whitelisting a constant declared in a grouped constant statement (e.g. `const FOO = '
                    .'\'foo\', BAR = \'bar\'; is not supported. Consider breaking it down in multiple constant '
                    .'declaration statements'
                );
            }

            return new Expression(
                new FuncCall(
                    new FullyQualified('define'),
                    [
                        new Arg(
                            new String_((string) $resolvedConstantName)
                        ),
                        new Arg($constant->value),
                    ]
                )
            );
        }

        return $node;
    }
342057
private function decodeArrayNode(\DOMNode $node): array
    {
        $data = [];
        foreach ($node->childNodes as $childNode) {
            if ($childNode instanceof \DOMText) {
                continue;
            }

            $data[] = $this->decodeNode($childNode);
        }

        return $data;
    }
512427
protected function parseNode(NodeInterface $node)
    {
        return (object)[
            'type'       => $this->parseNodeType($node),
            'id'         => $node->getId() ?: null,
            'properties' => $this->parseNodeProperties($node),
        ];
    }
835154
protected function getRelevantNodeText($node)
    {
        if (!$node->hasChildNodes()) {
            return $node->innertext();
        }

        $output = '';
        foreach ($node->nodes as $child) {
            /* @var $child \simple_html_dom_node */
            if (!$child->hasChildNodes()) {
                $output .= $child->outertext();
            } elseif (in_array($child->nodeName(), static::$listContentTags, true)) {
                $output .= sprintf('<%1$s>%2$s</%1$s>', $child->nodeName(), $this->getRelevantNodeText($child));
            }
        }

        return $output;
    }
1039568
private function parseLevel($node) {
    if ($this->tryMatch('(', $node, 'openParen')) {
      $this->mustMatch(T_LNUMBER, $node, 'level');
      $this->mustMatch(')', $node, 'closeParen');
    }
    else {
      $this->mustMatch(T_LNUMBER, $node, 'level');
    }
  }
1016841
private function generateTmlTags($node) {
        $buffer = "";
        foreach($node->childNodes as $child) {
            if ($child->nodeType == 3) {                    // text node
                $buffer = $buffer . $child->wholeText;
            } else {
                $buffer = $buffer . $this->generateTmlTags($child);
            }
        }

        $token_context = $this->generateHtmlToken($node);
        $token = $this->adjustName($node);
        $token = $this->contextualize($token, $token_context);

        $value = $this->sanitizeValue($buffer);

        if ($this->isSelfClosingNode($node))
            return '{'.$token.'}';

        if ($this->isShortToken($token, $value))
            return '['.$token.': '.$value.']';

        return '['.$token.']'.$value.'[/'.$token.']';
    }