From 67c1bfc51be7ed8f4ffb7fc707e22ebc883427fa Mon Sep 17 00:00:00 2001 From: JensLincke Date: Wed, 27 Sep 2023 17:12:24 +0200 Subject: [PATCH] treesitter works like example from paper SQUASHED: AUTO-COMMIT-src-client-media-diceCoefficient.png,AUTO-COMMIT-src-client-tree-sitter.js,AUTO-COMMIT-src-components-tools-lively-container.js,AUTO-COMMIT-test-tree-sitter-test.js, --- src/client/media/diceCoefficient.png | Bin 0 -> 7184 bytes src/client/tree-sitter.js | 27 ++++++++++++++--------- src/components/tools/lively-container.js | 4 +--- test/tree-sitter-test.js | 6 +++-- 4 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 src/client/media/diceCoefficient.png diff --git a/src/client/media/diceCoefficient.png b/src/client/media/diceCoefficient.png new file mode 100644 index 0000000000000000000000000000000000000000..5e53906e33ee9756dd03bf170fe02f4f89a351e7 GIT binary patch literal 7184 zcmdsc^9l6XH12+?72tQk<{k5<0=tP+Ze0n5t2ksjK`7Uym{sNqzAN~k(AqfIW zCBLWK%yg0R88k?EBQPAe^muIc#O2V_L4wd?5#EkPPhZo=hRLtXCwABChY`v?ComR5 z&<$_~zQR02%r$*bzzmk#&;$HYBb{-K2%QE%h@r2a1PdYLnOpx|MkPbYt&$zXo}c#+ zMS0R;&YR&RNacr>I3EB9uDxx5lbSU%ai9SrKIOl0sWqpeq^U4IcVX1TyR#g<=RM4D zM_m7p0lyiJ3BGJ~-UEaV?Vrzx#%qGm5>4rc#pfJZ@O2db5%D8Izb2V4|4|42$p0Uu z>f;MJJK58i`=C*f0`Wfkx1a0!l?}h{##_;Y)tgx_s89UqvDaHX-yTko7kN?00t@4k zM^08^mp7XHsD{NQP&vx0zEa9Q#V-hbWpfYQH`0F&NL=!|i<{cDz6BUEYyi zu~mO|>OC8n;=Fyx)js*D1MZbvGo)xH?!rt$BH4B2)|<3I>T8pGpUr?XtO zmYu^Ee1k$ELnFz4fEDSRfmQrFW>MVE?OjtYSWvUu72-!DgFK-UsS!S)mwG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zE9qsq>!nXfUNmPso_xioELg=7R)%O;`eSHcnRdviX>;o&hEnD9+w>d7y`EdPVlNE& zne7@yid{D+bY1q|TDwooB`A2lDf2x3J5G`V!>%&NKgu>f(ptgLnqY2%3mYvo)`j1} zI=L!pzMRL4Zufooi@dC-_^LkTZ0Fw84Ou{PBSUD2BS%3qPhlUN1 z^C&8t6h&pn&y%7kQFl@R)j17eIuE0?NLXu;gFu3vB=@U+%2WuD!lo!v92LXA>_&pB uCLq*#w;TsM52SQRfs~HS|DO68R2p4#)qnB55Gm;cl<%wG%fD;(?tcJ}O*6m% literal 0 HcmV?d00001 diff --git a/src/client/tree-sitter.js b/src/client/tree-sitter.js index ab75924ba..03f8dec08 100644 --- a/src/client/tree-sitter.js +++ b/src/client/tree-sitter.js @@ -136,16 +136,19 @@ export function isomorphic(node1, node2) { return true; } +// similarity coefficient + + +/*MD + +![](media/diceCoefficient.png){width=100px} +MD*/ export function dice(t1, t2, M) { let descendantsT1 = s(t1) let descendantsT2 = s(t2) - - let mappedElements = [] // the ratio of common descendants between two nodes given a set of mappings M - - for (let m of M) { if (descendantsT1.has(m.node1.id) && descendantsT2.has(m.node2.id)) { mappedElements.push(m) @@ -338,7 +341,6 @@ function isLeaf(node) { function lastChanceMatch(mappings, src, dst, maxSize) { - debugger if (s(src).size < maxSize || s(dst).size < maxSize) { let zsMappings = zhangShashaMapping(src, dst, function children(node) { return node.children }, @@ -346,16 +348,17 @@ function lastChanceMatch(mappings, src, dst, maxSize) { function removeCost() { return 1 }, function updateCost(from, to) { if (from.type === to.type) { - debugger return qGramsDifference(label(from), label(from), 2) } else { return 1 } }); for (let candidate of zsMappings) { - let srcCand = candidate.t1; - let dstCand = candidate.t2; - addMapping(mappings, srcCand, dstCand); + if (candidate.t1 && candidate.t2) { + if (!isSrcMapped(candidate.t1, mappings) && !isDstMapped(candidate.t2, mappings)) { + addMapping(mappings, candidate.t1, candidate.t2); + } + } } } } @@ -371,8 +374,10 @@ function bottomUpPhase(T1, dst, mappings, minDice, maxSize) { visitPostorder(T1, t => { if (!t.parent) { - addMapping(mappings, t, dst) - lastChanceMatch(mappings, t, dst, maxSize); + if (!isSrcMapped(t, mappings)) { + addMapping(mappings, t, dst) + lastChanceMatch(mappings, t, dst, maxSize); + } } else if (!isSrcMapped(t, mappings) && !isLeaf(t)) { let candidatesList = candidates(t, mappings); let best = null; diff --git a/src/components/tools/lively-container.js b/src/components/tools/lively-container.js index ac0edfcdb..b08dd0782 100644 --- a/src/components/tools/lively-container.js +++ b/src/components/tools/lively-container.js @@ -2932,6 +2932,7 @@ export default class Container extends Morph { // TEST + if (unsavedText) { // container or editor load text async and we have to interact with them // await lively.sleep(1000) @@ -2940,10 +2941,7 @@ export default class Container extends Morph { // newEditor.textChanged = true // newEditor.lastText = obj.lastText newEditor.livelyMigrate(oldEditor) - } - - }) } else { this.isMigrating = false; diff --git a/test/tree-sitter-test.js b/test/tree-sitter-test.js index f89eb7a20..d0e964648 100644 --- a/test/tree-sitter-test.js +++ b/test/tree-sitter-test.js @@ -49,6 +49,7 @@ describe('tree-sitter', () => { expect(matches.length).gt(3) + debugger var result = dice(callExpr1,callExpr2, matches) expect(result).to.equal(1) @@ -132,7 +133,7 @@ a = 3 + 4`]) expect(matches.length).gt(5) for(let match of matches) { if (match.node1.text !== tree1.text) { - expect(match.node1.text).to.equal(match.node2.text) + expect(match.node1.text, match.node1.type + " -> " + match.node2.type).to.equal(match.node2.text) } } }) @@ -175,12 +176,13 @@ if (true) { // that.tree.language.query("(variable_declarator)@a").captures(this) var classDecl1 = tree1.child(0) - var classDecl1 = tree2.child(0) + var classDecl2 = tree2.child(0) var matches = match(tree1, tree2) expect(matches.length).gt(10) + debugger let found = matches.find(ea => ea.node1.id == classDecl1.id && ea.node2.id == classDecl2.id) expect(found).to.not.be.undefined