broken: fixed circular import (File -> Import -> File)
This commit is contained in:
parent
a4cd711574
commit
6990c3f759
2 changed files with 13 additions and 5 deletions
|
@ -13,11 +13,15 @@ import Data.Functor ((<&>))
|
|||
|
||||
import Text.Parsec (choice, ParsecT, many)
|
||||
|
||||
import Ubc.Parse.Syntax (Transformer)
|
||||
|
||||
import {-# SOURCE #-} Ubc.Parse.Syntax.Import (Import)
|
||||
import Ubc.Parse.Syntax.Struct (Struct)
|
||||
import Ubc.Parse.Syntax.Function (Function)
|
||||
import Ubc.Parse.Syntax.Statement (Statement)
|
||||
import Ubc.Parse.Syntax.Enumeration (Enumeration)
|
||||
|
||||
import {-# SOURCE #-} qualified Ubc.Parse.Syntax.Import as Import
|
||||
import qualified Ubc.Parse.Syntax.Struct as Struct
|
||||
import qualified Ubc.Parse.Syntax.Function as Function
|
||||
import qualified Ubc.Parse.Syntax.Statement as Statement
|
||||
|
@ -30,7 +34,8 @@ data File = File
|
|||
deriving (Show)
|
||||
|
||||
data FileBody = FileBody
|
||||
{ structs :: [Struct]
|
||||
{ imports :: [Import]
|
||||
, structs :: [Struct]
|
||||
, functions :: [Function]
|
||||
, statements :: [Statement]
|
||||
, enumerations :: [Enumeration]
|
||||
|
@ -39,12 +44,13 @@ data FileBody = FileBody
|
|||
deriving (Semigroup, Monoid) via Generically FileBody
|
||||
-- dont use `deriving ... via FileBody` because that leads to a loop, somehow
|
||||
|
||||
parse :: Monad m => String -> ParsecT String u m File
|
||||
parse :: String -> ParsecT String u Transformer File
|
||||
parse source = File source <$!> mconcat <$!> many fileMember
|
||||
|
||||
fileMember :: Monad m => ParsecT String u m FileBody
|
||||
fileMember :: ParsecT String u Transformer FileBody
|
||||
fileMember = choice
|
||||
[ Struct.parse <&> \s -> mempty { structs = [s] }
|
||||
, Import.parse <&> \i -> mempty { imports = [i] }
|
||||
, Function.parse <&> \f -> mempty { functions = [f] }
|
||||
, Statement.parse <&> \s -> mempty { statements = [s] }
|
||||
, Enumeration.parse <&> \e -> mempty { enumerations = [e] }
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{-# LANGUAGE LambdaCase #-}
|
||||
{-# LANGUAGE DerivingStrategies #-}
|
||||
module Ubc.Parse.Syntax.Import
|
||||
( parse
|
||||
, Import(..)
|
||||
|
@ -37,6 +38,7 @@ data Import = Import
|
|||
{ file :: File.File
|
||||
, alias :: String
|
||||
}
|
||||
deriving stock (Show)
|
||||
|
||||
importPath :: Monad m => ParsecT String u m (NonEmpty String)
|
||||
importPath = UbcLanguage.angles (many importChar `sepBy1` char '/')
|
||||
|
@ -84,7 +86,7 @@ notFoundMessage relFile searchedLocations = "Could not locate import file path"
|
|||
<> "Searched locations were:"
|
||||
<> (unlines . List.map (('\t':) . Path.fromAbsFile) $ searchedLocations)
|
||||
|
||||
parseFile :: MonadIO m => Path Abs File -> String -> ParsecT String u m Import
|
||||
parseFile :: Path Abs File -> String -> ParsecT String u Transformer Import
|
||||
parseFile path importAs = do
|
||||
let stringPath = Path.fromAbsFile path
|
||||
contents <- liftIO . readFile $ stringPath
|
||||
|
|
Loading…
Reference in a new issue