UNPKG

typesxml

Version:

Open source XML library written in TypeScript

64 lines 2.23 kB
"use strict"; /******************************************************************************* * Copyright (c) 2023-2026 Maxprograms. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 1.0 * which accompanies this distribution, and is available at * https://www.eclipse.org/org/documents/epl-v10.html * * Contributors: * Maxprograms - initial API and implementation *******************************************************************************/ Object.defineProperty(exports, "__esModule", { value: true }); exports.DTDChoiceModel = void 0; const XMLUtils_js_1 = require("../XMLUtils.js"); const DTDElementNameParticle_js_1 = require("./DTDElementNameParticle.js"); class DTDChoiceModel { cardinality = ''; choices = []; constructor(choices) { if (choices) { this.choices = choices; } } getType() { return 'choice'; } addChoice(choice) { this.choices.push(choice); } getChoices() { return this.choices; } validate() { // Cardinality must be '', '*', '+', or '?' if (this.cardinality && !['*', '+', '?'].includes(this.cardinality)) { return false; } // At least one choice required for valid model if (this.choices.length === 0) { return false; } // Validate each choice and its name if it's an element particle for (const choice of this.choices) { if (!choice.validate()) { return false; } // Only check name if choice is DTDElementNameParticle if (choice instanceof DTDElementNameParticle_js_1.DTDElementNameParticle) { const name = choice.getName(); if (name !== '#PCDATA' && !XMLUtils_js_1.XMLUtils.isValidXMLName(name)) { return false; } } } return true; } toBNF() { let bnf = this.choices.map(choice => choice.toBNF()).join(' | '); return bnf + (this.cardinality ? this.cardinality : ''); } } exports.DTDChoiceModel = DTDChoiceModel; //# sourceMappingURL=DTDChoiceModel.js.map