[TZ      All experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk>KMacro expansion text is divided into sections, each of which is classified F as one of three kinds: a formal argument (Arg), plain text (Text), * or a stringised formal argument (Str). smart; constructor to avoid warnings from ghc (undefined fields) Expand an instance of a macro. 0 Precondition: got a match on the macro name. Parse a # define, or #undef, ignoring other # directives  All experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> :Source positions contain a filename, line, column, and an = inclusion point, which is itself another source position,  recursively. ! Constructor "Updates #$%&' Projections ()*cpp-style printing +BStrip non-directory suffix from file name (analogous to the shell  command of the same name).  !"#$%&'()*  !"#$%&'()*All experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk>,9Each 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. -./0@Submodes are required to deal correctly with nesting of lexical  structures. 1234567FA Mode value describes whether to tokenise a la Haskell, or a la Cpp. D The main difference is that in Cpp mode we should recognise line  continuation characters. 89::linesCpp is, broadly speaking, Prelude.lines, except that  on a line beginning with a ##, line continuation characters are A recognised. In a line continuation, the newline character is ( preserved, but the backslash is not. ;+Put back the line-continuation characters. <=>;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 4 * All whitespace is preserved intact as tokens. I * C-comments are converted to white-space (depending on first param) 7 * Parens and commas are tokens in their own right. 0 * Any cpp line continuations are respected.  No errors can be raised. 7 The inverse of tokenise is (concatMap deWordStyle). ?IParse a possible macro call, returning argument list and remaining input ,-./:;=>? ,/.--./:;=>?%@The parser monad ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcd$@ACDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcd$@AACDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdAllStable/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk>efgh(Index Trees (storing indexes at nodes). ijk?Symbol Table. Stored values are polymorphic, but the keys are  always strings. lmnopqrsthklmnophklmnopAll experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk>uIAttempt to read the given file from any location within the search path. I The first location found is returned, together with the file content. E (The directory of the calling file is always searched first, then ? the current directory, finally any specified search path.)  filename inclusion point  search path #defined symbols 'discovered filepath, and file contents vuu wxyz{|}~: takes a filename (for error reports), and transforms the K given string, to eliminate the literate comments from the program text.  All experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk>      All experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> NWalk through the document, replacing calls of macros with their expanded RHS. %Pre-defined symbols and their values Strip C-comments? Accept # and ## operators? Retain layout in macros? Input language (Haskell/not) The input file content The file after processing $Turn command-line definitions (from -D) into s. FTrundle through the document, one word at a time, using the WordStyle  classification introduced by > to decide whether to expand a " word or macro. Encountering a # define or #undef causes that symbol to K be overwritten in the symbol table. Any other remaining cpp directives 6 are discarded and replaced with blanks, except for #line markers. F All valid identifiers are checked for the presence of a definition H of that name in the symbol table, and if so, expanded appropriately.   All experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> <Internal state for whether lines are being kept or dropped.  In Drop n b, n is the depth of nesting, b is whether A we have already succeeded in keeping some lines in a chain of  elif's $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. File for error reports %Pre-defined symbols and their values Search path for # includes Leave # define and #undef in output? Place #line droppings in output? The input file content %The file after processing (in lines) FReturn just the list of lines that the real cpp would decide to keep.   All experimental/Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk>                   !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~    cpphs-1.3Language.Preprocessor.UnlitLanguage.Preprocessor.Cpphs&Language.Preprocessor.Cpphs.HashDefine$Language.Preprocessor.Cpphs.Position$Language.Preprocessor.Cpphs.Tokenise#Text.ParserCombinators.HuttonMeijer"Language.Preprocessor.Cpphs.SymTab%Language.Preprocessor.Cpphs.ReadFirst#Language.Preprocessor.Cpphs.Options%Language.Preprocessor.Cpphs.MacroPass$Language.Preprocessor.Cpphs.CppIfdef$Language.Preprocessor.Cpphs.RunCpphsunlit CpphsOption CpphsPath CpphsMacro CpphsUnlit CpphsLayout CpphsAnsi CpphsStrip CpphsText CpphsNoLine CpphsNoMacro parseOption macroPasscppIfdefrunCpphs ArgOrTextStrTextArg HashDefineMacroExpansion arguments expansionSymbolReplacement replacement linebreaksLineDropnamesymbolReplacement expandMacroparseHashDefinePosnPnnewfileaddcolnewlinetabnewlinesnewposlinenofilename directorycpplinedirname WordStyleCmdOtherIdentSubModeCComment NestComment LineCommentStringPredAnyModeCppHaskelllinesCppreslashother deWordStyletokeniseparseMacroCallParserPTokenitemfirstpapply+++satmanymany1sepbysepby1chainlchainl1chainrchainr1opsbracketchardigitlowerupperletteralphanumstringidentnatintspacescommentjunkskiptokennaturalintegersymbol identifierHashable hashWithMaxhashIndTreeForkLeafSymTabemptySTinsertSTdeleteSTlookupST definedSTitgenitiapitindmaxHash readFirstreal ClassifiedPreIncludeCommentBlankProgramclassify unclassifyadjacentmessageinlinesflagstrailnoPos preDefine macroProcess KeepStateDropKeepcpp gatherDefined parseBoolExp parseExp1 parseExp0parseOp