------------------------------------------------------------------------------- |-- 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.Annotated(-- * Re-exported modulesmoduleLanguage.Haskell.Exts.Annotated.Syntax,moduleLanguage.Haskell.Exts.Annotated.Build,moduleLanguage.Haskell.Exts.Parser,moduleLanguage.Haskell.Exts.Pretty,moduleLanguage.Haskell.Exts.Annotated.Fixity,moduleLanguage.Haskell.Exts.Annotated.ExactPrint,moduleLanguage.Haskell.Exts.SrcLoc,moduleLanguage.Haskell.Exts.Comments,moduleLanguage.Haskell.Exts.Extension-- * Parsing of Haskell source files,parseFile,parseFileWithMode,parseFileWithExts,parseFileWithComments,parseFileContents,parseFileContentsWithMode,parseFileContentsWithExts,parseFileContentsWithComments-- * Parsing of Haskell source elements,,parseModule,parseModuleWithMode,parseModuleWithComments,parseExp,parseExpWithMode,parseExpWithComments,parseStmt,parseStmtWithMode,parseStmtWithComments,parsePat,parsePatWithMode,parsePatWithComments,parseDecl,parseDeclWithMode,parseDeclWithComments,parseType,parseTypeWithMode,parseTypeWithComments-- * Read extensions declared in LANGUAGE pragmas,readExtensions)whereimportLanguage.Haskell.Exts.Annotated.BuildimportLanguage.Haskell.Exts.Annotated.SyntaximportLanguage.Haskell.Exts.Parser(Parseable(..),ParseResult(..),fromParseResult,ParseMode(..),defaultParseMode)importLanguage.Haskell.Exts.PrettyimportLanguage.Haskell.Exts.Annotated.FixityimportLanguage.Haskell.Exts.Annotated.ExactPrintimportLanguage.Haskell.Exts.SrcLocimportLanguage.Haskell.Exts.ExtensionimportLanguage.Haskell.Exts.CommentsimportLanguage.Haskell.Exts.InternalParserimportData.ListimportLanguage.Preprocessor.Unlit-- | Parse a source file on disk, using the default parse mode.parseFile::FilePath->IO(ParseResult(ModuleSrcSpanInfo))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(ParseResult(ModuleSrcSpanInfo))parseFileWithExtsextsfp=parseFileWithMode(defaultParseMode{extensions=exts,parseFilename=fp})fp-- | Parse a source file on disk, supplying a custom parse mode.parseFileWithMode::ParseMode->FilePath->IO(ParseResult(ModuleSrcSpanInfo))parseFileWithModepfp=readFilefp>>=(return.parseFileContentsWithModep)parseFileWithComments::ParseMode->FilePath->IO(ParseResult(ModuleSrcSpanInfo,[Comment]))parseFileWithCommentspfp=readFilefp>>=(return.parseFileContentsWithCommentsp)-- | Parse a source file from a string using the default parse mode.parseFileContents::String->ParseResult(ModuleSrcSpanInfo)parseFileContents=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->ParseResult(ModuleSrcSpanInfo)parseFileContentsWithExtsexts=parseFileContentsWithMode(defaultParseMode{extensions=exts})-- | Parse a source file from a string using a custom parse mode.parseFileContentsWithMode::ParseMode->String->ParseResult(ModuleSrcSpanInfo)parseFileContentsWithModep@(ParseModefnextsign__)rawStr=letmd=delitfn$ppContentsrawStrallExts=impliesExts$case(ign,readExtensionsmd)of(False,Justes)->exts++es_->extsinparseModuleWithMode(p{extensions=allExts})mdparseFileContentsWithComments::ParseMode->String->ParseResult(ModuleSrcSpanInfo,[Comment])parseFileContentsWithCommentsp@(ParseModefnextsign__)rawStr=letmd=delitfn$ppContentsrawStrallExts=impliesExts$case(ign,readExtensionsmd)of(False,Justes)->exts++es_->extsinparseModuleWithComments(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::OptionPragmal->[Extension]getExts(LanguagePragma_ns)=mapreadExtnsgetExts_=[]readExt(Ident_e)=classifyExtensioneppContents::String->StringppContents=unlines.f.lineswheref(('#':_):rest)=restfx=xdelit::String->String->Stringdelitfn=if".lhs"`isSuffixOf`fnthenunlitfnelseid