Skip to content

Commit

Permalink
Created swapProjection; not working properly
Browse files Browse the repository at this point in the history
  • Loading branch information
ArturHD committed Oct 22, 2023
1 parent 4684d51 commit 7521023
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 5 deletions.
56 changes: 56 additions & 0 deletions apps/python-dsl/src/projections/SwapProjection.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<script lang="ts">
import { onMount } from "svelte";
import { tags } from "@lezer/highlight";
import type { EditorState } from "@codemirror/state";
import type { EditorView } from "@codemirror/view";
import { highlightingFor } from "@codemirror/language";
import type { Match } from "@puredit/parser";
import type { FocusGroup } from "@puredit/projections/focus";
import TextInput from "@puredit/projections/TextInput.svelte";
import { validateFromList } from "@puredit/projections/shared";

Check warning on line 10 in apps/python-dsl/src/projections/SwapProjection.svelte

View workflow job for this annotation

GitHub Actions / Deploy

'validateFromList' is defined but never used
import type { ContextGlobal } from "./context";
export let isNew: boolean;
export let view: EditorView | null;
export let match: Match;
export let context: ContextGlobal;

Check warning on line 16 in apps/python-dsl/src/projections/SwapProjection.svelte

View workflow job for this annotation

GitHub Actions / Deploy

Component has unused export property 'context'. If it is for external reference only, please consider using `export const context`
export let state: EditorState;
export let focusGroup: FocusGroup;
// let tables: string[];
// $: tables = Object.keys(context.tables);
onMount(() => {
if (isNew) {
requestAnimationFrame(() => {
focusGroup.first();
});
}
});
</script>

<span class="inline-flex">
<span>swap </span>
<TextInput
className={highlightingFor(state, [tags.atom])}
node={match.args.var_x}
{state}
{view}
{focusGroup}
placeholder="var1"
/><span> and </span>
<TextInput
className={highlightingFor(state, [tags.atom])}
node={match.args.var_y}
{state}
{view}
{focusGroup}
placeholder="var2"
/>
</span>

<style>
.colon {

Check warning on line 53 in apps/python-dsl/src/projections/SwapProjection.svelte

View workflow job for this annotation

GitHub Actions / Deploy

Unused CSS selector ".colon"
margin-left: -10px;
}
</style>
8 changes: 7 additions & 1 deletion apps/python-dsl/src/projections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
8 changes: 4 additions & 4 deletions apps/python-dsl/src/projections/replaceProjection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
28 changes: 28 additions & 0 deletions apps/python-dsl/src/projections/swapProjection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { Text } from "@codemirror/state";

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

View workflow job for this annotation

GitHub Actions / Deploy

'Text' is defined but never used
import { arg, block, contextVariable } from "@puredit/parser";

Check warning on line 2 in apps/python-dsl/src/projections/swapProjection.ts

View workflow job for this annotation

GitHub Actions / Deploy

'block' is defined but never used

Check warning on line 2 in apps/python-dsl/src/projections/swapProjection.ts

View workflow job for this annotation

GitHub Actions / Deploy

'contextVariable' is defined but never used
import type { Match } from "@puredit/parser";

Check warning on line 3 in apps/python-dsl/src/projections/swapProjection.ts

View workflow job for this annotation

GitHub Actions / Deploy

'Match' is defined but never used
import { stringLiteralValue } from "@puredit/projections/shared";

Check warning on line 4 in apps/python-dsl/src/projections/swapProjection.ts

View workflow job for this annotation

GitHub Actions / Deploy

'stringLiteralValue' is defined but never used
import { svelteProjection } from "@puredit/projections/svelte";
import type { Projection } from "@puredit/projections/types";
import SwapProjection from "./SwapProjection.svelte";
import type { ContextColumns, ContextTables } from "./context";

Check warning on line 8 in apps/python-dsl/src/projections/swapProjection.ts

View workflow job for this annotation

GitHub Actions / Deploy

'ContextColumns' is defined but never used

Check warning on line 8 in apps/python-dsl/src/projections/swapProjection.ts

View workflow job for this annotation

GitHub Actions / Deploy

'ContextTables' is defined but never used
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],
};

0 comments on commit 7521023

Please sign in to comment.