| OLD | NEW |
| 1 function tostr(t) | 1 function tostr(t) |
| 2 local str = "" | 2 local str = "" |
| 3 for k, v in next, t do | 3 for k, v in next, t do |
| 4 if #str > 0 then | 4 if #str > 0 then |
| 5 str = str .. ", " | 5 str = str .. ", " |
| 6 end | 6 end |
| 7 if type(k) == "number" then | 7 if type(k) == "number" then |
| 8 str = str .. "[" .. k .. "] = " | 8 str = str .. "[" .. k .. "] = " |
| 9 else | 9 else |
| 10 str = str .. tostring(k) .. " = " | 10 str = str .. tostring(k) .. " = " |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 end | 47 end |
| 48 | 48 |
| 49 function pretty_print_slides(slides) | 49 function pretty_print_slides(slides) |
| 50 io.write("gSlides = {\n") | 50 io.write("gSlides = {\n") |
| 51 for i = 1, #slides do | 51 for i = 1, #slides do |
| 52 pretty_print_slide(slides[i]) | 52 pretty_print_slide(slides[i]) |
| 53 end | 53 end |
| 54 io.write("}\n") | 54 io.write("}\n") |
| 55 end | 55 end |
| 56 | 56 |
| 57 function parse_transition_type(s) | 57 function parse_attr(s, lvalue) |
| 58 return s:match("^<%s*transition%s*=%s*(%a+)%s*>$") | 58 local ts = "^<%s*" .. lvalue .. "%s*=%s*(%a+)%s*>$" |
| 59 return s:match(ts) |
| 59 end | 60 end |
| 60 | 61 |
| 61 function parse_blockstyle_type(s) | 62 function flush(slides, block) |
| 62 return s:match("^<%s*blockstyle%s*=%s*(%a+)%s*>$") | 63 if #block > 0 then |
| 64 slides[#slides + 1] = block |
| 65 return {} |
| 66 end |
| 67 return block |
| 63 end | 68 end |
| 64 | 69 |
| 65 function parse_file(file) | 70 function parse_file(file) |
| 66 local slides = {} | 71 local slides = {} |
| 67 local block = {} | 72 local block = {} |
| 68 | 73 |
| 69 for line in file:lines() do | 74 for line in file:lines() do |
| 70 local s = trim_ws(line) | 75 local s = trim_ws(line) |
| 71 if #s == 0 then -- done with a block | 76 if #s == 0 then -- done with a block |
| 72 if #block > 0 then | 77 block = flush(slides, block) |
| 73 slides[#slides + 1] = block | |
| 74 block = {} | |
| 75 end | |
| 76 else | 78 else |
| 77 local transition_type = parse_transition_type(s) | 79 local transition_type = parse_attr(s, "transition") |
| 78 local blockstyle = parse_blockstyle_type(s) | 80 local blockstyle = parse_attr(s, "blockstyle") |
| 79 if transition_type then | 81 if transition_type then |
| 80 block["transition"] = transition_type | 82 block["transition"] = transition_type |
| 81 elseif blockstyle then | 83 elseif blockstyle then |
| 82 block["blockstyle"] = blockstyle | 84 block["blockstyle"] = blockstyle |
| 83 else | 85 else |
| 84 if block.blockstyle == "code" then | 86 if block.blockstyle == "code" then |
| 85 block[#block + 1] = { text = line } | 87 block[#block + 1] = { text = line } |
| 86 else | 88 else |
| 87 local n = count_hypens(s) | 89 local n = count_hypens(s) |
| 88 block[#block + 1] = { | 90 block[#block + 1] = { |
| 89 indent = n, | 91 indent = n, |
| 90 text = trim_ws(s:sub(n + 1, -1)) | 92 text = trim_ws(s:sub(n + 1, -1)) |
| 91 } | 93 } |
| 92 end | 94 end |
| 93 end | 95 end |
| 94 end | 96 end |
| 95 end | 97 end |
| 96 -- pretty_print_slides(slides) | 98 -- pretty_print_slides(slides) |
| 97 return slides | 99 return slides |
| 98 end | 100 end |
| 99 | 101 |
| OLD | NEW |