-- | Define a position datatype for giving locations in error messages.moduleText.XML.HaXml.Posn(-- * Position typePosn()-- ** Constructors of a new position,posInNewCxt-- :: String -> Maybe Posn -> Posn,noPos-- :: Posn-- ** Strictifier,forcep-- ** Modifiers,addcol,newline,tab,white-- ** Accessors,posnFilename,posnLine,posnColumn)whereimportData.Char-- | Source positions contain a filename, line, column, and an-- inclusion point, which is itself another source position,-- recursively.dataPosn=PnString!Int!Int(MaybePosn)deriving(Eq)posnFilename::Posn->FilePathposnFilename(Pnf___)=fposnLine,posnColumn::Posn->IntposnLine(Pn_x__)=xposnColumn(Pn__x_)=x-- | Dummy value for generated data, where a true source position does-- not exist.noPos::PosnnoPos=Pn"no recorded position"00Nothing-- | @posInNewCxt name pos@ creates a new source position from an old one.-- It is used when opening a new file (e.g. a DTD inclusion), to denote-- the start of the file @name@, but retain the stacked information that-- it was included from the old @pos@.posInNewCxt::String->MaybePosn->PosnposInNewCxtnamepos=Pnname11posinstanceShowPosnwhereshowsPrec_(Pnflci)=showString"file ".showStringf.showString" at line ".showsl.showString" col ".showsc.(caseiofNothing->idJustp->showString"\n used by ".showsp)-- | Just used to strictify the internal values of a position, to avoid-- space leaks.forcep::Posn->Intforcep(Pn_nm_)=m`seq`n-- | Add n character positions to the given position.addcol::Int->Posn->Posnaddcoln(Pnfrci)=Pnfr(c+n)i-- | Add a newline or tab to the given position.newline,tab::Posn->Posnnewline(Pnfr_i)=Pnf(r+1)1itab(Pnfrci)=Pnfr(((c`div`8)+1)*8)i-- | Add the given whitespace char to the given position.-- Precondition: @white c | isSpace c = True@white::Char->Posn->Posnwhite' '=addcol1white'\n'=newlinewhite'\r'=idwhite'\t'=tabwhite'\xa0'=addcol1whitex|isSpacex=addcol1-- other Unicode whitespacewhite_=error"precondition not satisfied: Posn.white c | isSpace c"