UNPKG

mlld

Version:

mlld: a modular prompt scripting language

99 lines (97 loc) 3.15 kB
import { __name, __publicField } from './chunk-OMKLS24H.mjs'; // interpreter/core/interpolation-context.ts var InterpolationContext = /* @__PURE__ */ function(InterpolationContext2) { InterpolationContext2["Default"] = "default"; InterpolationContext2["ShellCommand"] = "shell-command"; InterpolationContext2["ShellCode"] = "shell-code"; InterpolationContext2["Url"] = "url"; InterpolationContext2["Template"] = "template"; InterpolationContext2["DataValue"] = "data-value"; InterpolationContext2["FilePath"] = "file-path"; return InterpolationContext2; }({}); var _EscapingStrategyFactory = class _EscapingStrategyFactory { static register(context, strategy) { this.strategies.set(context, strategy); } static getStrategy(context) { const strategy = this.strategies.get(context); if (!strategy) { return this.strategies.get("default"); } return strategy; } }; __name(_EscapingStrategyFactory, "EscapingStrategyFactory"); __publicField(_EscapingStrategyFactory, "strategies", /* @__PURE__ */ new Map()); var EscapingStrategyFactory = _EscapingStrategyFactory; var _a; var DefaultEscapingStrategy = (_a = class { escape(value) { return value; } getContext() { return "default"; } }, __name(_a, "DefaultEscapingStrategy"), _a); var _a2; var ShellCommandEscapingStrategy = (_a2 = class { escape(value) { if (!value) return ""; const escaped = value.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\$/g, "\\$").replace(/`/g, "\\`"); return escaped; } getContext() { return "shell-command"; } }, __name(_a2, "ShellCommandEscapingStrategy"), _a2); var _a3; var TemplateEscapingStrategy = (_a3 = class { escape(value) { return value; } getContext() { return "template"; } }, __name(_a3, "TemplateEscapingStrategy"), _a3); var _a4; var DataValueEscapingStrategy = (_a4 = class { escape(value) { return value; } getContext() { return "data-value"; } }, __name(_a4, "DataValueEscapingStrategy"), _a4); EscapingStrategyFactory.register("default", new DefaultEscapingStrategy()); EscapingStrategyFactory.register("shell-command", new ShellCommandEscapingStrategy()); EscapingStrategyFactory.register("template", new TemplateEscapingStrategy()); EscapingStrategyFactory.register("data-value", new DataValueEscapingStrategy()); function getInterpolationContext(directiveType, subtype) { if (!directiveType) return "default"; switch (directiveType) { case "run": if (subtype === "runCommand" || subtype === "runExec") { return "shell-command"; } if (subtype === "runCode") { return "shell-code"; } break; case "exec": return "shell-command"; case "text": return "template"; case "data": return "data-value"; case "path": return "file-path"; case "add": return "template"; } return "default"; } __name(getInterpolationContext, "getInterpolationContext"); export { EscapingStrategyFactory, InterpolationContext, getInterpolationContext }; //# sourceMappingURL=chunk-RZIZRJBS.mjs.map //# sourceMappingURL=chunk-RZIZRJBS.mjs.map