------------------------------------------------------------------------------- |-- Module : Language.Haskell.Exts-- Copyright : (c) Niklas Broberg 2004-2009-- License : BSD-style (see the file LICENSE.txt)---- Maintainer : Niklas Broberg, d00nibro@chalmers.se-- Stability : stable-- Portability : portable---- An umbrella module for the various functionality-- of the package. Also provides some convenient-- functionality for dealing directly with source files.-------------------------------------------------------------------------------moduleLanguage.Haskell.Exts(-- * Re-exported modulesmoduleLanguage.Haskell.Exts.Syntax,moduleLanguage.Haskell.Exts.Build,moduleLanguage.Haskell.Exts.Parser,moduleLanguage.Haskell.Exts.Pretty,moduleLanguage.Haskell.Exts.Extension,moduleLanguage.Haskell.Exts.Fixity,moduleLanguage.Haskell.Exts.Comments-- * Parsing of Haskell source files,parseFile,parseFileWithMode,parseFileWithExts,parseFileContents,parseFileContentsWithMode-- * Read extensions declared in LANGUAGE pragmas,readExtensions)whereimportLanguage.Haskell.Exts.BuildimportLanguage.Haskell.Exts.SyntaximportLanguage.Haskell.Exts.ParserimportLanguage.Haskell.Exts.PrettyimportLanguage.Haskell.Exts.ExtensionimportLanguage.Haskell.Exts.FixityimportLanguage.Haskell.Exts.CommentsimportData.ListimportLanguage.Preprocessor.Unlit-- | Parse a source file on disk, using the default parse mode.parseFile::FilePath->IO(ParseResultModule)parseFilefp=parseFileWithMode(defaultParseMode{parseFilename=fp})fp-- | Parse a source file on disk, with an extra set of extensions to know about-- on top of what the file itself declares.parseFileWithExts::[Extension]->FilePath->IO(ParseResultModule)parseFileWithExtsextsfp=parseFileWithMode(defaultParseMode{extensions=exts,parseFilename=fp})fp-- | Parse a source file on disk, supplying a custom parse mode.parseFileWithMode::ParseMode->FilePath->IO(ParseResultModule)parseFileWithModepfp=readFilefp>>=(return.parseFileContentsWithModep)-- | Parse a source file from a string using the default parse mode.parseFileContents::String->ParseResultModuleparseFileContents=parseFileContentsWithModedefaultParseMode-- | Parse a source file from a string, with an extra set of extensions to know about-- on top of what the file itself declares.parseFileContentsWithExts::[Extension]->String->ParseResultModuleparseFileContentsWithExtsexts=parseFileContentsWithMode(defaultParseMode{extensions=exts})-- | Parse a source file from a string using a custom parse mode.parseFileContentsWithMode::ParseMode->String->ParseResultModuleparseFileContentsWithModep@(ParseModefnextsign__)rawStr=letmd=delitfn$ppContentsrawStrallExts=impliesExts$case(ign,readExtensionsmd)of(False,Justes)->exts++es_->extsinparseWithMode(p{extensions=allExts})md-- | Gather the extensions declared in LANGUAGE pragmas-- at the top of the file. Returns 'Nothing' if the-- parse of the pragmas fails.readExtensions::String->Maybe[Extension]readExtensionsstr=casegetTopPragmasstrofParseOkpgms->Just(concatMapgetExtspgms)_->NothingwheregetExts::OptionPragma->[Extension]getExts(LanguagePragma_ns)=mapreadExtnsgetExts_=[]readExt(Idente)=classifyExtensioneppContents::String->StringppContents=unlines.f.lineswheref(('#':_):rest)=restfx=xdelit::String->String->Stringdelitfn=if".lhs"`isSuffixOf`fnthenunlitfnelseid