UNPKG

typesxml

Version:

Open source XML library written in TypeScript

62 lines 2.17 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.DTDSequenceModel = void 0; const XMLUtils_js_1 = require("../XMLUtils.js"); const DTDElementNameParticle_js_1 = require("./DTDElementNameParticle.js"); class DTDSequenceModel { cardinality = ''; children = []; constructor(children) { if (children) this.children = children; } getType() { return 'sequence'; } addChild(child) { this.children.push(child); } getChildren() { return this.children; } validate() { // Cardinality must be '', '*', '+', or '?' if (this.cardinality && !['*', '+', '?'].includes(this.cardinality)) { return false; } // At least one child required for valid model if (this.children.length === 0) { return false; } // Validate each child and its name if it's an element particle for (const child of this.children) { if (!child.validate()) { return false; } // Only check name if child is DTDElementNameParticle if (child instanceof DTDElementNameParticle_js_1.DTDElementNameParticle) { if (!XMLUtils_js_1.XMLUtils.isValidXMLName(child.getName())) { return false; } } } return true; } toBNF() { let bnf = this.children.map(child => child.toBNF()).join(', '); return bnf + (this.cardinality ? this.cardinality : ''); } } exports.DTDSequenceModel = DTDSequenceModel; //# sourceMappingURL=DTDSequenceModel.js.map