cpphsSource codeContentsIndex
Language.Preprocessor.Cpphs.Tokenise
PortabilityAll
Stabilityexperimental
MaintainerMalcolm Wallace <Malcolm.Wallace@cs.york.ac.uk>
Description
The purpose of this module is to lex a source file (language unspecified) into tokens such that cpp can recognise a replaceable symbol or macro-use, and do the right thing.
Synopsis
linesCpp :: String -> [String]
reslash :: String -> String
tokenise :: Bool -> Bool -> Bool -> Bool -> [(Posn, String)] -> [WordStyle]
data WordStyle
= Ident Posn String
| Other String
| Cmd (Maybe HashDefine)
deWordStyle :: WordStyle -> String
parseMacroCall :: Posn -> [WordStyle] -> Maybe ([[WordStyle]], [WordStyle])
Documentation
linesCpp :: String -> [String]Source
linesCpp is, broadly speaking, Prelude.lines, except that on a line beginning with a #, line continuation characters are recognised. In a line continuation, the newline character is preserved, but the backslash is not.
reslash :: String -> StringSource
Put back the line-continuation characters.
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)
show/hide Instances
deWordStyle :: WordStyle -> StringSource
parseMacroCall :: Posn -> [WordStyle] -> Maybe ([[WordStyle]], [WordStyle])Source
Parse a possible macro call, returning argument list and remaining input
Produced by Haddock version 0.8