ngx_int_t
ngx_http_script_compile(ngx_http_script_compile_t *sc)
{
    u_char       ch;
    ngx_str_t    name;
    ngx_uint_t   i, bracket;
    if (ngx_http_script_init_arrays(sc) != NGX_OK) {
        return NGX_ERROR;
    }
    for (i = 0; i < sc->source->len;   ) {
        name.len = 0;
        if (sc->source->data[i] == '$') {
            if (++i == sc->source->len) {
                goto invalid_variable;
            }
#if (NGX_PCRE)
            {
            ngx_uint_t  n;
            if (sc->source->data[i] >= '1' && sc->source->data[i] <= '9') {
                n = sc->source->data[i] - '0';
                if (sc->captures_mask & (1 << n)) {
                    sc->dup_capture = 1;
                }
                sc->captures_mask |= 1 << n;
                if (ngx_http_script_add_capture_code(sc, n) != NGX_OK) {
                    return NGX_ERROR;
                }
                i++;
                continue;
            }
            }
#endif
            if (sc->source->data[i] == '{') {
                bracket = 1;
                if (++i == sc->source->len) {
                    goto invalid_variable;
                }
                name.data = &sc->source->data[i];
            } else {
                bracket = 0;
                name.data = &sc->source->data[i];
            }
            for (   ; i < sc->source->len; i++, name.len++) {
                ch = sc->source->data[i];
                if (ch == '}' && bracket) {
                    i++;
                    bracket = 0;
                    break;
                }
                if ((ch >= 'A' && ch <= 'Z')
                    || (ch >= 'a' && ch <= 'z')
                    || (ch >= '0' && ch <= '9')
                    || ch == '_')
                {
                    continue;
                }
                break;
            }
            if (bracket) {
                ngx_conf_log_error(NGX_LOG_EMERG, sc->cf, 0,
                                   "the closing bracket in \"%V\" "
                                   "variable is missing", &name);
                return NGX_ERROR;
            }
            if (name.len == 0) {
                goto invalid_variable;
            }
            sc->variables++;
            if (ngx_http_script_add_var_code(sc, &name) != NGX_OK) {
                return NGX_ERROR;
            }
            continue;
        }
        if (sc->source->data[i] == '?' && sc->compile_args) {
            sc->args = 1;
            sc->compile_args = 0;
            if (ngx_http_script_add_args_code(sc) != NGX_OK) {
                return NGX_ERROR;
            }
            i++;
            continue;
        }
        name.data = &sc->source->data[i];
        while (i < sc->source->len) {
            if (sc->source->data[i] == '$') {
                break;
            }
            if (sc->source->data[i] == '?') {
                sc->args = 1;
                if (sc->compile_args) {
                    break;
                }
            }
            i++;
            name.len++;
        }
        sc->size += name.len;
        if (ngx_http_script_add_copy_code(sc, &name, (i == sc->source->len))
            != NGX_OK)
        {
            return NGX_ERROR;
        }
    }
    return ngx_http_script_done(sc);
invalid_variable:
    ngx_conf_log_error(NGX_LOG_EMERG, sc->cf, 0, "invalid variable name");
    return NGX_ERROR;
}
['static char *\nngx_http_core_root(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)\n{\n    ngx_http_core_loc_conf_t *clcf = conf;\n    ngx_str_t                  *value;\n    ngx_int_t                   alias;\n    ngx_uint_t                  n;\n    ngx_http_script_compile_t   sc;\n    alias = (cmd->name.len == sizeof("alias") - 1) ? 1 : 0;\n    if (clcf->root.data) {\n        if ((clcf->alias != 0) == alias) {\n            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n                               "\\"%V\\" directive is duplicate",\n                               &cmd->name);\n        } else {\n            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n                               "\\"%V\\" directive is duplicate, "\n                               "\\"%s\\" directive was specified earlier",\n                               &cmd->name, clcf->alias ? "alias" : "root");\n        }\n        return NGX_CONF_ERROR;\n    }\n    if (clcf->named && alias) {\n        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n                           "the \\"alias\\" directive cannot be used "\n                           "inside the named location");\n        return NGX_CONF_ERROR;\n    }\n    value = cf->args->elts;\n    if (ngx_strstr(value[1].data, "$document_root")\n        || ngx_strstr(value[1].data, "${document_root}"))\n    {\n        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n                           "the $document_root variable cannot be used "\n                           "in the \\"%V\\" directive",\n                           &cmd->name);\n        return NGX_CONF_ERROR;\n    }\n    if (ngx_strstr(value[1].data, "$realpath_root")\n        || ngx_strstr(value[1].data, "${realpath_root}"))\n    {\n        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n                           "the $realpath_root variable cannot be used "\n                           "in the \\"%V\\" directive",\n                           &cmd->name);\n        return NGX_CONF_ERROR;\n    }\n    clcf->alias = alias ? clcf->name.len : 0;\n    clcf->root = value[1];\n    if (!alias && clcf->root.len > 0\n        && clcf->root.data[clcf->root.len - 1] == \'/\')\n    {\n        clcf->root.len--;\n    }\n    if (clcf->root.data[0] != \'$\') {\n        if (ngx_conf_full_name(cf->cycle, &clcf->root, 0) != NGX_OK) {\n            return NGX_CONF_ERROR;\n        }\n    }\n    n = ngx_http_script_variables_count(&clcf->root);\n    ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));\n    sc.variables = n;\n#if (NGX_PCRE)\n    if (alias && clcf->regex) {\n        clcf->alias = NGX_MAX_SIZE_T_VALUE;\n        n = 1;\n    }\n#endif\n    if (n) {\n        sc.cf = cf;\n        sc.source = &clcf->root;\n        sc.lengths = &clcf->root_lengths;\n        sc.values = &clcf->root_values;\n        sc.complete_lengths = 1;\n        sc.complete_values = 1;\n        if (ngx_http_script_compile(&sc) != NGX_OK) {\n            return NGX_CONF_ERROR;\n        }\n    }\n    return NGX_CONF_OK;\n}', 'ngx_int_t\nngx_http_script_compile(ngx_http_script_compile_t *sc)\n{\n    u_char       ch;\n    ngx_str_t    name;\n    ngx_uint_t   i, bracket;\n    if (ngx_http_script_init_arrays(sc) != NGX_OK) {\n        return NGX_ERROR;\n    }\n    for (i = 0; i < sc->source->len;   ) {\n        name.len = 0;\n        if (sc->source->data[i] == \'$\') {\n            if (++i == sc->source->len) {\n                goto invalid_variable;\n            }\n#if (NGX_PCRE)\n            {\n            ngx_uint_t  n;\n            if (sc->source->data[i] >= \'1\' && sc->source->data[i] <= \'9\') {\n                n = sc->source->data[i] - \'0\';\n                if (sc->captures_mask & (1 << n)) {\n                    sc->dup_capture = 1;\n                }\n                sc->captures_mask |= 1 << n;\n                if (ngx_http_script_add_capture_code(sc, n) != NGX_OK) {\n                    return NGX_ERROR;\n                }\n                i++;\n                continue;\n            }\n            }\n#endif\n            if (sc->source->data[i] == \'{\') {\n                bracket = 1;\n                if (++i == sc->source->len) {\n                    goto invalid_variable;\n                }\n                name.data = &sc->source->data[i];\n            } else {\n                bracket = 0;\n                name.data = &sc->source->data[i];\n            }\n            for (   ; i < sc->source->len; i++, name.len++) {\n                ch = sc->source->data[i];\n                if (ch == \'}\' && bracket) {\n                    i++;\n                    bracket = 0;\n                    break;\n                }\n                if ((ch >= \'A\' && ch <= \'Z\')\n                    || (ch >= \'a\' && ch <= \'z\')\n                    || (ch >= \'0\' && ch <= \'9\')\n                    || ch == \'_\')\n                {\n                    continue;\n                }\n                break;\n            }\n            if (bracket) {\n                ngx_conf_log_error(NGX_LOG_EMERG, sc->cf, 0,\n                                   "the closing bracket in \\"%V\\" "\n                                   "variable is missing", &name);\n                return NGX_ERROR;\n            }\n            if (name.len == 0) {\n                goto invalid_variable;\n            }\n            sc->variables++;\n            if (ngx_http_script_add_var_code(sc, &name) != NGX_OK) {\n                return NGX_ERROR;\n            }\n            continue;\n        }\n        if (sc->source->data[i] == \'?\' && sc->compile_args) {\n            sc->args = 1;\n            sc->compile_args = 0;\n            if (ngx_http_script_add_args_code(sc) != NGX_OK) {\n                return NGX_ERROR;\n            }\n            i++;\n            continue;\n        }\n        name.data = &sc->source->data[i];\n        while (i < sc->source->len) {\n            if (sc->source->data[i] == \'$\') {\n                break;\n            }\n            if (sc->source->data[i] == \'?\') {\n                sc->args = 1;\n                if (sc->compile_args) {\n                    break;\n                }\n            }\n            i++;\n            name.len++;\n        }\n        sc->size += name.len;\n        if (ngx_http_script_add_copy_code(sc, &name, (i == sc->source->len))\n            != NGX_OK)\n        {\n            return NGX_ERROR;\n        }\n    }\n    return ngx_http_script_done(sc);\ninvalid_variable:\n    ngx_conf_log_error(NGX_LOG_EMERG, sc->cf, 0, "invalid variable name");\n    return NGX_ERROR;\n}']