diff --git a/package.yaml b/package.yaml index 874de9f..a5b2696 100644 --- a/package.yaml +++ b/package.yaml @@ -22,10 +22,12 @@ description: Please see the README on GitHub at = 4.7 && < 5 - containers -- parsec -- filepath -- path - directory +- exceptions +- filepath +- os-string +- path +- parsec ghc-options: - -Wall diff --git a/src/Ubc/Parse/Syntax/Import.hs b/src/Ubc/Parse/Syntax/Import.hs index 4c7c0b7..bd631de 100644 --- a/src/Ubc/Parse/Syntax/Import.hs +++ b/src/Ubc/Parse/Syntax/Import.hs @@ -3,17 +3,22 @@ module Ubc.Parse.Syntax.Import parse) where +import Control.Monad.Catch ( SomeException () ) + +import Data.Functor ((<&>)) +import Data.List.NonEmpty (NonEmpty) + import Text.Parsec (sepBy1, ParsecT, anyChar, many, char, choice, notFollowedBy, oneOf) -import OsPath as OsPath +import Path as Path ( Path, File, parseRelFile, Rel, parseRelDir, Dir ) import qualified Ubc.Parse.Syntax.Language as UbcLanguage -import System.OsPath (encodeUtf, OsPath) -import System.OsPath.Encoding (EncodingException (EncodingError)) -import Control.Exception (SomeException(SomeException)) +import qualified Data.List.NonEmpty as NonEmpty +import Control.Monad (liftM2) -importPath :: Monad m => ParsecT String u m [String] +importPath :: Monad m => ParsecT String u m (NonEmpty String) importPath = UbcLanguage.angles (many importChar `sepBy1` char '/') + <&> NonEmpty.fromList importChar :: (Monad m) => ParsecT String u m Char importChar = choice @@ -25,9 +30,11 @@ parse :: ParsecT String u IO [String] parse = do UbcLanguage.reserved "import" fragments <- importPath - case mapM encodeUtf fragments :: Either EncodingException [OsPath] of - Left err -> pure () - Right success -> pure () - pure [] + let name = Path.parseRelFile $ NonEmpty.last fragments :: Either SomeException (Path Rel File) + let dirPath = mapM Path.parseRelDir . NonEmpty.init $ fragments :: Either SomeException [Path Rel Dir] + + case liftM2 (,) name dirPath of + Left err -> pure [] + Right success -> pure [] diff --git a/ubcc.cabal b/ubcc.cabal index 106a473..3aee142 100644 --- a/ubcc.cabal +++ b/ubcc.cabal @@ -48,7 +48,9 @@ library base >=4.7 && <5 , containers , directory + , exceptions , filepath + , os-string , parsec , path default-language: Haskell2010 @@ -66,7 +68,9 @@ executable ubcc-exe base >=4.7 && <5 , containers , directory + , exceptions , filepath + , os-string , parsec , path , ubcc @@ -86,7 +90,9 @@ test-suite ubcc-test base >=4.7 && <5 , containers , directory + , exceptions , filepath + , os-string , parsec , path , ubcc