UNPKG

phrase-engine

Version:

Language files on steroids for conversational UIs that aren't boring.

48 lines 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Node_1 = require("../Node"); const text_1 = require("../text"); const textSupport_1 = require("../textSupport"); const PhraseError_1 = require("../PhraseError"); class SentenceNode extends Node_1.PhraseNode { validateNodeName(name) { return name === 'sentence'; } init(root, packet) { const id_node_map = {}; const indexIds = (root) => { if (root.nodeName === '#text' || root.nodeName === 'ref') { return; } if (root.hasAttributes() && root.hasAttribute('id')) { const id = root.getAttribute('id'); if (id in id_node_map) { let err = new PhraseError_1.PhraseError(`Duplicate ID detected "${id}"`); err.node(root); throw err; } id_node_map[id] = root; return; } const length = root.childNodes.length; for (let i = 0; i < length; i++) { indexIds(root.childNodes.item(i)); } }; indexIds(root); packet.id_map = id_node_map; this.setNextNode(text_1.default.call(this, root, packet, textSupport_1.default)); } eval(packet, branch) { return this.next().eval(packet); } *gen(packet) { yield* this.next().gen(packet); } count(e_packet) { const ret = this.next().count(e_packet); return ret; } } exports.SentenceNode = SentenceNode; //# sourceMappingURL=SentenceNode.js.map