From 8dd003b4ab2db3ecaa097f38f9df1eaba92ce41a Mon Sep 17 00:00:00 2001 From: Niklas Korz Date: Sat, 4 Jun 2022 14:48:38 +0200 Subject: [PATCH] Experimenting with different projection definitions --- apps/generate/templates.ts | 5 +++++ exp.js | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 apps/generate/templates.ts create mode 100644 exp.js diff --git a/apps/generate/templates.ts b/apps/generate/templates.ts new file mode 100644 index 0000000..57c8ddc --- /dev/null +++ b/apps/generate/templates.ts @@ -0,0 +1,5 @@ +const definitionTemplate = () => ` +import { arg, contextVariable } "@puredit/parser"; +import type { Projection } from "@puredit/projections/types"; +import { tsParser } from "./parser"; +`; diff --git a/exp.js b/exp.js new file mode 100644 index 0000000..87f4328 --- /dev/null +++ b/exp.js @@ -0,0 +1,26 @@ +function process(input) { + let parts = []; + for (let from = 0, to = 0; to < input.length; to++) { + if (input[to] === "{") { + parts.push(input.slice(from, to)); + from = to + 1; + while (from < input.length && input[from] !== "}") { + from += 1; + } + let variables = input + .slice(to + 1, from) + .split(",") + .map((name) => name.trim()); + parts.push(variables); + to = from; + from += 1; + } + } + return parts; +} + +console.log( + process( + "replace {target} in column {columnTarget, columnSource} with {replacement}" + ) +); -- 2.51.2