summaryrefslogtreecommitdiff
path: root/src/compiler/GF/Infra
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2014-07-27 22:13:13 +0000
committerhallgren <hallgren@chalmers.se>2014-07-27 22:13:13 +0000
commit59172ce9c5baf593e3110036a14c910da80878f7 (patch)
tree9ef752a113b9cbc84a04971ca2a7338eaeac6a50 /src/compiler/GF/Infra
parent30cda5151651e712803527b6ab4e5abc07536f2c (diff)
Adding GF.Infra.Location and GF.Text.Pretty (forgot to 'darcs add' them before)
Diffstat (limited to 'src/compiler/GF/Infra')
-rw-r--r--src/compiler/GF/Infra/Location.hs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/compiler/GF/Infra/Location.hs b/src/compiler/GF/Infra/Location.hs
new file mode 100644
index 000000000..b38482ff9
--- /dev/null
+++ b/src/compiler/GF/Infra/Location.hs
@@ -0,0 +1,31 @@
+module GF.Infra.Location where
+import GF.Text.Pretty
+
+class HasSourcePath a where sourcePath :: a -> FilePath
+
+data Location
+ = NoLoc
+ | Local Int Int
+ | External FilePath Location
+ deriving (Show,Eq,Ord)
+
+-- | Attaching location information
+data L a = L Location a deriving Show
+
+instance Functor L where fmap f (L loc x) = L loc (f x)
+
+unLoc :: L a -> a
+unLoc (L _ x) = x
+
+noLoc = L NoLoc
+
+ppLocation :: FilePath -> Location -> Doc
+ppLocation fpath NoLoc = pp fpath
+ppLocation fpath (External p l) = ppLocation p l
+ppLocation fpath (Local b e)
+ | b == e = fpath <> ":" <> b
+ | otherwise = fpath <> ":" <> b <> "-" <> e
+
+
+ppL (L loc x) msg = hang (ppLocation "" loc<>":") 4
+ ("In"<+>x<>":"<+>msg)