Skip to content

Commit

Permalink
Updated inc, times, puts to simpleProjection
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturHD committed Oct 24, 2023
1 parent 03c3e46 commit b32ba95
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
17 changes: 8 additions & 9 deletions apps/python-dsl/src/projections/incrementProjection.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import type { Text } from "@codemirror/state";
import { arg, block, contextVariable } from "@puredit/parser";

Check warning on line 1 in apps/python-dsl/src/projections/incrementProjection.ts

View workflow job for this annotation

GitHub Actions / Deploy

'block' is defined but never used

Check warning on line 1 in apps/python-dsl/src/projections/incrementProjection.ts

View workflow job for this annotation

GitHub Actions / Deploy

'contextVariable' is defined but never used
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",
Expand Down
10 changes: 7 additions & 3 deletions apps/python-dsl/src/projections/putsProjection.ts
Original file line number Diff line number Diff line change
@@ -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");

Expand All @@ -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",
Expand Down
22 changes: 14 additions & 8 deletions apps/python-dsl/src/projections/timesProjection.ts
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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",
Expand Down

0 comments on commit b32ba95

Please sign in to comment.