typesxml
Version:
Open source XML library written in TypeScript
90 lines • 3.07 kB
JavaScript
;
/*******************************************************************************
* 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.DTDSequence = void 0;
const ContentModel_js_1 = require("./ContentModel.js");
const contentParticle_js_1 = require("./contentParticle.js");
const dtdChoice_js_1 = require("./dtdChoice.js");
const dtdName_js_1 = require("./dtdName.js");
class DTDSequence {
cardinality;
content;
constructor() {
this.content = new Array();
this.cardinality = ContentModel_js_1.Cardinality.NONE;
}
addParticle(particle) {
this.content.push(particle);
}
getType() {
return contentParticle_js_1.ContentParticleType.SEQUENCE;
}
setCardinality(cardinality) {
this.cardinality = cardinality;
}
getCardinality() {
return this.cardinality;
}
toString() {
let sb = '(';
for (let i = 0; i < this.content.length; i++) {
let particle = this.content[i];
sb = sb + particle.toString();
if (i < this.content.length - 1) {
sb = sb + ',';
}
}
sb = sb + ')';
switch (this.cardinality) {
case ContentModel_js_1.Cardinality.NONE:
return sb.toString();
case ContentModel_js_1.Cardinality.OPTIONAL:
return sb + "?";
case ContentModel_js_1.Cardinality.ONEMANY:
return sb + "+";
case ContentModel_js_1.Cardinality.ZEROMANY:
return sb + "*";
default:
// ignore
}
return sb.toString();
}
getParticles() {
return this.content;
}
getChildren() {
const children = new Set();
for (const particle of this.content) {
if (particle instanceof dtdName_js_1.DTDName) {
children.add(particle.getName());
}
if (particle instanceof dtdChoice_js_1.DTDChoice) {
let choice = particle;
// add all the children of the choice
for (const child of choice.getChildren()) {
children.add(child);
}
}
if (particle instanceof DTDSequence) {
let sequence = particle;
// add all the children of the sequence
for (const child of sequence.getChildren()) {
children.add(child);
}
}
}
return children;
}
}
exports.DTDSequence = DTDSequence;
//# sourceMappingURL=dtdSequence.js.map