"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.qRegistryUrls = void 0;
const good_enough_parser_1 = require("good-enough-parser");
const regex_1 = require("../../../../util/regex");
const common_1 = require("./common");
const handlers_1 = require("./handlers");
// mavenCentral()
// mavenCentral { ... }
const qPredefinedRegistries = good_enough_parser_1.query
    .sym((0, regex_1.regEx)(`^(?:${Object.keys(common_1.REGISTRY_URLS).join('|')})$`), common_1.storeVarToken)
    .alt(good_enough_parser_1.query.tree({
    type: 'wrapped-tree',
    startsWith: '(',
    endsWith: ')',
    search: good_enough_parser_1.query.begin().end(),
}), good_enough_parser_1.query.tree({
    type: 'wrapped-tree',
    startsWith: '{',
    endsWith: '}',
}))
    .handler((ctx) => (0, common_1.storeInTokenMap)(ctx, 'registryUrl'))
    .handler(handlers_1.handlePredefinedRegistryUrl)
    .handler(common_1.cleanupTempVars);
// maven(url = uri("https://foo.bar/baz"))
// maven { name = some; url = "https://foo.bar/${name}" }
const qCustomRegistryUrl = good_enough_parser_1.query
    .sym('maven')
    .alt(good_enough_parser_1.query.tree({
    type: 'wrapped-tree',
    maxDepth: 1,
    startsWith: '(',
    endsWith: ')',
    search: good_enough_parser_1.query
        .begin()
        .opt(good_enough_parser_1.query.sym('url').op('='))
        .alt(good_enough_parser_1.query.sym('uri').tree({
        maxDepth: 1,
        search: good_enough_parser_1.query.alt(common_1.qTemplateString, common_1.qVariableAccessIdentifier),
    }), good_enough_parser_1.query.alt(common_1.qTemplateString, common_1.qVariableAccessIdentifier))
        .end(),
}), good_enough_parser_1.query.tree({
    type: 'wrapped-tree',
    maxDepth: 1,
    startsWith: '{',
    endsWith: '}',
    search: good_enough_parser_1.query.alt(good_enough_parser_1.query
        .sym('name')
        .opt(good_enough_parser_1.query.op('='))
        .alt(common_1.qTemplateString, common_1.qVariableAccessIdentifier)
        .handler((ctx) => (0, common_1.storeInTokenMap)(ctx, 'name')), good_enough_parser_1.query
        .sym('url')
        .opt(good_enough_parser_1.query.op('='))
        .alt(good_enough_parser_1.query.sym('uri').tree({
        maxDepth: 1,
        search: good_enough_parser_1.query.alt(common_1.qTemplateString, common_1.qVariableAccessIdentifier),
    }), good_enough_parser_1.query.alt(common_1.qTemplateString, common_1.qVariableAccessIdentifier)), good_enough_parser_1.query.sym('setUrl').tree({
        maxDepth: 1,
        startsWith: '(',
        endsWith: ')',
        search: good_enough_parser_1.query
            .begin()
            .alt(common_1.qTemplateString, common_1.qVariableAccessIdentifier)
            .end(),
    })),
}))
    .handler((ctx) => (0, common_1.storeInTokenMap)(ctx, 'registryUrl'))
    .handler(handlers_1.handleCustomRegistryUrl)
    .handler(common_1.cleanupTempVars);
exports.qRegistryUrls = good_enough_parser_1.query.alt(good_enough_parser_1.query.sym('publishing').tree(), qPredefinedRegistries, qCustomRegistryUrl);
//# sourceMappingURL=registry-urls.js.map