Generate ASCII output code for an ExpressionNode

Create a string giving ASCII output representing an ExpressionNode `(x op y)`
where `op` is one of `+`, `-`, `*`, `/` or `^`


@retval string
@param ExpressionNode $node AST to be typeset
510276
public function visitExpressionNode(ExpressionNode $node)
    {
        $operator = $node->getOperator();
        $left = $node->getLeft();
        $right = $node->getRight();

        switch ($operator) {
            case '+':
                $leftValue = $left->accept($this);
                $rightValue = $this->parenthesize($right, $node);

                return "$leftValue+$rightValue";

            case '-':
                if ($right) {
                    // Binary minus

                    $leftValue = $left->accept($this);
                    $rightValue = $this->parenthesize($right, $node);

                    return "$leftValue-$rightValue";
                } else {
                    // Unary minus

                    $leftValue = $this->parenthesize($left, $node);

                    return "-$leftValue";
                }

            case '*':
            case '/':

                $leftValue = $this->parenthesize($left, $node, '', false);
                $rightValue = $this->parenthesize($right, $node, '', true);

                return "$leftValue$operator$rightValue";

            case '^':
                $leftValue = $this->parenthesize($left, $node, '', true);
                $rightValue = $this->parenthesize($right, $node, '', false);

                return "$leftValue$operator$rightValue";
        }
    }
1298484
public function enterNode(Node $node)
    {
        // @todo support MethodCall and StaticCall as well.
        if ($node instanceof FuncCall) {
            // if function name is an expression or a variable, give it a pass for now.
            if ($node->name instanceof Expr || $node->name instanceof Variable) {
                return;
            }

            $name = (string) $node->name;

            if ($name === 'array_multisort') {
                return $this->validateArrayMultisort($node);
            }

            try {
                $refl = new \ReflectionFunction($name);
            } catch (\ReflectionException $e) {
                // Well, we gave it a shot!
                return;
            }

            foreach ($refl->getParameters() as $key => $param) {
                if (\array_key_exists($key, $node->args)) {
                    $arg = $node->args[$key];
                    if ($param->isPassedByReference() && !$this->isPassableByReference($arg)) {
                        throw new FatalErrorException(self::EXCEPTION_MESSAGE, 0, E_ERROR, null, $node->getLine());
                    }
                }
            }
        }
    }
140946
function astValue(node) {

  switch (node.type) {

  case 'ExpressionStatement':
    return astValue(node.expression);

  case 'ObjectExpression':
    return node.properties.reduce(
      (obj, prop) => Object.assign(obj, {[prop.key.value]: astValue(prop.value)}),
      {}
    );

  case 'ArrayExpression':
    return node.elements.map(element => astValue(element));

  case 'Literal':
    return node.value;

  default:
    throw new Error(`Unexpected ast node type: ${node.type}`);

  }
}
393457
public function render(&$node)
    {
        $id = call_user_func_array([&$this, 'fetchId'], $node);
        $output = call_user_func_array([&$this, 'fetchItem'], $node);
        list ($source) = $node;
        list ($plugin) = pluginSplit($source);

        $options = [
            'id'     => $id,
            'output' => $output,
            'class'  => $node['class'],
        ];

        $element = 'Toolbar/wrapper';
        if ($plugin !== null) {
            $element = $plugin . '.' . $element;
        }

        return $this->_view->element($element, $options);
    }
673957
protected function generateNodeMarkup(Node $node) : string
    {
        if ($node instanceof TagNode) {
            // Find tad definition.
            $tag = $node->getTag();
            $tagName = $tag->getTagName();
            $tagDef = $this->tagDefs->get($tagName);

            // Recursive generate markup for the inner content.
            $children = $node->getChildren();
            $content = $this->generateMarkup($children);

            // Generate markup for this tag.
            $attribute = $tag->getAttribute();
            return $tagDef->generateMarkup($attribute, $content);
        } else {
            /** @var TextNode $node */
            return $node->getText();
        }
    }
1221099
function it_compiles_nodes_using_a_generic_solution($node)
    {
        $node->compile($this)->will(function ($args) {
            $args[0]->write('echo $message');
        });

        $this->repr($node)->getSource()->shouldMatch('/echo \$message/');
    }
