Skip to content
Browse files

Merge branch 'master' of https://github.com/spockz/lhs2texhl

  • Loading branch information...
2 parents 8420c76 + 60bacfe commit d67087a7e5219fa4d21324ef6026769e0cea0bcb @norm2782 committed Oct 3, 2011
Showing with 49 additions and 28 deletions.
  1. +3 −3 examples/theme1.tex
  2. +1 −1 lhs2TeX-hl.cabal
  3. +25 −5 src/Base/CLI.hs
  4. +1 −1 src/Base/Common.hs
  5. +3 −1 src/Literate/Haskell.hs
  6. +16 −17 src/LiterateHighlighter.hs
View
6 examples/theme1.tex
@@ -21,6 +21,6 @@
\newcommand{\lhsCHtype}[1]{\color{datatype}{{#1}}}
\newcommand{\lhsCHclass}[1]{\color{class}{{#1}}}
-%subst char a = "\color{char}\text{\tt ''" a "''}"
-%subst string a = "\color{string}\text{\tt \char34 " a "\char34}"
-%subst numeral a = "\color{numeral}{ " a " }"
+%subst char a = "{\color{char}\text{\tt ''" a "''}}"
+%subst string a = "{\color{string}\text{\tt \char34 " a "\char34}}"
+%subst numeral a = "{\color{numeral}{ " a " }}"
View
2 lhs2TeX-hl.cabal
@@ -1,5 +1,5 @@
Name: lhs2TeX-hl
-Version: 0.1.3.3
+Version: 0.1.4.0
Cabal-Version: >= 1.6
License: MIT
Author: Alessandro Vermeulen <me@alessandrovermeulen.me>
View
30 src/Base/CLI.hs
@@ -1,12 +1,19 @@
{-# LANGUAGE DeriveDataTypeable #-}
-module Base.CLI (ProgramOptions(..), usage, standard, module System.Console.CmdArgs) where
+module Base.CLI (ProgramOptions(..), Action(..), usage, newCommands, standard, module System.Console.CmdArgs) where
import System.Console.CmdArgs
import Base.Common
+data Action = Format | ListCommands
+ deriving (Show, Typeable, Data)
+
+instance Default Action where
+ def = Format
+
data ProgramOptions = ProgramOptions
{ agda_mode :: Bool
+ , action :: Action
, input :: [FilePath]
, output :: FilePath
} deriving (Show, Data, Typeable)
@@ -20,16 +27,29 @@ usage = unlines
, " https://github.com/spockz/lhs2texhl"
, "Copyright 2010, Alessandro Vermeulen <me@alessandrovermeulen.me>" ]
-
+newCommands :: String
+newCommands = unlines [
+ "\\newcommand{\\lhsCHfunction}[1]{\\color{infixoperator}{{#1}}}",
+ "\\newcommand{\\lhsCHinfixoperator}[1]{\\color{infixoperator}{{#1}}}",
+ "\\newcommand{\\lhsCHprelude}[1]{\\color{prelude}{{#1}}}",
+ "\\newcommand{\\lhsCHkeyword}[1]{\\color{keyword}{{#1}}}",
+ "\\newcommand{\\lhsCHconstructor}[1]{\\color{constructor}{{#1}}}",
+ "\\newcommand{\\lhsCHlitNumber}[1]{\\color{numeral}{{#1}}}",
+ "\\newcommand{\\lhsCHtype}[1]{\\color{datatype}{{#1}}}",
+ "\\newcommand{\\lhsCHsyntax}[1]{\\color{syntax}{{#1}}}",
+ "\\newcommand{\\lhsCHclass}[1]{\\color{class}{{#1}}}",
+ "\\newcommand{\\lhsCHconstant}[1]{\\color{prelude}{{#1}}}"
+ ]
-- | Standard command line options.
--
standard = cmdArgsMode $ ProgramOptions
{
- agda_mode = def &= help "Run in agda-mode!"
- , output = (def &= help "Output file") &= typFile
- , input = (def &= args )
+ agda_mode = def &= help "Run in agda-mode!"
+ , action = (def &= help "What should the program do? Format|ListCommands.") &= typ "Action"
+ , output = (def &= help "Output file") &= typFile
+ , input = (def &= args )
} &= summary usage
View
2 src/Base/Common.hs
@@ -1,4 +1,4 @@
module Base.Common where
-programVersion = "0.1.3.2"
+programVersion = "0.1.4.0"
programName = "lhs2TeX-hl"
View
4 src/Literate/Haskell.hs
@@ -11,6 +11,8 @@ import Language.Haskell.Exts hiding (parseFile)
import Language.LaTeX
import Literate.SimpleInfo
+
+import Debug.Trace (trace)
newtype M = M Module deriving (Typeable, Data)
@@ -142,7 +144,7 @@ mapping = [
mtypes :: SimpleInfo -> [(String, String)]
mtypes SimpleInfo{types} = map dp types
-moperators SimpleInfo{operators} = map (\ a -> (a, "\\ "++ makeLatexSafe a++"\\ "))
+moperators SimpleInfo{operators} = trace "Operators:\n" $ trace (show operators) $ map (\ a -> (a, "\\ \\mathbin{"++ makeLatexSafe a++"}\\ "))
operators
mconstructors SimpleInfo{constructors} = map (dp) constructors
mfunctions SimpleInfo{functions } = map (dp) functions
View
33 src/LiterateHighlighter.hs
@@ -28,29 +28,28 @@ main = do args <- cmdArgsRun standard
hSetEncoding stdout utf8
hSetEncoding stderr utf8
- hOutput <- openFile (output args) WriteMode
- hSetEncoding hOutput utf8
-
- let writer = writeOutput hOutput
-
- if (agda_mode args)
- then
- error "Agda mode is currently not supported."
- -- mapM_ (\file -> runAgda file
- -- >>= (flip writer) Literate.Agda.mapping)
- -- (input args)
- else
- mapM_ (\file -> runHaskell file
- >>= (flip writer) Literate.Haskell.mapping)
- (input args)
-
- hClose hOutput
+ case (action args) of
+ ListCommands -> putStr newCommands
+ _ -> if (agda_mode args)
+ then
+ error "Agda mode is currently not supported."
+ else
+ printFormatting args
+
where printFormat keyword seek rep = "%format " ++ seek ++ " = \" {\\lhsCH" ++ keyword ++ "{" ++ rep ++ "}}\""
writeOutput output si mapping =
mapM_ (\(keyword, f) -> mapM_ (\ (seek,rep) -> hPutStrLn output $ printFormat keyword seek rep)
(filter lhs2TeXSafe (f si))
)
mapping
+ printFormatting args = do hOutput <- openFile (output args) WriteMode
+ let writer = writeOutput hOutput
+ hSetEncoding hOutput utf8
+ mapM_ (\file -> runHaskell file
+ >>= (flip writer) Literate.Haskell.mapping)
+ (input args)
+ hClose hOutput
+
lhs2TeXSafe :: (String, String) -> Bool
lhs2TeXSafe ("()" , _) = False

0 comments on commit d67087a

Please sign in to comment.
Something went wrong with that request. Please try again.