get("#137") -- split get("#515") -- splitLines get("#389") -- mminsert/mmcontains get("#521") -- asciiTable get("#522") -- tryCopyFromParents keywordsText = getSnippet("#2000023") new = getSnippet("#2000019") -- with partial annotations old = getSnippet("#2000015") -- with annotations overwriteAnnotations = true -- find all keywords keywords = {} for _, l in ipairs(splitLines(keywordsText)) do _, _, x, kw = l:find("^line ([^:]+): +(.*)") if x == nil then print("Warning: ignoring line. "..l) else keywords[kw] = true end end -- look for them in known annotations kw2ann = {} for _, l in ipairs(splitLines(old)) do local _, _, ann, s = l:find("^(.*) | (.*)$") if ann then ann = ann:gsub("^ +", ""):gsub(" +$", "") for kw, _ in pairs(keywords) do if s:find(kw, 1, true) then if not mmcontains(kw2ann, kw, ann) then mminsert(kw2ann, kw, ann) end end end end end uniquekeywords = {} for kw, l in pairs(kw2ann) do print("keyword "..kw.." maps to "..table.concat(l, "/")) if #l == 1 then uniquekeywords[kw] = l[1] end end print() line = 0 newLines, annotations = {}, {} for _, l in ipairs(splitLines(new)) do line = line+1 local _, _, ann, s = l:find("^(.*) | (.*)$") if ann then ann = ann:gsub("^ +", ""):gsub(" +$", "") if overwriteAnnotations or ann == '' then for kw, ann2 in pairs(uniquekeywords) do if s:find(kw, 1, true) then ann = ann2 goto found end end ::found:: if ann == nil then error() end if ann ~= '' then print("New annotation derived for line "..line..": "..ann) end end table.insert(newLines, s) table.insert(annotations, ann) end end tryCopyFromParents(newLines, annotations) print() print(mergeTexts(annotations, newLines))