From: Matthijs Kooijman Date: Thu, 20 Aug 2009 17:37:26 +0000 (+0200) Subject: Add a haskell pretty printer. X-Git-Tag: final-thesis~303 X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=1108517b5c84c5fc7c8aa21ac60cd33e28487519;p=matthijs%2Fmaster-project%2Freport.git Add a haskell pretty printer. This pretty printer is mostly just verbatim text, but with the ability to apply strikethrough to lines by putting dashes around the text. --- diff --git a/SConstruct b/SConstruct index 043fd45..3411e32 100644 --- a/SConstruct +++ b/SConstruct @@ -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') diff --git a/Utils/Formats.tex b/Utils/Formats.tex index 5dc0158..63a58df 100644 --- a/Utils/Formats.tex +++ b/Utils/Formats.tex @@ -15,3 +15,13 @@ % 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] + diff --git a/Utils/Lambda.tex b/Utils/Lambda.tex index e4f2a1b..b5b2e7a 100644 --- a/Utils/Lambda.tex +++ b/Utils/Lambda.tex @@ -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 index 0000000..483d660 --- /dev/null +++ b/pret-haskell.lua @@ -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: