{-# LANGUAGE CPP, DeriveDataTypeable #-}------------------------------------------------------------------------------- |-- Module : Language.Haskell.Exts.SrcLoc-- Copyright : (c) Niklas Broberg 2009-- License : BSD-style (see the file LICENSE.txt)---- Maintainer : Niklas Broberg, d00nibro@chalmers.se-- Stability : stable-- Portability : portable---- This module defines various data types representing source location-- information, of varying degree of preciseness.-------------------------------------------------------------------------------moduleLanguage.Haskell.Exts.SrcLocwhere#ifdef __GLASGOW_HASKELL__#ifdef BASE4importData.Data#elseimportData.Generics(Data(..),Typeable(..))#endif#endif-- | A single position in the source.dataSrcLoc=SrcLoc{srcFilename::String,srcLine::Int,srcColumn::Int}#ifdef __GLASGOW_HASKELL__deriving(Eq,Ord,Show,Typeable,Data)#elsederiving(Eq,Ord,Show)#endif-- | A portion of the source, spanning one or more lines and zero or more columns.dataSrcSpan=SrcSpan{srcSpanFilename::String,srcSpanStartLine::Int,srcSpanStartColumn::Int,srcSpanEndLine::Int,srcSpanEndColumn::Int}#ifdef __GLASGOW_HASKELL__deriving(Eq,Ord,Show,Typeable,Data)#elsederiving(Eq,Ord,Show)#endif-- | Returns 'srcSpanStartLine' and 'srcSpanStartColumn' in a pair.srcSpanStart::SrcSpan->(Int,Int)srcSpanStartx=(srcSpanStartLinex,srcSpanStartColumnx)-- | Returns 'srcSpanEndLine' and 'srcSpanEndColumn' in a pair.srcSpanEnd::SrcSpan->(Int,Int)srcSpanEndx=(srcSpanEndLinex,srcSpanEndColumnx)-- | Combine two locations in the source to denote a span.mkSrcSpan::SrcLoc->SrcLoc->SrcSpanmkSrcSpan(SrcLocfnslsc)(SrcLoc_elec)=SrcSpanfnslscelec-- | Merge two source spans into a single span from the start of the first-- to the end of the second. Assumes that the two spans are given in the-- order they appear in the source.mergeSrcSpan::SrcSpan->SrcSpan->SrcSpanmergeSrcSpan(SrcSpanfnslsc__)(SrcSpan___elec)=SrcSpanfnslscelec-- | Test if a given span starts and ends at the same location.isNullSpan::SrcSpan->BoolisNullSpanss=srcSpanStartLiness==srcSpanEndLiness&&srcSpanStartColumnss>=srcSpanEndColumnss-- | An entity located in the source.dataLoca=Loc{loc::SrcSpan,unLoc::a}deriving(Eq,Ord,Show)-- | A portion of the source, extended with information on the position of entities within the span.dataSrcSpanInfo=SrcSpanInfo{srcInfoSpan::SrcSpan-- , explLayout :: Bool,srcInfoPoints::[SrcSpan]-- Marks the location of specific entities inside the span}#ifdef __GLASGOW_HASKELL__deriving(Eq,Ord,Show,Typeable,Data)#elsederiving(Eq,Ord,Show)#endifnoInfoSpan::SrcSpan->SrcSpanInfonoInfoSpanss=SrcSpanInfoss[]infoSpan::SrcSpan->[SrcSpan]->SrcSpanInfoinfoSpanxy=SrcSpanInfoxy(<++>),combSpanInfo::SrcSpanInfo->SrcSpanInfo->SrcSpanInfocombSpanInfos1s2=SrcSpanInfo(mergeSrcSpan(srcInfoSpans1)(srcInfoSpans2))[](<++>)=combSpanInfo(<+?>)::SrcSpanInfo->MaybeSrcSpanInfo->SrcSpanInfoa<+?>b=casebof{Nothing->a;Justb->a<++>b}(<?+>)::MaybeSrcSpanInfo->SrcSpanInfo->SrcSpanInfoa<?+>b=caseaof{Nothing->b;Justa->a<++>b}(<**)::SrcSpanInfo->[SrcSpan]->SrcSpanInfoss@(SrcSpanInfo{srcInfoPoints=ps})<**xs=ss{srcInfoPoints=ps++xs}(<^^>)::SrcSpan->SrcSpan->SrcSpanInfoa<^^>b=noInfoSpan(mergeSrcSpanab)infixl6<^^>infixl5<++>infixl4<**,<+?>,<?+>classSrcInfosiwheretoSrcInfo::SrcLoc->[SrcSpan]->SrcLoc->sifromSrcInfo::SrcSpanInfo->sigetPointLoc::si->SrcLocfileName::si->StringstartLine::si->IntstartColumn::si->IntgetPointLocsi=SrcLoc(fileNamesi)(startLinesi)(startColumnsi)instanceSrcInfoSrcLocwheretoSrcInfos__=sfromSrcInfosi=SrcLoc(fileNamesi)(startLinesi)(startColumnsi)fileName=srcFilenamestartLine=srcLinestartColumn=srcColumninstanceSrcInfoSrcSpanwheretoSrcInfost_end=mkSrcSpanstendfromSrcInfo=srcInfoSpanfileName=srcSpanFilenamestartLine=srcSpanStartLinestartColumn=srcSpanStartColumninstanceSrcInfoSrcSpanInfowheretoSrcInfostptsend=SrcSpanInfo(mkSrcSpanstend)ptsfromSrcInfo=idfileName=fileName.srcInfoSpanstartLine=startLine.srcInfoSpanstartColumn=startColumn.srcInfoSpan