Created
August 11, 2010 12:47
-
-
Save bussiere/518919 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// generate code for parsing an array of array | |
tab = [ ["a","b"] , ["c","e"] , ["d"]] | |
def generation(tab) | |
metastring = "" | |
length = tab.length | |
i = 0 | |
indent = " " | |
for content in tab | |
if i != 0 | |
metastring += "for t#{i} in tab" | |
j = i | |
while j > 0 | |
metastring += "-[t#{(j-1)}]" | |
j = j - 1 | |
end | |
metastring += "\n" | |
metastring += indent*(i+1) | |
i = i +1 | |
elsif | |
metastring += "for t#{i} in tab\n" | |
metastring += indent | |
i = i +1 | |
end | |
end | |
temp = i | |
i = 0 | |
for content in tab | |
if i != 0 | |
metastring += "for u#{i} in t#{i}" | |
j = i | |
while j > 0 | |
metastring += "-[u#{(j-1)}]" | |
j = j - 1 | |
end | |
metastring += "\n" | |
metastring += indent*(temp+i+1) | |
i = i +1 | |
elsif | |
metastring += "for u#{i} in t#{i}\n" | |
metastring += indent*(temp+1) | |
i = i +1 | |
end | |
end | |
metastring += "\n" | |
metastring += (indent*tab.length*2)+"puts\" " | |
i = 0 | |
for content in tab | |
metastring += "\#{u#{i}} " | |
i += 1 | |
end | |
metastring += "\"\n" | |
metastring += "\n" | |
i = 0 | |
while i < tab.length*2 | |
i += 1 | |
metastring += (indent*((tab.length*2)-i))+"end\n" | |
end | |
return metastring | |
end | |
puts generation(tab) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment