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

Copyright2000-2006 Malcolm Wallace
LicenseLGPL
MaintainerMalcolm Wallace <Malcolm.Wallace@cs.york.ac.uk>
Stabilityexperimental
PortabilityAll
Safe HaskellNone
LanguageHaskell98

Language.Preprocessor.Cpphs

Description

Include the interface that is exported

Synopsis

Documentation

cppIfdef #

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] #

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 #

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) 

macroPass #

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 #

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 #

Cpphs options structure.

Constructors

CpphsOptions 

Fields

data BoolOptions #

Options representable as Booleans.

Constructors

BoolOptions 

Fields

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

Parse all command-line options.

defaultBoolOptions :: BoolOptions #

Default settings of boolean options.

data Posn #

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

Eq Posn # 

Methods

(==) :: Posn -> Posn -> Bool #

(/=) :: Posn -> Posn -> Bool #

Show Posn # 

Methods

showsPrec :: Int -> Posn -> ShowS #

show :: Posn -> String #

showList :: [Posn] -> ShowS #

newfile :: String -> Posn #

Constructor. Argument is filename.

addcol :: Int -> Posn -> Posn #

Increment column number by given quantity.

newline :: Posn -> Posn #

Increment row number, reset column to 1.

tab :: Posn -> Posn #

Increment column number, tab stops are every 8 chars.

newlines :: Int -> Posn -> Posn #

Increment row number by given quantity.

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

Update position with a new row, and possible filename.

cppline :: Posn -> String #

cpp-style printing of file position

haskline :: Posn -> String #

haskell-style printing of file position

cpp2hask :: String -> String #

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

filename :: Posn -> String #

Project the filename.

lineno :: Posn -> Int #

Project the line number.

directory :: Posn -> FilePath #

Project the directory of the filename.

cleanPath :: FilePath -> FilePath #

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