HatParser.hs revision bdc17bb22397639e89c698b3909c4cee399b556c
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley{-|
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob HalleyModule : $Header$
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob HalleyCopyright : (c) Christian Maeder, Uni Bremen 2002-2005
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob HalleyLicence : similar to LGPL, see HetCATS/LICENCE.txt or LIZENZ.txt
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob HalleyMaintainer : hets@tzi.de
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob HalleyStability : provisional
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob HalleyPortability : non-portable(multiple parameter class, functional dependency)
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley Wrapper for Haskell parsing.
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley Parses Haskell declarations (not a whole module), for use
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley in heterogeneous specifications
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley-}
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleymodule Haskell.HatParser (module P, HsDecls(..), hatParser) where
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleyimport AST4ModSys as P(toMod)
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleyimport DefinedNames as P(DefinedNames)
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleyimport Ents as P(Ent(Ent))
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleyimport HasBaseName as P(HasBaseName(getBaseName))
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleyimport HsConstants as P(mod_Prelude)
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleyimport HsDeclStruct as P
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleyimport HsModule as P (HsModuleI(HsModule))
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleyimport HsName as P (hsUnQual, HsName(UnQual))
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleyimport LexerOptions as P(lexerflags0)
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleyimport Lift as P(Lift(lift))
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleyimport Modules as P(inscope)
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleyimport MUtils as P(mapFst)
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleyimport Names as P(QualNames(getQualified), QName)
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleyimport NewPrettyPrint as P(pp)
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleyimport OrigTiMonad as P(withStdNames, inModule, extendts,
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halley extendkts, extendIEnv)
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleyimport ParseMonad as P(parseTokens)
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleyimport PNT as P(PNT(PNT))
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleyimport PPfeInstances()
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleyimport PrettyPrint2 as P(Printable)
a5d43b72413db3edd6b36a58f9bdf2cf6ff692f2Bob Halleyimport PropLexer as P(pLexerPass0)
import PropParser as P(parse)
import PropPosSyntax as P hiding(Id, HsName)
import ReAssocBase as P(getInfixes)
import ReAssocModule as P(reAssocModule)
import Relations as P(applyRel, minusRel, mapDom, emptyRel, Rel)
import ScopeModule as P(origName, scopeModule)
import SourceNames as P(fakeSN, SN(SN))
import TiClasses as P(TAssump, TypeCheckDecls(tcTopDecls), HasDefs(fromDefs))
import TiDefinedNames as P(definedType)
import TiInstanceDB as P(Instance)
import TiNames as P(ValueId(topName))
import TiPropDecorate as P(TiDecl, TiDecls)
import TiTypes as P(Kind, Scheme, Typing((:>:)), Assump, TypeInfo)
import TypedIds as P(IdTy(Value), HasNameSpace(namespace))
import UniqueNames as P(noSrcLoc, Orig(G), PN(PN))
import WorkModule as P(mkWM, WorkModuleI)
import Haskell.Wrapper
import Text.ParserCombinators.Parsec
import Common.PrettyPrint
import Common.Lib.Pretty
import Common.Result
instance PrettyPrint HsDecls where
printText0 _ ds =
vcat (map (text . ((++) "\n") . pp) $ hsDecls ds)
data HsDecls = HsDecls { hsDecls :: [HsDeclI (SN HsName)] } deriving (Show, Eq)
hatParser :: GenParser Char st HsDecls
hatParser = do p <- getPosition
s <- hStuff
let (l, c) = (sourceLine p, sourceColumn p)
ts = pLexerPass0 lexerflags0
(replicate (l-2) '\n' ++
"module Prelude where\n" ++
replicate (c-1) ' ' ++ s)
case parseTokens P.parse (sourceName p) ts of
Result _ (Just (HsModule _ _ _ _ ds)) ->
return $ HsDecls ds
Result ds Nothing -> unexpected
('\n' : unlines (map diagString ds)
++ "(in Haskell code after " ++ shows p ")")