hscolour 1.10.1 → 1.11
raw patch · 8 files changed
+89/−53 lines, 8 files
Files
- HsColour.hs +11/−21
- Language/Haskell/HsColour.hs +31/−22
- Language/Haskell/HsColour/Options.hs +22/−0
- Language/Haskell/HsColour/Output.hs +9/−0
- Makefile +4/−2
- README +3/−3
- hscolour.cabal +4/−2
- index.html +5/−3
HsColour.hs view
@@ -1,27 +1,16 @@ module Main where import Language.Haskell.HsColour+import qualified Language.Haskell.HsColour as HSColour import Language.Haskell.HsColour.Colourise (readColourPrefs)-+import Language.Haskell.HsColour.Options import System import IO (hPutStrLn,hFlush,stdout,stderr,hSetBuffering,BufferMode(..)) import Monad (when) import List (intersperse)--version = "1.10.1"+import Debug.Trace --- | Command-line options-data Option =- Help -- ^ print usage message- | Version -- ^ report version- | Information -- ^ report auxiliary information, e.g. CSS defaults- | Format Output -- ^ what type of output to produce- | LHS Bool -- ^ literate input (i.e. multiple embedded fragments)- | Anchors Bool -- ^ whether to add anchors- | Partial Bool -- ^ whether to produce a full document or partial- | Input FilePath -- ^ input source file- | Output FilePath -- ^ output source file- deriving Eq+version = "1.11" optionTable :: [(String,Option)] optionTable = [ ("help", Help)@@ -32,8 +21,9 @@ , ("tty", Format TTY) , ("latex", Format LaTeX) , ("mirc", Format MIRC)- , ("lit", LHS True)- , ("nolit", LHS False)+ , ("lit", LHS Bird)+ , ("lit-tex",LHS TeX)+ , ("nolit", LHS NoLit) , ("anchor", Anchors True) , ("noanchor", Anchors False) , ("partial", Partial True)@@ -58,11 +48,11 @@ outFile = [ f | Output f <- good ] fileInteract = fileInteractOut outFile output = useDefault TTY id formats- ioWrapper = useDefault ttyInteract fileInteract [ f | Input f <- good ]+ ioWrapper = useDefault ttyInteract fileInteract [ f | Input f <- good ] anchors = useDefault False id [ b | Anchors b <- good ] partial = useDefault False id [ b | Partial b <- good ]- lhs = useDefault False id [ b | LHS b <- good ] - title = useDefault "Haskell code" id [ f | Input f <- good ]+ lhs = useDefault NoLit id [ b | LHS b <- good ] + title = useDefault "Haskell code" id [ f | Input f <- good ] when (not (null bad)) (errorOut ("Unrecognised option(s): "++unwords bad++"\n"++usage prog)) when (Help `elem` good) (do putStrLn (usage prog); exitSuccess)@@ -74,7 +64,7 @@ ++unwords (map show formats))) when (length outFile > 1) (errorOut ("Can only have one output file at a time."))- ioWrapper (hscolour output pref anchors partial lhs title)+ ioWrapper (HSColour.hscolour output pref anchors partial lhs title) hFlush stdout where
Language/Haskell/HsColour.hs view
@@ -20,30 +20,30 @@ import qualified Language.Haskell.HsColour.CSS as CSS import qualified Language.Haskell.HsColour.LaTeX as LaTeX import qualified Language.Haskell.HsColour.MIRC as MIRC---- | The supported output formats.-data Output = TTY -- ^ ANSI terminal codes- | LaTeX -- ^ TeX macros- | HTML -- ^ HTML with font tags- | CSS -- ^ HTML with CSS.- | MIRC -- ^ mIRC chat clients- deriving (Eq,Show)+import Data.List(mapAccumL, isPrefixOf) +import Data.Maybe+import Language.Haskell.HsColour.Output+import Language.Haskell.HsColour.Options (Literate(..))+import Debug.Trace -- | Colourise Haskell source code with the given output format. hscolour :: Output -- ^ Output format. -> ColourPrefs -- ^ Colour preferences (for formats that support them). -> Bool -- ^ Whether to include anchors. -> Bool -- ^ Whether output document is partial or complete.- -> Bool -- ^ Whether input document is literate haskell or not+ -> Literate -- ^ Whether input document is literate haskell or not -> String -- ^ Title for output. -> String -- ^ Haskell source code. -> String -- ^ Coloured Haskell source code.-hscolour output pref anchor partial literate title- | literate = concatMap chunk . joinL . map lhsClassify . inlines- | otherwise = hscolour' output pref anchor partial title+hscolour output pref anchor partial literate title =+ case literate of+ NoLit -> hscolour' output pref anchor partial title+ Bird -> literateHandler (map lhsClassify)+ TeX -> literateHandler (snd . mapAccumL decideTypeOfLine False) where- chunk (Literate c) = c- chunk (Code c) = hscolour' output pref anchor True title c+ literateHandler f = concatMap chunk . joinL . f . inlines+ chunk (Lit c) = c+ chunk (Code c) = hscolour' output pref anchor True title c hscolour' :: Output -- ^ Output format. -> ColourPrefs -- ^ Colour preferences (for formats that support them).@@ -59,7 +59,7 @@ hscolour' CSS _ anchor partial top = CSS.hscolour anchor partial top -- | Separating literate files into code\/comment chunks.-data Literate = Code {unL :: String} | Literate {unL :: String}+data Lit = Code {unL :: String} | Lit {unL :: String} deriving (Show) -- Re-implementation of 'lines', for better efficiency (but decreased laziness). -- Also, importantly, accepts non-standard DOS and Mac line ending characters.@@ -75,13 +75,22 @@ -- Note, I just pass the > symbol to the colouriser, which assumes that -- it's token based and not parse-based!!!-lhsClassify :: String -> Literate+lhsClassify :: String -> Lit lhsClassify ('>':xs) = Code ('>':xs)-lhsClassify xs = Literate xs+lhsClassify xs = Lit xs -joinL :: [Literate] -> [Literate]-joinL [] = []-joinL (Code c:Code c2:xs) = joinL (Code (c++c2):xs)-joinL (Literate c:Literate c2:xs) = joinL (Literate (c++c2):xs)-joinL (any:xs) = any: joinL xs+-- texstyle is a bool indicating whether we are currently inside a code block+decideTypeOfLine texStyle current_line + | isPrefix "\\begin{code}" = codeLine+ | texStyle = if not is_end then codeLine else (False, Code (current_line ))+ | otherwise = (False, Lit current_line)+ where isPrefix = flip isPrefixOf current_line + codeLine = (True, Code (current_line))+ is_end = isPrefix "\\end{code}"++joinL :: [Lit] -> [Lit]+joinL [] = []+joinL (Code c:Code c2:xs) = joinL (Code (c++c2):xs)+joinL (Lit c :Lit c2 :xs) = joinL (Lit (c++c2):xs)+joinL (any:xs) = any: joinL xs
+ Language/Haskell/HsColour/Options.hs view
@@ -0,0 +1,22 @@+module Language.Haskell.HsColour.Options+ ( Option(..)+ , Output(..)+ , Literate(..)+ ) where ++import Language.Haskell.HsColour.Output++-- | Command-line options+data Option =+ Help -- ^ print usage message+ | Version -- ^ report version+ | Information -- ^ report auxiliary information, e.g. CSS defaults+ | Format Output -- ^ what type of output to produce+ | LHS Literate -- ^ literate input (i.e. multiple embedded fragments)+ | Anchors Bool -- ^ whether to add anchors+ | Partial Bool -- ^ whether to produce a full document or partial+ | Input FilePath -- ^ input source file+ | Output FilePath -- ^ output source file+ deriving Eq++data Literate = NoLit | Bird | TeX deriving Eq
+ Language/Haskell/HsColour/Output.hs view
@@ -0,0 +1,9 @@+module Language.Haskell.HsColour.Output where++-- | The supported output formats.+data Output = TTY -- ^ ANSI terminal codes+ | LaTeX -- ^ TeX macros+ | HTML -- ^ HTML with font tags+ | CSS -- ^ HTML with CSS.+ | MIRC -- ^ mIRC chat clients+ deriving (Eq,Show)
Makefile view
@@ -1,5 +1,5 @@ LIBRARY = hscolour-VERSION = 1.10.1+VERSION = 1.11 DIRS = Language/Haskell/HsColour @@ -14,7 +14,9 @@ Language/Haskell/HsColour/HTML.hs \ Language/Haskell/HsColour/LaTeX.hs \ Language/Haskell/HsColour/TTY.hs \- Language/Haskell/HsColour/MIRC.hs+ Language/Haskell/HsColour/MIRC.hs \+ Language/Haskell/HsColour/Output.hs \+ Language/Haskell/HsColour/Options.hs AUX = README LICENCE* $(LIBRARY).cabal Setup.hs Makefile \ HsColour.hs hscolour.css .hscolour \
README view
@@ -1,6 +1,6 @@ HsColour: A Haskell source-code colouriser. --------------------------------------------Copyright: 2003-2008, Malcolm Wallace, University of York+Copyright: 2003-2009, Malcolm Wallace, University of York Licence: GPL Building:@@ -11,8 +11,8 @@ Usage: HsColour [-Ofile] [ -tty | -html | -css | -latex | -mirc ]- [ -lit | -anchor | -partial ]- [ -nolit | -noanchor| -nopartial ]+ [ -lit | -lit-tex | -anchor | -partial ]+ [ -nolit | -noanchor| -nopartial ] [file.hs] The program can colourise a Haskell source file for either terminal
hscolour.cabal view
@@ -1,6 +1,6 @@ Name: hscolour-Version: 1.10.1-Copyright: Malcolm Wallace, University of York, 2003-2008, Bjorn Bringert 2006+Version: 1.11+Copyright: 2003-2009 Malcolm Wallace, University of York; 2006 Bjorn Bringert Maintainer: Malcolm Wallace Author: Malcolm Wallace Homepage: http://www.cs.york.ac.uk/fp/darcs/hscolour/@@ -31,6 +31,8 @@ Language.Haskell.HsColour.General, Language.Haskell.HsColour.MIRC, Language.Haskell.HsColour.CSS+ Language.Haskell.HsColour.Output+ Language.Haskell.HsColour.Options data-files: hscolour.css --ghc-options: -O -W Build-Type: Simple
index.html view
@@ -61,7 +61,7 @@ HsColour [ -help | -version | -print-css ] [ -oOUTPUT ] [ -tty | -html | -css | -latex | -mirc ]- [ -lit | -nolit ]+ [ -lit | -lit-tex | -nolit ] [ -anchor | -noanchor | -partial | -nopartial ] [file.hs]</pre> </li></ul>@@ -90,7 +90,8 @@ then the <tt>-lit</tt> option will pass the literate parts untouched, and colourise only the code fragments (indicated by Bird-tracks - a > in the left-most column), as if each was called individually with-<tt>-partial</tt>.+<tt>-partial</tt>. A literate file containing LaTeX rather than+Bird-style should use <tt>-lit-tex</tt> instead. <h2>Configuration of colours</h2>@@ -187,6 +188,7 @@ <h2>History</h2> <p> <dl>+<dt>1.11</dt><dd> new literate input option -lit-tex <dt>1.10.1</dt><dd> reports the correct version with the --version flag <dt>1.10</dt><dd> the title of HTML output is now the filename</dd> <dt>1.9</dt><dd> added the -mirc and -lit options, and -print-css</dd>@@ -205,7 +207,7 @@ </dl> <p>-This page last modified: 3rd Sept 2008<br>+This page last modified: 19th Jan 2009<br> Malcolm Wallace<br> </td></tr></table>