typesxml
Version:
Open source XML library written in TypeScript
86 lines • 2.78 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
*******************************************************************************/
import { Cardinality } from "./ContentModel.js";
import { ContentParticleType } from "./contentParticle.js";
import { DTDChoice } from "./dtdChoice.js";
import { DTDName } from "./dtdName.js";
export class DTDSequence {
cardinality;
content;
constructor() {
this.content = new Array();
this.cardinality = Cardinality.NONE;
}
addParticle(particle) {
this.content.push(particle);
}
getType() {
return 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 Cardinality.NONE:
return sb.toString();
case Cardinality.OPTIONAL:
return sb + "?";
case Cardinality.ONEMANY:
return sb + "+";
case 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) {
children.add(particle.getName());
}
if (particle instanceof 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;
}
}
//# sourceMappingURL=dtdSecuence.js.map