822800
protected function compileMixinCall(Node $node)
    {

        $name = $node->name;
        $hasBlock = false;

        $interpolatedName = $this->interpolate($name, true);
        $interpolated = $name !== $interpolatedName;
        $name = $interpolatedName;

        if ($interpolated)
            $this->options['compile_uncalled_mixins'] = true;

        if (!$interpolated && !isset($this->mixins[$name]))
            $this->throwException(
                "A mixin with the name [$name] is not defined. Please define it with `mixin $name` before you attempt to call a it".
                "with that name.",
                $node
            );

        if (!$interpolated && !in_array($name, $this->calledMixins, true))
            $this->calledMixins[] = $name;

        $mixin = null;

        if (!$interpolated) {
            
            $mixin = $this->mixins[$name];

            if ($mixin instanceof Node) {
    
                //This is still an unhandled mixin, inside another mixin
                //Make sure to resolve circular references
                $this->handleMixin($mixin);
                $mixin = $this->mixins[$name];
            }
        }


        $phtml = '';

        if (count($node->children) > 0) {

            $hasBlock = true;
            $phtml = $this->createCode(
                '$__block = function(array $__scope) {
                    extract($__scope);
                '
            ).$this->newLine();
            $phtml .= $this->compileChildren($node->children, false).$this->newLine();
            $phtml .= $this->indent().$this->createCode('};').$this->newLine();
        }

        $nodeAttributes = $node->attributes;
        foreach ($node->assignments as $assignment) {

            $attrName = $assignment->name;

            //This line provides compatibility to the offical jade method
            if (($this->isHtml() || $this->isXml()) && $attrName === 'classes')
                $attrName = 'class';

            foreach ($assignment->attributes as $attr) {

                if (!$attr->value)
                    $attr->value = $attr->name;

                $attr->name = $attrName;
                $nodeAttributes[] = $attr;
            }
        }

        $args = [];
        $i = 0;
        foreach ($nodeAttributes as $index => $attr) {

            $value = $attr->value;

            if ($attr->name) {

                if (isset($args[$attr->name])) {

                    if (is_array($args[$attr->name]))
                        $args[$attr->name][] = $value;
                    else
                        $args[$attr->name] = [$args[$attr->name], $value];
                } else {

                    $args[$attr->name] = $value;
                }
                continue;
            }


                $mixinAttributes = !$interpolated ? $mixin['node']->attributes : null;

                if (!$interpolated && isset($mixinAttributes[$i]) && strncmp('...', $mixinAttributes[$i]->name, 3) !== 0) {

                    $args[$mixinAttributes[$i]->name] = $value;
                } else {

                    $args[] = $value;
                }
            $i++;
        }

        $phtml .= (count($node->children) > 0 ? $this->indent() : '').$this->createCode(
                '$__scope = \\Tale\\Jade\\Compiler\\create_scope(get_defined_vars()); '. 
                '$__mixinCallArgs = '.$this->exportArray($args).';'.(
                    $hasBlock ? '$__mixinCallArgs[\'__block\'] = isset($__block) ? $__block : null; ' : ''
                ).'call_user_func($__mixins[\''.$name.'\'], $__mixinCallArgs, $__scope); '.
                'unset($__scope); '.
                'unset($__mixinCallArgs); '.(
                    $hasBlock ? 'unset($__block); ' : ''
                )
            ).$this->newLine();

        return $phtml;
    }
333145
protected function htmlFromNode($node)
    {
        $domDocument = new \DOMDocument();
        $newNode = $domDocument->importNode($node, true);
        $domDocument->appendChild($newNode);

        return $domDocument->saveHTML();
    }
1319264
protected function parseNode(Node $node)
    {
        switch (true) {
            case $node instanceof Node\Stmt:
                return $this->parseStatementNode($node);

            case $node instanceof Node\Expr:
                return $this->parseExpressionNode($node);

            case $node instanceof Node\Param:
                return $this->parseParameterNode($node);

            case $node instanceof Node\Arg:
                return $this->parseArgumentNode($node);

            default:
                throw new ASTException('Unsupported node type: %s', get_class($node));
        }
    }
1350938
function isLastNode(node) {
            const token = sourceCode.getTokenAfter(node);

            return !token || (token.type === "Punctuator" && token.value === "}");
        }
1189555
public function render_node(node $node) {
        $return = '';
        if (is_object($node->url)) {
            $header = \html_writer::link($node->url, $node->title);
        } else {
            $header = $node->title;
        }
        $icon = $node->icon;
        if (!empty($icon)) {
            $header .= $this->render($icon);
        }
        $content = $node->content;
        $classes = $node->classes;
        if (!empty($content)) {
            if ($header) {
                // There is some content to display below this make this a header.
                $return = \html_writer::tag('dt', $header);
                $return .= \html_writer::tag('dd', $content);

                $return = \html_writer::tag('dl', $return);
            } else {
                $return = \html_writer::span($content);
            }
            if ($classes) {
                $return = \html_writer::tag('li', $return, array('class' => 'contentnode ' . $classes));
            } else {
                $return = \html_writer::tag('li', $return, array('class' => 'contentnode'));
            }
        } else {
            $return = \html_writer::span($header);
            $return = \html_writer::tag('li', $return, array('class' => $classes));
        }

        return $return;
    }
239533
public function leaveNode(Node $node)
    {
        if (self::isConditional($node)) {
            $this->conditionalScopes--;
        } elseif ($node instanceof FuncCall) {
            // if function name is an expression or a variable, give it a pass for now.
            $name = $node->name;
            if (!$name instanceof Expr && !$name instanceof Variable) {
                $shortName = \implode('\\', $name->parts);
                $fullName  = $this->getFullyQualifiedName($name);
                $inScope   = isset($this->currentScope[\strtolower($fullName)]);
                if (!$inScope && !\function_exists($shortName) && !\function_exists($fullName)) {
                    $message = \sprintf('Call to undefined function %s()', $name);
                    throw new FatalErrorException($message, 0, E_ERROR, null, $node->getLine());
                }
            }
        }
    }
3726
protected function compileDo(Node $node)
    {

        $subject = $node->subject;

        if (!empty($subject))
            $this->throwException(
                "Do-loops can't have a subject, they only accept children to repeat.",
                $node
            );

        if (!$node->next() || $node->next()->type !== 'while')
            $this->throwException(
                "A do-statement needs a while-statement with a condition following immediately, {$node->next()->type} was provided"
            );

        //Notice that the } wont have closing ? >, php needs this.
        //Check compileWhile to see the combination of both
        $phtml = $this->createCode("do {").$this->newLine();
        $phtml .= $this->compileChildren($node->children).$this->newLine();
        $phtml .= $this->indent().$this->createCode('}', '<?php ', '').$this->newLine();

        return $phtml;
    }
1344697
public function pExpr_Closure(Expr\Closure $node)
    {
        return sprintf(
            "%s%s %s(%s)%s%s %s%s\n%s",
            ($node->static ? 'static ' : ''),
            $this->color('function', SyntaxHighlighterConfig::TYPE_KEYWORD),
            ($node->byRef ? '&' : ''),
            $this->pCommaSeparated($node->params),
            (!empty($node->uses) ? ' use(' . $this->pCommaSeparated($node->uses) . ')': ''),
            (null !== $node->returnType ? ' : ' . $this->pType($node->returnType) : ''),
            $this->color('{', SyntaxHighlighterConfig::TYPE_BRACE),
            $this->pStmts($node->stmts),
            $this->color('}', SyntaxHighlighterConfig::TYPE_BRACE)
        );
    }
555773
protected function formatStringCellValue($node)
    {
        $pNodeValues = [];
        $pNodes = $node->getElementsByTagName(self::XML_NODE_P);

        foreach ($pNodes as $pNode) {
            $currentPValue = '';

            foreach ($pNode->childNodes as $childNode) {
                if ($childNode instanceof \DOMText) {
                    $currentPValue .= $childNode->nodeValue;
                } else if ($childNode->nodeName === self::XML_NODE_S) {
                    $spaceAttribute = $childNode->getAttribute(self::XML_ATTRIBUTE_C);
                    $numSpaces = (!empty($spaceAttribute)) ? intval($spaceAttribute) : 1;
                    $currentPValue .= str_repeat(' ', $numSpaces);
                } else if ($childNode->nodeName === self::XML_NODE_A || $childNode->nodeName === self::XML_NODE_SPAN) {
                    $currentPValue .= $childNode->nodeValue;
                }
            }

            $pNodeValues[] = $currentPValue;
        }

        $escapedCellValue = implode("\n", $pNodeValues);
        $cellValue = $this->escaper->unescape($escapedCellValue);
        return $cellValue;
    }
488611
protected function compileFilter(Node $node)
    {

        $name = $node->name;

        if (!isset($this->options['filters'][$name]))
            $this->throwException(
                "Filter $name was not defined. Make sure to add it via the [`filters`]-option or the [`->addFilter`]-method ",
                $node
            );

        $result = call_user_func($this->options['filters'][$name], $node, $this->indent(), $this->newLine(), $this);

        return $result instanceof Node ? $this->compileNode($result) : (string)$result;
    }
659604
protected function formatInlineStringCellValue($node)
    {
        // inline strings are formatted this way:
        // <c r="A1" t="inlineStr"><is><t>[INLINE_STRING]</t></is></c>
        $tNode = $node->getElementsByTagName(self::XML_NODE_INLINE_STRING_VALUE)->item(0);
        $cellValue = $this->escaper->unescape($tNode->nodeValue);
        return $cellValue;
    }