typesxml
Version:
Open source XML library written in TypeScript
57 lines • 2.27 kB
JavaScript
"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.DTDContentModelTokenizer = void 0;
const XMLUtils_js_1 = require("../XMLUtils.js");
class DTDContentModelTokenizer {
input;
pos = 0;
tokens = [];
constructor(input) {
this.input = input;
}
tokenize() {
while (this.pos < this.input.length) {
let c = this.input[this.pos];
if (/\s/.test(c)) {
this.pos++;
continue;
}
if (c === '(' || c === ')' || c === ',' || c === '|' || c === '*' || c === '+' || c === '?') {
this.tokens.push({ type: c, value: c });
this.pos++;
continue;
}
if (this.input.startsWith('#PCDATA', this.pos)) {
this.tokens.push({ type: 'PCDATA', value: '#PCDATA' });
this.pos += 7;
continue;
}
// Element name or QName with full XML Name support
if (this.pos < this.input.length && XMLUtils_js_1.XMLUtils.isNameStartChar(this.input[this.pos])) {
const start = this.pos;
this.pos++;
while (this.pos < this.input.length && XMLUtils_js_1.XMLUtils.isNameChar(this.input[this.pos])) {
this.pos++;
}
const name = this.input.substring(start, this.pos);
this.tokens.push({ type: 'NAME', value: name });
continue;
}
throw new Error('Unexpected character in content model: ' + c);
}
return this.tokens;
}
}
exports.DTDContentModelTokenizer = DTDContentModelTokenizer;
//# sourceMappingURL=DTDContentModelTokenizer.js.map