<commit_before><?php namespace LessCompiler;

/**
 * LESS compiler.
 */
class Compiler {

    /**
     * @var ScopeManager
     */
    protected $scopeManager;

    /**
     * @param Less\LessTree $tree
     * @return Css\CssTree
     */
    public function compileTree(Less\LessTree $tree)
    {
        $newTree = new Css\CssTree;

        // Init ScopeManager.
        $this->scopeManager = new Compiler\ScopeManager;

        foreach ($tree as $node) {
            if ($node instanceof Less\Statements\ImportStatement) {
                // ...
                continue;
            }

            if ($node instanceof Less\Statements\VarAssignmentStatement) {
                $this->scopeManager->getScope("global")->setVariable(
                    $node->getValue("name"),
                    $node->getValue("value")
                );

                continue;
            }

            if ($node instanceof Less\Container) {
                foreach ($this->compileContainer($node) as $container) {
                    $newTree->addNode($container);
                }
            }
        }

        return $newTree;
    }

    /**
     * @param Less\Container $container
     * @param Less\Query $query
     * @return Css\Container
     */
    protected function compileContainer(Less\Container $container, Less\Query $query = null)
    {
        $containers = [];

        if (is_null($query)) {
            $id = $container->getValue("query")->represent();
            $parentId = "global";
        } else {
            $id = $query->merge($container->getValue("query"))->represent();
            $parentId = $query->represent();
        }

        // ...and scope.
        $scope = $this->scopeManager->getScope(
            $id,
            $this->scopeManager->getScope($parentId)
        );

        // Set variables...
        foreach ($container->getValue("variables") as $variable) {
            $scope->setVariable(
                $variable->getValue("name"),
                $variable->getValue("value")
            );
        }

        // Set properties.
        $containerQuery = $container->getValue("query");

        $newContainer = new Css\Container(
            is_null($query) ? $containerQuery : $query->merge($containerQuery)
        );

        foreach ($container->getValue("properties") as $property) {
            $newContainer->addProperty(new Css\Property(
                $property->getValue("name"),
                $scope->interpolate($property->getValue("value"))
            ));
        }

        $containers[] = $newContainer;

        // Nested.
        foreach ($container->getValue("children") as $children) {
            $containers = array_merge(
                $containers,
                $this->compileContainer($children, $container->getValue("query"))
            );
        }

        return $containers;
    }
}<commit_msg>Fix a bug.<commit_after><?php namespace LessCompiler;

/**
 * LESS compiler.
 */
class Compiler {

    /**
     * @var ScopeManager
     */
    protected $scopeManager;

    /**
     * @param Less\LessTree $tree
     * @return Css\CssTree
     */
    public function compileTree(Less\LessTree $tree)
    {
        $newTree = new Css\CssTree;

        // Init ScopeManager.
        $this->scopeManager = new Compiler\ScopeManager;

        foreach ($tree as $node) {
            if ($node instanceof Less\Statements\ImportStatement) {
                // ...
                continue;
            }

            if ($node instanceof Less\Statements\VarAssignmentStatement) {
                $this->scopeManager->getScope("global")->setVariable(
                    $node->getValue("name"),
                    $node->getValue("value")
                );

                continue;
            }

            if ($node instanceof Less\Container) {
                foreach ($this->compileContainer($node) as $container) {
                    $newTree->addNode($container);
                }
            }
        }

        return $newTree;
    }

    /**
     * @param Less\Container $container
     * @param Less\Query $query
     * @return Css\Container
     */
    protected function compileContainer(Less\Container $container, Less\Query $query = null)
    {
        $containers = [];

        if (is_null($query)) {
            $id = $container->getValue("query")->represent();
            $parentId = "global";
        } else {
            $id = $query->merge($container->getValue("query"))->represent();
            $parentId = $query->represent();
        }

        // ...and scope.
        $scope = $this->scopeManager->getScope(
            $id,
            $this->scopeManager->getScope($parentId)
        );

        // Set variables...
        foreach ($container->getValue("variables") as $variable) {
            $scope->setVariable(
                $variable->getValue("name"),
                $variable->getValue("value")
            );
        }

        // Set properties.
        $containerQuery = $container->getValue("query");

        $newContainer = new Css\Container(
            is_null($query) ? $containerQuery : $query->merge($containerQuery)
        );

        foreach ($container->getValue("properties") as $property) {
            $newContainer->addProperty(new Css\Property(
                $property->getValue("name"),
                $scope->interpolate($property->getValue("value"))
            ));
        }

        $containers[] = $newContainer;

        // Nested rules.
        foreach ($container->getValue("children") as $children) {
            $containers = array_merge(
                $containers,
                $this->compileContainer(
                    $children,
                    is_null($query) ? $containerQuery : $query->merge($containerQuery)
                )
            );
        }

        return $containers;
    }
}
{'fraction_non_alphanumeric': 0.13842482100238662, 'fraction_numerical': 0.0, 'mean_word_length': 1.5880017644464048, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6486053', 'n_tokens_mistral': 1539, 'n_tokens_neox': 1464, 'n_words': 266}