Add a haskell pretty printer.
[matthijs/master-project/report.git] / pret-haskell.lua
diff --git a/pret-haskell.lua b/pret-haskell.lua
new file mode 100644 (file)
index 0000000..483d660
--- /dev/null
@@ -0,0 +1,38 @@
+-- filename : type-haskell.lua
+-- comment  : Pretty printing of haskell programs. Currently, this is just
+---           verbatim printing with the option of applying strikethrough
+-- author   : Matthijs Kooijman, Universiteit Twente, NL
+-- copyright: Matthijs Kooijman
+-- license  : None
+
+local utf = unicode.utf8
+
+local visualizer = buffers.newvisualizer('haskell')
+
+function visualizer.flush_line(str,nested)
+    while str ~= '' do
+        print("Looking at '" .. str .. "'")
+        if utf.match(str, '^ ') then 
+            tex.sprint('\\obs ')
+            -- Eat the first character
+            str = utf.sub(str, 2)
+        else
+            local text, rest = utf.match(str, "^%-%-(.-)%-%-(.*)")
+            if text then
+                tex.sprint('\\strikethrough{')
+                -- Recursively call ourselves to handle spaces gracefully.
+                visualizer.flush_line(text)
+                tex.sprint('}')
+                -- Eat the processed characters
+                str = rest
+            else
+                -- Write the first character
+                tex.write(utf.sub(str, 1, 1))
+                -- Eat the first character
+                str = utf.sub(str, 2)
+            end
+        end
+    end
+end
+
+-- vim: set sw=4 sts=4 expandtab ai: