Permalink
Browse files

* Added a list of commands

  • Loading branch information...
1 parent 0057d6b commit 977841d2630c08f9387e00efb982d556d779e8a6 @spockz spockz committed Oct 2, 2011
Showing with 41 additions and 22 deletions.
  1. +25 −5 src/Base/CLI.hs
  2. +16 −17 src/LiterateHighlighter.hs
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
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 977841d

Please sign in to comment.