<commit_before><?php
declare(strict_types=1);
/**
 * This file was formerly part of the Eden PHP Library.
 * (c) 2014-2016 Openovate Labs
 * (c) 2016 <NAME>
 *
 * Copyright and license information can be found at LICENSE.txt
 * distributed with this package.
 */

namespace MattyG\Handlebars;

class Compiler
{
    const BLOCK_TEXT_LINE = '\r\t$buffer .= \'%s\'.\n;';
    const BLOCK_TEXT_LAST = '\r\t$buffer .= \'%s\';';

    const BLOCK_VARIABLE_VALUE = '\r\t$buffer .= htmlspecialchars($data->find(\'%s\'), ENT_COMPAT, \'UTF-8\');\r';
    const BLOCK_ESCAPE_VALUE = '\r\t$buffer .= $data->find(\'%s\');\r';

    const BLOCK_HELPER_OPEN = '\r\t$helperResult = $this->runtime->getHelper(\'%s\')(';
    const BLOCK_HELPER_CLOSE = '\r\t);';
    const BLOCK_HELPER_VARIABLE_RESULTCHECK = '\r\t$buffer .= $helperResult instanceof SafeString ? $helperResult : htmlspecialchars($helperResult, ENT_COMPAT, \'UTF-8\');\r';
    const BLOCK_HELPER_ESCAPE_RESULTCHECK = '\r\t$buffer .= $helperResult;\r';

    const BLOCK_ESCAPE_HELPER_OPEN = '\r\t$buffer .= $this->runtime->getHelper(\'%s\')(';
    const BLOCK_ESCAPE_HELPER_CLOSE = '\r\t);\r';

    const BLOCK_ARGUMENT_VALUE = '$data->find(\'%s\')';

    const BLOCK_OPTIONS_OPEN = 'array(';
    const BLOCK_OPTIONS_CLOSE = '\r\t)';

    const BLOCK_OPTIONS_FN_OPEN = '\r\t\'fn\' => function($context = null) use ($data) {';
    const BLOCK_OPTIONS_FN_BODY_1 = '\r\t\1if (is_array($context)) {';
    const BLOCK_OPTIONS_FN_BODY_2 = '\r\t\1\1$data->push($context);';
    const BLOCK_OPTIONS_FN_BODY_3 = '\r\t\1}';
    const BLOCK_OPTIONS_FN_BODY_4 = '\r\r\t\1$buffer = \'\';';
    const BLOCK_OPTIONS_FN_BODY_5 = '\r\r\t\1if (is_array($context)) {';
    const BLOCK_OPTIONS_FN_BODY_6 = '\r\t\1\1$data->pop();';
    const BLOCK_OPTIONS_FN_BODY_7 = '\r\t\1}';
    const BLOCK_OPTIONS_FN_CLOSE = '\r\r\t\1return $buffer;\r\t},\r';

    const BLOCK_OPTIONS_INVERSE_OPEN = '\r\t\'inverse\' => function($context = null) use ($data) {';
    const BLOCK_OPTIONS_INVERSE_BODY_1 = '\r\t\1if (is_array($context)) {';
    const BLOCK_OPTIONS_INVERSE_BODY_2 = '\r\t\1\1$data->push($context);';
    const BLOCK_OPTIONS_INVERSE_BODY_3 = '\r\t\1}';
    const BLOCK_OPTIONS_INVERSE_BODY_4 = '\r\r\t\1$buffer = \'\';';
    const BLOCK_OPTIONS_INVERSE_BODY_5 = '\r\r\t\1if (is_array($context)) {';
    const BLOCK_OPTIONS_INVERSE_BODY_6 = '\r\t\1\1$data->pop();';
    const BLOCK_OPTIONS_INVERSE_BODY_7 = '\r\t\1}';
    const BLOCK_OPTIONS_INVERSE_CLOSE = '\r\r\t\1return $buffer;\r\t}\r';

