Compare commits

..

No commits in common. "6990c3f7593f79d42fcf5fd8f0f9b673d501a816" and "6242b2f1eb3232022277f973d3ecdf806703ea8a" have entirely different histories.

4 changed files with 5 additions and 18 deletions

View file

@ -1,7 +1,4 @@
module Ubc.Parse.Syntax.Expression
( Expression(..)
, expressionParser
)
where
import Text.Parsec (ParsecT)

View file

@ -13,15 +13,11 @@ 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.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
@ -34,8 +30,7 @@ data File = File
deriving (Show)
data FileBody = FileBody
{ imports :: [Import]
, structs :: [Struct]
{ structs :: [Struct]
, functions :: [Function]
, statements :: [Statement]
, enumerations :: [Enumeration]
@ -44,13 +39,12 @@ data FileBody = FileBody
deriving (Semigroup, Monoid) via Generically FileBody
-- dont use `deriving ... via FileBody` because that leads to a loop, somehow
parse :: String -> ParsecT String u Transformer File
parse :: Monad m => String -> ParsecT String u m File
parse source = File source <$!> mconcat <$!> many fileMember
fileMember :: ParsecT String u Transformer FileBody
fileMember :: Monad m => ParsecT String u m 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] }

View file

@ -1,5 +1,4 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE DerivingStrategies #-}
module Ubc.Parse.Syntax.Import
( parse
, Import(..)
@ -38,7 +37,6 @@ 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 '/')
@ -86,7 +84,7 @@ notFoundMessage relFile searchedLocations = "Could not locate import file path"
<> "Searched locations were:"
<> (unlines . List.map (('\t':) . Path.fromAbsFile) $ searchedLocations)
parseFile :: Path Abs File -> String -> ParsecT String u Transformer Import
parseFile :: MonadIO m => Path Abs File -> String -> ParsecT String u m Import
parseFile path importAs = do
let stringPath = Path.fromAbsFile path
contents <- liftIO . readFile $ stringPath

View file

@ -1,6 +1,4 @@
module Ubc.Parse.Syntax.Statement
( Statement
)
where
data Statement