@@ -74,7 +74,13 @@ type data ImportPhase where
7474------------------------------------------------------------
7575-- Anchor
7676
77- -- | An "anchor" from which to interpret a path.
77+ -- | An "anchor" from which to interpret a path: an absolute path, a
78+ -- web URL, a local path (i.e. relative to CWD), or the home
79+ -- directory.
80+ --
81+ -- In the future, if we wanted to have some kind of standard
82+ -- library, we could add a fifth kind of anchor which refers to the
83+ -- location of the stdlib files.
7884data Anchor (phase :: ImportPhase ) where
7985 -- | Absolute, /i.e./ relative to the filesystem root.
8086 Absolute :: Anchor phase
@@ -339,8 +345,6 @@ d1 <//> ImportLoc d2 f = ImportLoc (d1 <> d2) f
339345------------------------------------------------------------
340346-- Import resolution
341347
342- -- XXX simply assume web resources exist without checking? + require them to be fully named...?
343-
344348-- | Resolve an import directory, turning it into an absolute path.
345349resolveImportDir :: Has (Lift IO ) sig m => ImportDir Raw -> m (ImportDir Resolved )
346350resolveImportDir (ImportDir a p) = case a of
@@ -356,17 +360,15 @@ resolveImportDir (ImportDir a p) = case a of
356360-- | Check whether a given 'ImportLoc' in fact exists. Note that, for
357361-- the sake of efficiency, this simply assumes that any 'Web'
358362-- resource exists without checking; all other locations will
359- -- actually be checked.
363+ -- actually be checked. This means, for example, that web imports
364+ -- must have an `.sw` extension fully written out.
360365doesLocationExist :: (Has (Lift IO ) sig m ) => ImportLoc Resolved -> m Bool
361366doesLocationExist loc = do
362367 let fp = locToFilePath loc
363368 case importAnchor loc of
364369 Web {} -> pure True
365370 _ -> sendIO $ doesFileExist fp
366371
367- -- XXX need to be able to resolve "local" to something in a standard
368- -- Swarm data location, instead of just looking up CWD??
369-
370372-- | Resolve an import location, by turning the path into an absolute
371373-- path, and optionally adding a .sw suffix to the file name.
372374resolveImportLoc :: Has (Lift IO ) sig m => ImportLoc Raw -> m (ImportLoc Resolved )
@@ -382,7 +384,7 @@ resolveImportLoc (ImportLoc d f) = do
382384 (False , True ) -> pure loc'sw
383385 _ -> pure loc'
384386
385- -- XXX
387+ -- | Turn any import loc back into a raw one.
386388unresolveImportLoc :: ImportLoc a -> ImportLoc Raw
387389unresolveImportLoc (ImportLoc d f) = ImportLoc (unresolveImportDir d) f
388-
390+
0 commit comments