    const BLOCK_OPTIONS_FN_EMPTY = '\r\t\'fn\' => function() {},';
    const BLOCK_OPTIONS_INVERSE_EMPTY = '\r\t\'inverse\' => function() {},';
    const BLOCK_OPTIONS_NAME = '\r\t\'name\' => \'%s\',';
    const BLOCK_OPTIONS_ARGS = '\r\t\'args\' => \'%s\',';
    const BLOCK_OPTIONS_HASH = '\r\t\'hash\' => array(%s),';
    const BLOCK_OPTIONS_HASH_KEY_VALUE = '\'%s\' => %s';

    const LAST_OPEN = ' LAST ';

    const ERROR_AND = ' AND ';
    const ERROR_LINE = '"%s" on line %s';
    const ERROR_MISSING_CLOSING = 'Missing closing tags for: %s';
    const ERROR_UNKNOWN_END = 'Unknown close tag: "%s" on line %s';

    /**
     * @var Runtime
     */
    protected $runtime;

    /**
     * @var TokenizerFactory
     */
    protected $tokenizerFactory;

    /**
     * @var ArgumentParserFactory
     */
    protected $argumentParserFactory;

    /**
     * @var int
     */
    protected $offset = 1;

    /**
     * Just load the source template
     *
     * @param Runtime $runtime
     * @param TokenizerFactory $tokenizerFactory
     * @param ArgumentParserFactory $argumentParserFactory
     */
    public function __construct(Runtime $runtime, TokenizerFactory $tokenizerFactory, ArgumentParserFactory $argumentParserFactory)
    {
        $this->runtime = $runtime;
        $this->tokenizerFactory = $tokenizerFactory;
        $this->argumentParserFactory = $argumentParserFactory;
    }

    /**
     * Transform the template to code that can be used independently
     * TODO: Must never return layout
     *
     * @param string $source
     * @param int $startingOffset
     * @return string<commit_msg>Remove TODO comment that was already dealt with<commit_after><?php
declare(strict_types=1);
/**
 * This file was formerly part of the Eden PHP Library.
 * (c) 2014-2016 Openovate Labs
 * (c) 2016 <NAME>
 *
 * Copyright and license information can be found at LICENSE.txt
 * distributed with this package.
 */

namespace MattyG\Handlebars;

class Compiler
{
    const BLOCK_TEXT_LINE = '\r\t$buffer .= \'%s\'.\n;';
    const BLOCK_TEXT_LAST = '\r\t$buffer .= \'%s\';';

    const BLOCK_VARIABLE_VALUE = '\r\t$buffer .= htmlspecialchars($data->find(\'%s\'), ENT_COMPAT, \'UTF-8\');\r';
    const BLOCK_ESCAPE_VALUE = '\r\t$buffer .= $data->find(\'%s\');\r';

    const BLOCK_HELPER_OPEN = '\r\t$helperResult = $this->runtime->getHelper(\'%s\')(';
    const BLOCK_HELPER_CLOSE = '\r\t);';
    const BLOCK_HELPER_VARIABLE_RESULTCHECK = '\r\t$buffer .= $helperResult instanceof SafeString ? $helperResult : htmlspecialchars($helperResult, ENT_COMPAT, \'UTF-8\');\r';
    const BLOCK_HELPER_ESCAPE_RESULTCHECK = '\r\t$buffer .= $helperResult;\r';

    const BLOCK_ESCAPE_HELPER_OPEN = '\r\t$buffer .= $this->runtime->getHelper(\'%s\')(';
    const BLOCK_ESCAPE_HELPER_CLOSE = '\r\t);\r';

    const BLOCK_ARGUMENT_VALUE = '$data->find(\'%s\')';

    const BLOCK_OPTIONS_OPEN = 'array(';
    const BLOCK_OPTIONS_CLOSE = '\r\t)';

