cpphs-1.20.10: A liberalised re-implementation of cpp, the C pre-processor.

Copyright | 2000-2006 Malcolm Wallace
License | LGPL
Maintainer | Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk>
Stability | experimental
Portability | All
Safe Haskell | None
Language | Haskell2010

Language.Preprocessor.Cpphs

Description

Include the interface that is exported

Synopsis

- runCpphs :: CpphsOptions -> FilePath -> String -> IO String
- runCpphsPass1 :: CpphsOptions -> FilePath -> String -> IO [(Posn, String)]
- runCpphsPass2 :: BoolOptions -> [(String, String)] -> FilePath -> [(Posn, String)] -> IO String
- runCpphsReturningSymTab :: CpphsOptions -> FilePath -> String -> IO (String, [(String, String)])
- cppIfdef :: FilePath -> [(String, String)] -> [String] -> BoolOptions -> String -> IO [(Posn, String)]
- tokenise :: Bool -> Bool -> Bool -> Bool -> [(Posn, String)] -> [WordStyle]
- data WordStyle
  - = Ident Posn String
  - | Other String
  - | Cmd (Maybe HashDefine)
- macroPass :: [(String, String)] -> BoolOptions -> [(Posn, String)] -> IO String
- macroPassReturningSymTab :: [(String, String)] -> BoolOptions -> [(Posn, String)] -> IO (String, [(String, String)])
- data CpphsOptions = CpphsOptions {
  - infiles :: [FilePath]
  - outfiles :: [FilePath]
  - defines :: [(String, String)]
  - includes :: [String]
  - preInclude :: [FilePath]
  - boolopts :: BoolOptions
  }
- data BoolOptions = BoolOptions {
  - macros :: Bool
  - locations :: Bool
  - hashline :: Bool
  - pragma :: Bool
  - stripEol :: Bool
  - stripC89 :: Bool
  - lang :: Bool
  - ansi :: Bool
  - layout :: Bool
  - literate :: Bool
  - warnings :: Bool
  }
- parseOptions :: [String] -> Either String CpphsOptions
- defaultCpphsOptions :: CpphsOptions
- defaultBoolOptions :: BoolOptions
- directory :: Posn -> FilePath
- data Posn = Pn String !Int !Int (Maybe Posn)
- newfile :: String -> Posn
- newline :: Posn -> Posn
- newlines :: Int -> Posn -> Posn
- cppline :: Posn -> String
- cpp2hask :: String -> String
- newpos :: Int -> Maybe String -> Posn -> Posn
- filename :: Posn -> String
- lineno :: Posn -> Int
- addcol :: Int -> Posn -> Posn
- tab :: Posn -> Posn
- haskline :: Posn -> String
- cleanPath :: FilePath -> FilePath

# Documentation

runCpphs :: CpphsOptions -> FilePath -> String -> IO String Source #

runCpphsPass1 :: CpphsOptions -> FilePath -> String -> IO [(Posn, String)] Source #

runCpphsPass2 :: BoolOptions -> [(String, String)] -> FilePath -> [(Posn, String)] -> IO String Source #

runCpphsReturningSymTab :: CpphsOptions -> FilePath -> String -> IO (String, [(String, String)]) Source #

cppIfdef Source #

Arguments

:: FilePath | File for error reports
-> [(String, String)] | Pre-defined symbols and their values
-> [String] | Search path for #includes
-> BoolOptions | Options controlling output style
-> String | The input file content
-> IO [(Posn, String)] | The file after processing (in lines)

Run a first pass of cpp, evaluating #ifdef's and processing #include's, whilst taking account of #define's and #undef's as we encounter them.

tokenise :: Bool -> Bool -> Bool -> Bool -> [(Posn, String)] -> [WordStyle] Source #

tokenise is, broadly-speaking, Prelude.words, except that: * the input is already divided into lines * each word-like "token" is categorised as one of {Ident,Other,Cmd} * #define's are parsed and returned out-of-band using the Cmd variant * All whitespace is preserved intact as tokens. * C-comments are converted to white-space (depending on first param) * Parens and commas are tokens in their own right. * Any cpp line continuations are respected. No errors can be raised. The inverse of tokenise is (concatMap deWordStyle).

data WordStyle Source #

