-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created swapProjection; not working properly
- Loading branch information
Showing
4 changed files
with
95 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
import type { ContextGlobal } from "./context"; | ||
export let isNew: boolean; | ||
export let view: EditorView | null; | ||
export let match: Match; | ||
export let context: ContextGlobal; | ||
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 { | ||
margin-left: -10px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import type { Text } from "@codemirror/state"; | ||
import { arg, block, contextVariable } from "@puredit/parser"; | ||
Check warning on line 2 in apps/python-dsl/src/projections/swapProjection.ts GitHub Actions / Deploy
|
||
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"; | ||
Check warning on line 8 in apps/python-dsl/src/projections/swapProjection.ts GitHub Actions / Deploy
|
||
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], | ||
}; |