UNPKG

@ng-doc/builder

Version:

<!-- PROJECT LOGO --> <br /> <div align="center"> <a href="https://github.com/ng-doc/ng-doc"> <img src="https://ng-doc.com/assets/images/ng-doc.svg?raw=true" alt="Logo" height="150px"> </a>

35 lines 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseSnippet = parseSnippet; const tslib_1 = require("tslib"); const P = tslib_1.__importStar(require("parsimmon")); const helpers_1 = require("./helpers"); /** * * @param string - string to parse */ function parseSnippet(string) { const parser = P.createLanguage({ keyword: () => P.string('snippet'), id: () => P.string('#') .then(P.regexp(/[a-zA-Z0-9-]+/)) .fallback(null) .map((id) => ({ id })), lang: () => P.string(':') .then(P.regexp(/[a-zA-Z0-9-]+/)) .fallback(undefined) .map((lang) => ({ lang })), icon: () => (0, helpers_1.param)('icon'), title: () => (0, helpers_1.paramValue)().map((title) => ({ title })), opened: () => P.string('opened') .result(true) .fallback(undefined) .map((opened) => ({ opened })), snippet: ({ keyword, id, lang, icon, title, opened }) => keyword.then(P.seq(id, lang, P.whitespace.then(title.or(icon).or(opened).sepBy(P.whitespace)).fallback([])).map(([id, lang, rest]) => ({ ...id, ...lang, ...Object.assign({}, ...rest) }))), snippetFromFile: ({ lang, icon, title, opened }) => P.seq((0, helpers_1.param)('snippet-from-file', 'fromFile'), lang, P.whitespace.then(title.or(icon).or(opened).sepBy(P.whitespace)).fallback([])).map(([id, lang, rest]) => ({ ...id, ...lang, ...Object.assign({}, ...rest) })), anySnippet: ({ snippet, snippetFromFile }) => snippetFromFile.or(snippet), }); const result = parser.anySnippet.parse(string); return result.status ? result.value : undefined; } //# sourceMappingURL=parse-snippet.js.map