From b32ba952c96de6ced4b116ce1ce36d88b05c6679 Mon Sep 17 00:00:00 2001 From: Artur Andrzejak Date: Tue, 24 Oct 2023 18:20:37 +0200 Subject: [PATCH] Updated inc, times, puts to simpleProjection --- .../src/projections/incrementProjection.ts | 17 +++++++------- .../src/projections/putsProjection.ts | 10 ++++++--- .../src/projections/timesProjection.ts | 22 ++++++++++++------- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/apps/python-dsl/src/projections/incrementProjection.ts b/apps/python-dsl/src/projections/incrementProjection.ts index ca4da3d4..7c0c7864 100644 --- a/apps/python-dsl/src/projections/incrementProjection.ts +++ b/apps/python-dsl/src/projections/incrementProjection.ts @@ -1,21 +1,20 @@ -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 IncrementProjection from "./IncrementProjection.svelte"; -import type { ContextColumns, ContextTables } from "./context"; import { pythonParser } from "./parser"; +import { simpleProjection } from "@puredit/simple-projection"; -// const db = contextVariable("db"); const var_x = arg("var_x", "identifier"); - export const [pattern, draft] = pythonParser.statementPattern` ${var_x} += 1 `; -export const widget = svelteProjection(IncrementProjection); +// todo: fix unnecessary indent +export const widget = simpleProjection([var_x, "++"]); + +// alternative: explicit and long projection definion +// import { svelteProjection } from "@puredit/projections/svelte"; +// import IncrementProjection from "./IncrementProjection.svelte"; +// export const widget = svelteProjection(IncrementProjection); export const incrementProjection: Projection = { name: "increment variable", diff --git a/apps/python-dsl/src/projections/putsProjection.ts b/apps/python-dsl/src/projections/putsProjection.ts index 9736b993..4e717d01 100644 --- a/apps/python-dsl/src/projections/putsProjection.ts +++ b/apps/python-dsl/src/projections/putsProjection.ts @@ -1,8 +1,7 @@ import { arg } from "@puredit/parser"; -import { svelteProjection } from "@puredit/projections/svelte"; import type { Projection } from "@puredit/projections/types"; -import PutsProjection from "./PutsProjection.svelte"; import { pythonParser } from "./parser"; +import { simpleProjection } from "@puredit/simple-projection"; const anything = arg("anything", "string"); @@ -13,7 +12,12 @@ export const [pattern, draft] = pythonParser.statementPattern` print(${anything}, end="") `; -export const widget = svelteProjection(PutsProjection); +export const widget = simpleProjection(["puts ", anything]); + +// alternative projection def: explicit and long projection definion +// import { svelteProjection } from "@puredit/projections/svelte"; +// import PutsProjection from "./PutsProjection.svelte"; +// export const widget = svelteProjection(PutsProjection); export const putsProjection: Projection = { name: "puts", diff --git a/apps/python-dsl/src/projections/timesProjection.ts b/apps/python-dsl/src/projections/timesProjection.ts index 44cbba5c..b5dc94f7 100644 --- a/apps/python-dsl/src/projections/timesProjection.ts +++ b/apps/python-dsl/src/projections/timesProjection.ts @@ -1,12 +1,7 @@ -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 { arg, block } from "@puredit/parser"; import type { Projection } from "@puredit/projections/types"; -import TimesProjection from "./TimesProjection.svelte"; -// import type { ContextColumns, ContextTables } from "./context"; import { pythonParser } from "./parser"; +import { simpleProjection } from "@puredit/simple-projection"; const times_var = arg("times_var", "identifier"); const times_value = arg("times_value", "identifier"); @@ -16,7 +11,18 @@ for ${times_var} in range(${times_value}): ${block({})} `; -export const widget = svelteProjection(TimesProjection); +// todo: fix unnecessary indent +export const widget = simpleProjection([ + times_value, + ".times with", + times_var, + ":", +]); + +// alternative: explicit and long projection definion +// import { svelteProjection } from "@puredit/projections/svelte"; +// import IncrementProjection from "./IncrementProjection.svelte"; +// export const widget = svelteProjection(TimesProjection); export const timesProjection: Projection = { name: "times",