Import path parsing
This commit is contained in:
parent
99dcfbd976
commit
a19bcf0ad5
3 changed files with 27 additions and 12 deletions
|
@ -22,10 +22,12 @@ description: Please see the README on GitHub at <https://github.com/gith
|
|||
dependencies:
|
||||
- base >= 4.7 && < 5
|
||||
- containers
|
||||
- parsec
|
||||
- filepath
|
||||
- path
|
||||
- directory
|
||||
- exceptions
|
||||
- filepath
|
||||
- os-string
|
||||
- path
|
||||
- parsec
|
||||
|
||||
ghc-options:
|
||||
- -Wall
|
||||
|
|
|
@ -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 []
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue