Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

61
LINES

< > BotCompany Repo | #538 // Duplicator, attempt 2

Lua code

1  
get("#537") -- printShortenedReferenceTree
2  
get("#534") -- parseQuestionnaire
3  
get("#532") -- getBridgeMap
4  
get("#533") -- replaceSnippetIDs
5  
get("#539") -- tableToLine
6  
7  
parseQuestionnaire("#2000291")
8  
_, _, masterSourceID, masterDestID = getSnippetTitle(masterBridgeID):find("A master bridge from (#%d+) to (#%d+)")
9  
idmap = getBridgeMap(masterBridgeID)
10  
11  
-- walk the reference tree
12  
13  
refTree = {}
14  
printShortenedReferenceTree(masterSourceID, "", {}, refTree)
15  
for line in all(refTree) do
16  
  _, _, id = line:find("^ *(#%d+) %- ")
17  
  if id then
18  
    -- ref tree part found. identify type & action
19  
    
20  
    dest = idmap[id]
21  
    if dest ~= nil and dest:find("^#") then
22  
      -- type: already bridged
23  
      verdict = 'bridged. '..dest
24  
    else
25  
      verdict = verdicts[id]
26  
      if id == masterSourceID then
27  
        -- type: is master source (thus already bridged)
28  
        verdict = 'done (is master source)'
29  
      end
30  
    end
31  
    print(id..": "..(verdict or "no verdict"))
32  
        
33  
    if verdict == 'copy verbatim' then
34  
      -- assume source type is nt
35  
      -- we interpret 'copy verbatim' as bridge-translate all IDs
36  
      -- we find in the original snippet (in title or text)
37  
      sourceID = id
38  
      sourceTitle = getSnippetTitle(sourceID)
39  
      sourceText = getSnippet(sourceID)
40  
      destTitle = replaceSnippetIDs(sourceTitle, idmap)
41  
      destText = replaceSnippetIDs(sourceText, idmap)
42  
      if (destTitle..destText):find("<unbridged #") then
43  
        print("Snippet contains unbridged elements, skipping node")
44  
        goto nextNode
45  
      end
46  
      snippet = {type='nt', title=destTitle, text=destText}
47  
      print("lua [[ ")
48  
      print("  destID = create "..tableToLine(snippet))
49  
      print("  create {type='nt', title='Bridge from "..sourceID.." to '..destID..' following master bridge "..masterBridgeID.."', text=destID}")
50  
      print("]]")
51  
      
52  
      -- end after first node processed
53  
      goto done
54  
    else
55  
      print("Unknown verdict, skipping node")
56  
    end
57  
  end
58  
  ::nextNode::
59  
end
60  
61  
::done::

test run  test run with input  download  show line numbers   

Travelled to 12 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #538
Snippet name: Duplicator, attempt 2
Eternal ID of this version: #538/1
Text MD5: 64ed724fe652a814a3dac05de090c221
Author: stefan
Category:
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-03-16 23:15:30
Source code size: 2062 bytes / 61 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 744 / 169
Referenced in: [show references]