From 7521023689a27a56cae3efcd2c642fa4569aef78 Mon Sep 17 00:00:00 2001 From: Artur Andrzejak Date: Sun, 22 Oct 2023 18:22:28 +0200 Subject: [PATCH] Created swapProjection; not working properly --- .../src/projections/SwapProjection.svelte | 56 +++++++++++++++++++ apps/python-dsl/src/projections/index.ts | 8 ++- .../src/projections/replaceProjection.ts | 8 +-- .../src/projections/swapProjection.ts | 28 ++++++++++ 4 files changed, 95 insertions(+), 5 deletions(-) create mode 100644 apps/python-dsl/src/projections/SwapProjection.svelte create mode 100644 apps/python-dsl/src/projections/swapProjection.ts diff --git a/apps/python-dsl/src/projections/SwapProjection.svelte b/apps/python-dsl/src/projections/SwapProjection.svelte new file mode 100644 index 00000000..0d71ca7a --- /dev/null +++ b/apps/python-dsl/src/projections/SwapProjection.svelte @@ -0,0 +1,56 @@ + + + + swap + and + + + + diff --git a/apps/python-dsl/src/projections/index.ts b/apps/python-dsl/src/projections/index.ts index 4fcc305b..afa52bb3 100644 --- a/apps/python-dsl/src/projections/index.ts +++ b/apps/python-dsl/src/projections/index.ts @@ -4,10 +4,16 @@ import { globalContextValues, globalContextVariables } from "./context"; import { pythonParser } from "./parser"; import { replaceProjection } from "./replaceProjection"; import { trimProjection } from "./trimProjection"; +import { swapProjection } from "./swapProjection"; export const projectionPluginConfig: ProjectionPluginConfig = { parser: pythonParser, - projections: [changeProjection, replaceProjection, trimProjection], + projections: [ + changeProjection, + replaceProjection, + trimProjection, + swapProjection, + ], globalContextVariables, globalContextValues, }; diff --git a/apps/python-dsl/src/projections/replaceProjection.ts b/apps/python-dsl/src/projections/replaceProjection.ts index 39019ede..9b9004bd 100644 --- a/apps/python-dsl/src/projections/replaceProjection.ts +++ b/apps/python-dsl/src/projections/replaceProjection.ts @@ -6,12 +6,12 @@ import ReplaceProjection from "./ReplaceProjection.svelte"; const table = contextVariable("table"); const column = arg("column", "string"); -// const target = arg("target", "string"); // original +const target = arg("target", "string"); // original // AA: const target = arg("target", "identifier"); -const target = arg("target", "primary_expression"); -// const replacement = arg("replacement", "string"); // original +// AA - now working: const target = arg("target", "primary_expression"); +const replacement = arg("replacement", "string"); // original // AA: const replacement = arg("replacement", "identifier"); -const replacement = arg("replacement", "primary_expression"); +// AA - now working: const replacement = arg("replacement", "primary_expression"); export const [pattern, draft] = pythonParser.statementPattern` ${table}.column(${column}).replace(${target}, ${replacement}) diff --git a/apps/python-dsl/src/projections/swapProjection.ts b/apps/python-dsl/src/projections/swapProjection.ts new file mode 100644 index 00000000..b94f630a --- /dev/null +++ b/apps/python-dsl/src/projections/swapProjection.ts @@ -0,0 +1,28 @@ +import type { Text } from "@codemirror/state"; +import { arg, block, contextVariable } from "@puredit/parser"; +import type { Match } from "@puredit/parser"; +import { stringLiteralValue } from "@puredit/projections/shared"; +import { svelteProjection } from "@puredit/projections/svelte"; +import type { Projection } from "@puredit/projections/types"; +import SwapProjection from "./SwapProjection.svelte"; +import type { ContextColumns, ContextTables } from "./context"; +import { pythonParser } from "./parser"; + +// const db = contextVariable("db"); +const var_x = arg("var_x", "identifier"); +const var_y = arg("var_y", "identifier"); + +export const [pattern, draft] = pythonParser.statementPattern` +${var_x}, ${var_y} = ${var_y},${var_x} +`; + +export const widget = svelteProjection(SwapProjection); + +export const swapProjection: Projection = { + name: "swap variables", + description: "Swaps two variables", + pattern, + draft, + requiredContextVariables: [], + widgets: [widget], +};