-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SQUASHED: AUTO-COMMIT-demos-tree-sitter-edit-history.md,AUTO-COMMIT-src-client-domain-code-chawathe-script-generator.js,AUTO-COMMIT-src-components-tools-lively-container.js,AUTO-COMMIT-test-chawathe-script-generator-test.js,
- Loading branch information
1 parent
fab6f5f
commit ca9b9d8
Showing
4 changed files
with
136 additions
and
17 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,53 @@ | ||
# Edit History | ||
|
||
<script> | ||
import {visit, Parser, JavaScript, match} from 'src/client/tree-sitter.js'; | ||
import { ChawatheScriptGenerator} from 'src/client/domain-code/chawathe-script-generator.js'; | ||
|
||
|
||
let editor1 = await (<lively-code-mirror style="display:inline-block; width: 400px; height: 200px; border: 1px solid gray"></lively-code-mirror>) | ||
let editor2 = await (<lively-code-mirror style="display:inline-block; width: 400px; height: 200px; border: 1px solid gray"></lively-code-mirror>) | ||
|
||
|
||
var parser = new Parser(); | ||
parser.setLanguage(JavaScript); | ||
var list = <ul></ul> | ||
|
||
// editor1.value = `let a = 3 + 4` | ||
editor1.value = `3` | ||
// editor2.value = `let a = 3 + 4\na++` | ||
editor2.value = `4` | ||
|
||
editor1.editor.on("change", (() => update()).debounce(500)); | ||
editor2.editor.on("change", (() => update()).debounce(500)); | ||
|
||
|
||
function update() { | ||
let tree1 = parser.parse(editor1.value); | ||
let tree2 = parser.parse(editor2.value ); | ||
let mappings = match(tree1.rootNode, tree2.rootNode, 0, 100) | ||
var scriptGenerator = new ChawatheScriptGenerator() | ||
scriptGenerator.initWith(tree1.rootNode, tree2.rootNode, mappings) | ||
|
||
scriptGenerator.generate() | ||
|
||
list.innerHTML = "" | ||
|
||
for(let action of scriptGenerator.actions) { | ||
list.appendChild(<li>{action.type} {action.node && action.node.type} | ||
<button style="font-size:6pt" click={() => lively.openInspector(action)}>inspect</button> | ||
</li>) | ||
} | ||
|
||
} | ||
|
||
update() | ||
|
||
let pane = <div> | ||
{editor1}{editor2} | ||
{list} | ||
</div> | ||
|
||
|
||
pane | ||
</script> |
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