Each token is classified as one of Ident, Other, or Cmd: * Ident is a word that could potentially match a macro name. * Cmd is a complete cpp directive (#define etc). * Other is anything else.

Constructors

Ident Posn String |
Other String |
Cmd (Maybe HashDefine) |

#### Instances

Instances details

Show WordStyle Source # |
Instance details Defined in Language.Preprocessor.Cpphs.Tokenise Methods showsPrec :: Int -> WordStyle -> ShowS Source # show :: WordStyle -> String Source # showList :: [WordStyle] -> ShowS Source #
Eq WordStyle Source # |
Instance details Defined in Language.Preprocessor.Cpphs.Tokenise Methods (==) :: WordStyle -> WordStyle -> Bool Source # (/=) :: WordStyle -> WordStyle -> Bool Source #

macroPass Source #

Arguments

:: [(String, String)] | Pre-defined symbols and their values
-> BoolOptions | Options that alter processing style
-> [(Posn, String)] | The input file content
-> IO String | The file after processing

Walk through the document, replacing calls of macros with the expanded RHS.

macroPassReturningSymTab Source #

Arguments

:: [(String, String)] | Pre-defined symbols and their values
-> BoolOptions | Options that alter processing style
-> [(Posn, String)] | The input file content
-> IO (String, [(String, String)]) | The file and symbol table after processing

Walk through the document, replacing calls of macros with the expanded RHS. Additionally returns the active symbol table after processing.

data CpphsOptions Source #

Cpphs options structure.

Constructors

CpphsOptions |

Fields

- infiles :: [FilePath]
- outfiles :: [FilePath]
- defines :: [(String, String)]
- includes :: [String]
- preInclude :: [FilePath]

  Files to #include before anything else

- boolopts :: BoolOptions

#### Instances

Instances details

Show CpphsOptions Source # |
Instance details Defined in Language.Preprocessor.Cpphs.Options Methods showsPrec :: Int -> CpphsOptions -> ShowS Source # show :: CpphsOptions -> String Source # showList :: [CpphsOptions] -> ShowS Source #

data BoolOptions Source #

Options representable as Booleans.

Constructors

BoolOptions |

Fields

- macros :: Bool

  Leave #define and #undef in output of ifdef?

- locations :: Bool

  Place #line droppings in output?

- hashline :: Bool

  Write #line or {-# LINE #-} ?

- pragma :: Bool

  Keep #pragma in final output?

- stripEol :: Bool

  Remove C eol (//) comments everywhere?

- stripC89 :: Bool

  Remove C inline (/**/) comments everywhere?

- lang :: Bool

  Lex input as Haskell code?

- ansi :: Bool

  Permit stringise # and catenate ## operators?

- layout :: Bool

  Retain newlines in macro expansions?

- literate :: Bool

  Remove literate markup?

- warnings :: Bool

  Issue warnings?

#### Instances

Instances details

Show BoolOptions Source # |
Instance details Defined in Language.Preprocessor.Cpphs.Options Methods showsPrec :: Int -> BoolOptions -> ShowS Source # show :: BoolOptions -> String Source # showList :: [BoolOptions] -> ShowS Source #

parseOptions :: [String] -> Either String CpphsOptions Source #

Parse all command-line options.

defaultCpphsOptions :: CpphsOptions Source #

Default options.

defaultBoolOptions :: BoolOptions Source #

Default settings of boolean options.

directory :: Posn -> FilePath Source #

Project the directory of the filename.

data Posn Source #

Source positions contain a filename, line, column, and an inclusion point, which is itself another source position, recursively.

Constructors

Pn String !Int !Int (Maybe Posn) |

#### Instances

Instances details

Show Posn Source # |
Instance details Defined in Language.Preprocessor.Cpphs.Position Methods showsPrec :: Int -> Posn -> ShowS Source # show :: Posn -> String Source # showList :: [Posn] -> ShowS Source #
Eq Posn Source # |
Instance details Defined in Language.Preprocessor.Cpphs.Position Methods (==) :: Posn -> Posn -> Bool Source # (/=) :: Posn -> Posn -> Bool Source #

newfile :: String -> Posn Source #

Constructor. Argument is filename.

newline :: Posn -> Posn Source #

Increment row number, reset column to 1.

newlines :: Int -> Posn -> Posn Source #

Increment row number by given quantity.

cppline :: Posn -> String Source #

cpp-style printing of file position

cpp2hask :: String -> String Source #

Conversion from a cpp-style "#line" to haskell-style pragma.

newpos :: Int -> Maybe String -> Posn -> Posn Source #

Update position with a new row, and possible filename.

filename :: Posn -> String Source #

Project the filename.

lineno :: Posn -> Int Source #

Project the line number.

addcol :: Int -> Posn -> Posn Source #

Increment column number by given quantity.

tab :: Posn -> Posn Source #

Increment column number, tab stops are every 8 chars.

haskline :: Posn -> String Source #

haskell-style printing of file position

cleanPath :: FilePath -> FilePath Source #

Sigh. Mixing Windows filepaths with unix is bad. Make sure there is a canonical path separator.