Add some content to the State chapter.
[matthijs/master-project/report.git] / pret-haskell.lua
1 -- filename : type-haskell.lua
2 -- comment  : Pretty printing of haskell programs. Currently, this is just
3 ---           verbatim printing with the option of applying strikethrough
4 -- author   : Matthijs Kooijman, Universiteit Twente, NL
5 -- copyright: Matthijs Kooijman
6 -- license  : None
7
8 local utf = unicode.utf8
9
10 local visualizer = buffers.newvisualizer('haskell')
11
12 function visualizer.flush_line(str,nested)
13     while str ~= '' do
14         print("Looking at '" .. str .. "'")
15         if utf.match(str, '^ ') then 
16             tex.sprint('\\obs ')
17             -- Eat the first character
18             str = utf.sub(str, 2)
19         else
20             local text, rest = utf.match(str, "^%-%-(.-)%-%-(.*)")
21             if text then
22                 tex.sprint('\\strikethrough{')
23                 -- Recursively call ourselves to handle spaces gracefully.
24                 visualizer.flush_line(text)
25                 tex.sprint('}')
26                 -- Eat the processed characters
27                 str = rest
28             else
29                 -- Write the first character
30                 tex.write(utf.sub(str, 1, 1))
31                 -- Eat the first character
32                 str = utf.sub(str, 2)
33             end
34         end
35     end
36 end
37
38 -- vim: set sw=4 sts=4 expandtab ai: