Add a haskell pretty printer.
authorMatthijs Kooijman <m.kooijman@student.utwente.nl>
Thu, 20 Aug 2009 17:37:26 +0000 (19:37 +0200)
committerMatthijs Kooijman <m.kooijman@student.utwente.nl>
Thu, 20 Aug 2009 17:38:22 +0000 (19:38 +0200)
This pretty printer is mostly just verbatim text, but with the ability to
apply strikethrough to lines by putting dashes around the text.

SConstruct
Utils/Formats.tex
Utils/Lambda.tex
pret-haskell.lua [new file with mode: 0644]

index 043fd453d09659e39f9c7b055dcd9f4e90fba082..3411e32d2058068fbc741924a660b9fbf24df6a4 100644 (file)
@@ -34,6 +34,7 @@ Depends(core2core, 'pret-trans.lua')
 report = env.Context('Report')
 Depends(report, 'pret-lam.lua')
 Depends(report, 'pret-trans.lua')
+Depends(report, 'pret-haskell.lua')
 Depends(report, 'Chapters/State.tex')
 Depends(report, 'Utils/Fonts.tex')
 Depends(report, 'Utils/Formats.tex')
index 5dc0158c23bba389bce649bb20fec58094313049..63a58dfce4ad938b5c6f673c7ce6e92019001d8d 100644 (file)
         % a bunch of empty space at the start of the frame.
         \framed[offset=0mm,location=middle,strut=no,align=right,frame=off]{#1}
 }
+
+% Define a \strikethrough command. For some reason, this does blue
+strikethrough, sometime that still needs fixing.
+\definetextbackground
+  [strikethrough]
+  [location=text,
+   alternative=4,
+   background=,
+   frame=off]
+
index e4f2a1bfe36b19f3d861f4489908515e8b40e0c8..b5b2e7a85e37e3685247ba12ec23e94cad37be3d 100644 (file)
@@ -14,3 +14,8 @@
 \installprettytype [TRANS] [TRANS]
 % Define \starttrans \stoptrans
 \definetyping[trans][option=TRANS,style=normal,before=,after=]
+
+% Install the haskell pretty-printer, as defined in pret-haskell.lua.
+\installprettytype [HASKELL] [HASKELL]
+% Define \starthaskell \stophaskell
+\definetyping[haskell][option=HASKELL,before=,after=]
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: