UNPKG

pddl-workspace

Version:
88 lines 4.03 kB
"use strict"; /* -------------------------------------------------------------------------------------------- * Copyright (c) Jan Dolejsi. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. * ------------------------------------------------------------------------------------------ */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ProblemParserPreProcessor = void 0; const PreProcessors_1 = require("./PreProcessors"); class ConsoleOutputAdaptor { appendLine(text) { console.info(text); } show() { // do nothing } } class ProblemParserPreProcessor { constructor(context) { this.context = context; this.problemCompletePattern = /^;;\s*!pre-parsing:\s*{\s*type:\s*"(command|nunjucks|jinja2|python)"\s*,\s*(command:\s*"([\w:\-/\\\. ]+)"\s*(,\s*args:\s*\[([^\]]*)\])?|data:\s*"([\w:\-/\\\. ]+)")\s*}/gm; } async process(preProcessor, templatedProblem, workingDirectory) { if (preProcessor) { const transformed = await preProcessor.transform(templatedProblem, workingDirectory, new ConsoleOutputAdaptor()); console.log("Pre-processed successfully using " + preProcessor.toString()); return transformed || templatedProblem; } else { return templatedProblem; } } createPreProcessor(templatedProblem) { var _a, _b, _c; let preProcessor; this.problemCompletePattern.lastIndex = 0; const match = this.problemCompletePattern.exec(templatedProblem); if (match && match[1]) { switch (match[1]) { case "command": const args = this.parseArgs(match[5]); preProcessor = new PreProcessors_1.CommandPreProcessor(match[3], args, match[0], match.index); break; case "python": try { const args1 = this.parseArgs(match[5]); preProcessor = new PreProcessors_1.PythonPreProcessor(this.context.pythonPath(), match[3], args1, match[0], match.index); } catch (err) { console.log(err); const error = err; throw new PreProcessors_1.PreProcessingError((_a = error.message) !== null && _a !== void 0 ? _a : err, 0, 0); } break; case "nunjucks": try { preProcessor = new PreProcessors_1.NunjucksPreProcessor(match[6], match[0], match.index, true); } catch (err) { console.log(err); const error = err; throw new PreProcessors_1.PreProcessingError((_b = error.message) !== null && _b !== void 0 ? _b : err, 0, 0); } break; case "jinja2": if (!this.context) { break; } try { preProcessor = new PreProcessors_1.Jinja2PreProcessor(this.context.pythonPath(), this.context.extensionPath, match[6], match[0], match.index); } catch (err) { console.log(err); const error = err; throw new PreProcessors_1.PreProcessingError((_c = error.message) !== null && _c !== void 0 ? _c : err, 0, 0); } break; default: console.log("Not supported: " + match[1]); } } return preProcessor; } parseArgs(argsText) { return argsText ? argsText.split(',').map(arg => arg.trim().slice(1, -1)) : []; } } exports.ProblemParserPreProcessor = ProblemParserPreProcessor; //# sourceMappingURL=ProblemParserPreProcessor.js.map