20 lines
718 B
Text
20 lines
718 B
Text
string mlfile = "", -- eg story.txt
|
|
mltxt = iff(length(mlfile)?join(read_lines(mlfile),"\n"):"""
|
|
<name> went for a walk in the park. <he or she>
|
|
found a <noun>. <name> decided to take it home.
|
|
""")
|
|
|
|
sequence strings = {}, replacements = {}
|
|
integer startpos, endpos=1
|
|
while 1 do
|
|
startpos = find('<',mltxt,endpos)
|
|
if startpos=0 then exit end if
|
|
endpos = find('>',mltxt,startpos)
|
|
if endpos=0 then ?"missing >" abort(0) end if
|
|
string s = mltxt[startpos..endpos]
|
|
if not find(s,strings) then
|
|
strings = append(strings,s)
|
|
replacements = append(replacements,prompt_string(sprintf("Enter replacement for %s:",{s})))
|
|
end if
|
|
end while
|
|
puts(1,substitute_all(mltxt,strings,replacements))
|