    const BLOCK_OPTIONS_FN_OPEN = '\r\t\'fn\' => function($context = null) use ($data) {';
    const BLOCK_OPTIONS_FN_BODY_1 = '\r\t\1if (is_array($context)) {';
    const BLOCK_OPTIONS_FN_BODY_2 = '\r\t\1\1$data->push($context);';
    const BLOCK_OPTIONS_FN_BODY_3 = '\r\t\1}';
    const BLOCK_OPTIONS_FN_BODY_4 = '\r\r\t\1$buffer = \'\';';
    const BLOCK_OPTIONS_FN_BODY_5 = '\r\r\t\1if (is_array($context)) {';
    const BLOCK_OPTIONS_FN_BODY_6 = '\r\t\1\1$data->pop();';
    const BLOCK_OPTIONS_FN_BODY_7 = '\r\t\1}';
    const BLOCK_OPTIONS_FN_CLOSE = '\r\r\t\1return $buffer;\r\t},\r';

    const BLOCK_OPTIONS_INVERSE_OPEN = '\r\t\'inverse\' => function($context = null) use ($data) {';
    const BLOCK_OPTIONS_INVERSE_BODY_1 = '\r\t\1if (is_array($context)) {';
    const BLOCK_OPTIONS_INVERSE_BODY_2 = '\r\t\1\1$data->push($context);';
    const BLOCK_OPTIONS_INVERSE_BODY_3 = '\r\t\1}';
    const BLOCK_OPTIONS_INVERSE_BODY_4 = '\r\r\t\1$buffer = \'\';';
    const BLOCK_OPTIONS_INVERSE_BODY_5 = '\r\r\t\1if (is_array($context)) {';
    const BLOCK_OPTIONS_INVERSE_BODY_6 = '\r\t\1\1$data->pop();';
    const BLOCK_OPTIONS_INVERSE_BODY_7 = '\r\t\1}';
    const BLOCK_OPTIONS_INVERSE_CLOSE = '\r\r\t\1return $buffer;\r\t}\r';

    const BLOCK_OPTIONS_FN_EMPTY = '\r\t\'fn\' => function() {},';
    const BLOCK_OPTIONS_INVERSE_EMPTY = '\r\t\'inverse\' => function() {},';
    const BLOCK_OPTIONS_NAME = '\r\t\'name\' => \'%s\',';
    const BLOCK_OPTIONS_ARGS = '\r\t\'args\' => \'%s\',';
    const BLOCK_OPTIONS_HASH = '\r\t\'hash\' => array(%s),';
    const BLOCK_OPTIONS_HASH_KEY_VALUE = '\'%s\' => %s';

    const LAST_OPEN = ' LAST ';

    const ERROR_AND = ' AND ';
    const ERROR_LINE = '"%s" on line %s';
    const ERROR_MISSING_CLOSING = 'Missing closing tags for: %s';
    const ERROR_UNKNOWN_END = 'Unknown close tag: "%s" on line %s';

    /**
     * @var Runtime
     */
    protected $runtime;

    /**
     * @var TokenizerFactory
     */
    protected $tokenizerFactory;

    /**
     * @var ArgumentParserFactory
     */
    protected $argumentParserFactory;

    /**
     * @var int
     */
    protected $offset = 1;

    /**
     * Just load the source template
     *
     * @param Runtime $runtime
     * @param TokenizerFactory $tokenizerFactory
     * @param ArgumentParserFactory $argumentParserFactory
     */
    public function __construct(Runtime $runtime, TokenizerFactory $tokenizerFactory, ArgumentParserFactory $argumentParserFactory)
    {
        $this->runtime = $runtime;
        $this->tokenizerFactory = $tokenizerFactory;
        $this->argumentParserFactory = $argumentParserFactory;
    }

    /**
     * Transform the template to code that can be used independently
     *
     * @param string $source
     * @param int $startingOffset
     * @return string
{'fraction_non_alphanumeric': 0.17053701015965167, 'fraction_numerical': 0.012094823415578132, 'mean_word_length': 3.3315872184389734, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 49, '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': '2080539', 'n_tokens_mistral': 3173, 'n_tokens_neox': 2982, 'n_words': 559}