UNPKG

ts-fusion-parser

Version:

Parser for Neos Fusion Files

67 lines (66 loc) 2.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PrototypeDocumentationDefinition = void 0; const AbstractStatement_1 = require("./AbstractStatement"); var ContentParsingState; (function (ContentParsingState) { ContentParsingState[ContentParsingState["ShortDescription"] = 0] = "ShortDescription"; ContentParsingState[ContentParsingState["SearchModule"] = 1] = "SearchModule"; ContentParsingState[ContentParsingState["InModule"] = 2] = "InModule"; })(ContentParsingState || (ContentParsingState = {})); class PrototypeDocumentationDefinition extends AbstractStatement_1.AbstractStatement { constructor(rawContent, position, parent) { super(position, parent); this.rawContent = rawContent; this.description = ""; this.modules = []; const lines = rawContent.slice(3, -3).trim().split("\n"); let state = ContentParsingState.ShortDescription; let shortDescription = []; let modules = []; let currentModule = undefined; for (let i = 0; i < lines.length; i++) { const line = lines[i].trim(); if (state === ContentParsingState.ShortDescription) { shortDescription.push(line); if (i < lines.length - 2 && lines[i + 1].trim() === "" && lines[i + 1].trim() === "") { i += 2; state = ContentParsingState.SearchModule; continue; } } if (state === ContentParsingState.SearchModule) { if (line.startsWith("# ")) { currentModule = { title: line.slice(2).trim(), content: [] }; state = ContentParsingState.InModule; continue; } } if (state === ContentParsingState.InModule) { if (line.trim() === "" && lines[i + 1].startsWith("# ")) { state = ContentParsingState.SearchModule; modules.push(currentModule); currentModule = undefined; continue; } currentModule.content.push(line); } } if (currentModule) modules.push(currentModule); this.description = shortDescription.join("\n"); for (const module of modules) { this.modules.push({ title: module.title, content: module.content.join("\n") }); } } visit(visitor, ...args) { // TODO: visit PrototypeDocumentationDefinition } } exports.PrototypeDocumentationDefinition = PrototypeDocumentationDefinition;