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

24
LINES

< > BotCompany Repo | #512 // Line annotations expander

Lua code

get("#137") -- split

text = getSnippet("#2000013")

lines = split(text, "\n")
byline = {}
n = 0
for _, l in ipairs(lines) do
  _, _, x, ann = l:find("^line ([^:]+): +(.*)")
  if x == nil then
    print("Warning: ignoring line. "..l)
  else
    a, b = unpack(split(x, "\-"))
    if b == nil then b = a end
    for y = tonumber(a), tonumber(b) do
      byline[y] = ann
    end
    n = math.max(n, tonumber(b))
  end
end

for i=1, n do
  print(byline[i] or '')
end

Author comment

e.g. for #2000013

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

Comments [hide]

ID Author/Program Comment Date
943 #1000604 (pitcher) 2015-08-20 15:28:24
942 #1000610 Edit suggestion:
!636
!629

main {
static Object androidContext;
static String programID;

public static void main(String[] args) throws Exception {
get("#137") -- split

text = getSnippet("#2000013")

lines = split(text, "\n")
byline = {}
n = 0
for _, l in ipairs(lines) do
_, _, x, ann = l:find("^line ([^:]+): +(.*)")
if x == nil then
print("Warning: ignoring line. "..l)
else
a, b = unpack(split(x, "\-"))
if b == nil then b = a end
for y = tonumber(a), tonumber(b) do
byline[y] = ann
end
n = math.max(n, tonumber(b))
end
end

for i=1, n do
print(byline[i] or '')
end
}}
2015-08-20 06:27:18  delete 

add comment

Snippet ID: #512
Snippet name: Line annotations expander
Eternal ID of this version: #512/1
Text MD5: 19f2e846cf9c59325dbcb6a0633cfed8
Author: stefan
Category:
Type: Lua code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-03-11 18:10:44
Source code size: 485 bytes / 24 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 1066 / 179
Referenced in: [show references]