diff --git a/fco2/Makefile b/fco2/Makefile index 61d59b9..ba9605f 100644 --- a/fco2/Makefile +++ b/fco2/Makefile @@ -18,7 +18,8 @@ sources = \ SimplifyProcs.hs \ TLP.hs \ Types.hs \ - Unnest.hs + Unnest.hs \ + Utils.hs $(targets): $(sources) ghc -fglasgow-exts -o fco --make Main diff --git a/fco2/Metadata.hs b/fco2/Metadata.hs index 4e300a4..642e84b 100644 --- a/fco2/Metadata.hs +++ b/fco2/Metadata.hs @@ -3,6 +3,8 @@ module Metadata where import Data.Generics +import Utils + data Meta = Meta { metaFile :: Maybe String, metaLine :: Int, @@ -20,5 +22,5 @@ emptyMeta = Meta { instance Show Meta where show m = case metaFile m of - Just s -> s ++ ":" ++ show (metaLine m) ++ ":" ++ show (metaColumn m) + Just s -> basenamePath s ++ ":" ++ show (metaLine m) ++ ":" ++ show (metaColumn m) Nothing -> "no source position" diff --git a/fco2/Parse.hs b/fco2/Parse.hs index c8af117..a461824 100644 --- a/fco2/Parse.hs +++ b/fco2/Parse.hs @@ -19,6 +19,7 @@ import Metadata import ParseState import Pass import Types +import Utils --{{{ setup stuff for Parsec type OccParser = GenParser Char ParseState @@ -1416,16 +1417,6 @@ mangleModName mod then mod else mod ++ ".occ" --- | Join a relative path to an existing path (i.e. if you're given foo/bar and --- baz, return foo/baz). -joinPath :: String -> String -> String -joinPath base new - = case matchRegex pathRE base of - Just [dir] -> dir ++ new - Nothing -> new - where - pathRE = mkRegex "^(.*/)[^/]*$" - type LoaderM a = StateT ParseState IO a -- | Load all the source files necessary for a program. diff --git a/fco2/Utils.hs b/fco2/Utils.hs new file mode 100644 index 0000000..62e3d18 --- /dev/null +++ b/fco2/Utils.hs @@ -0,0 +1,30 @@ +-- | Utility functions that aren't inherently related to FCO -- i.e. things +-- that could be put into the standard library. +module Utils where + +import Text.Regex + +-- | Split the directory and file components of a path. +splitPath :: String -> (String, String) +splitPath path + = case matchRegex dirRE path of + Just [dir, base] -> (if dir == "" then "." else dir, base) + where + dirRE = mkRegex "^(.*/)?([^/]*)$" + +-- | Return the directory containing a path. +dirnamePath :: String -> String +dirnamePath = fst . splitPath + +-- | Return a path without any leading directory components. +basenamePath :: String -> String +basenamePath = snd . splitPath + +-- | Join a relative path to an existing path (i.e. if you're given foo/bar and +-- baz, return foo/baz). +joinPath :: String -> String -> String +joinPath base new + = case dirnamePath base of + "." -> new + dir -> dir ++ new +