diff --git a/.github/workflows/haskell.yml b/.github/workflows/ci.yml similarity index 99% rename from .github/workflows/haskell.yml rename to .github/workflows/ci.yml index 09c50bc..111c3da 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: Haskell CI +name: CI on: push: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..114b12f --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,74 @@ +name: Publish + +on: + release: + types: [published] + +permissions: + contents: write + +env: + # | + # WARNING: Don't put spaces around the | character. + LAYERS: | + LH0|B + LH1|B D + LH2|P B L + # TODO: These are placeholders. Later on, we will decide on what each layer should provide. + +jobs: + build: + strategy: + matrix: + include: + - os: ubuntu-latest + name: linux + ext: "" + archive: tar.gz + - os: windows-latest + name: win + ext: ".exe" + archive: zip + - os: macos-latest + name: osx + ext: "" + archive: tar.gz + runs-on: ${{ matrix.os }} + env: + FOLDER: LayeredHaskell-${{ matrix.name }} + ARCHIVE: LayeredHaskell-${{ matrix.name }}.${{ matrix.archive }} + + steps: + - uses: actions/checkout@v4 + - uses: haskell-actions/setup@v2 + with: + ghc-version: '9.6.7' + cabal-version: '3.12.1.0' + + - name: Build all layers + shell: bash + run: | + cabal update + mkdir -p "dist/$FOLDER" + while IFS='|' read -r name features; do + [ -z "$name" ] && continue + cabal run LayeredHaskell-make -- set $features < /dev/null + cabal build exe:LayeredHaskell < /dev/null + cp "$(cabal list-bin exe:LayeredHaskell)" "dist/$FOLDER/$name${{ matrix.ext }}" + done <<< "$LAYERS" + + - name: Create archive + shell: bash + run: | + cd dist + if [ "${{ matrix.archive }}" = "zip" ]; then + 7z a "../$ARCHIVE" "$FOLDER" + else + tar -czf "../$ARCHIVE" "$FOLDER" + fi + + - name: Attach to release + shell: bash + env: + GH_TOKEN: ${{ github.token }} + run: gh release upload "${{ github.event.release.tag_name }}" "$ARCHIVE" \ No newline at end of file diff --git a/LayeredHaskell-make/LayeredHaskell-make.cabal b/LayeredHaskell-make/LayeredHaskell-make.cabal index 5a631c9..0227a45 100644 --- a/LayeredHaskell-make/LayeredHaskell-make.cabal +++ b/LayeredHaskell-make/LayeredHaskell-make.cabal @@ -59,9 +59,14 @@ tested-with: GHC == 9.6.7 -- Extra source files to be distributed with the package, such as examples, or a tutorial module. extra-source-files: - src/LH/Feature/Features - src/LH/Feature/**/*.hs - src/LH/Feature/**/*.y + src/LHMake/Feature/Features + src/LHMake/Feature/**/*.hs + src/LHMake/Feature/**/*.y + +source-repository head + type: git + location: https://github.com/hshkk/LayeredHaskell + subdir: LayeredHaskell-make common warnings ghc-options: -Wall @@ -86,13 +91,13 @@ library -- Other library packages from which modules are imported. build-depends: - , base ^>=4.18.3.0 - , containers ^>=0.6.7 - , directory ^>=1.3.8 - , filepath ^>=1.4.301 - , happy-lib ^>=2.2 - , haskell-src ^>=1.0.4 - , text ^>=2.0.2 + , base ^>=4.18.3.0 + , containers ^>=0.6.7 + , directory ^>=1.3.8 + , filepath ^>=1.4.301 + , happy-lib ^>=2.2 + , haskell-src-exts ^>=1.24.0 + , text ^>=2.0.2 -- Directories containing source files. hs-source-dirs: src @@ -111,6 +116,9 @@ executable LayeredHaskell-make other-modules: Paths_LayeredHaskell_make + autogen-modules: + Paths_LayeredHaskell_make + -- LANGUAGE extensions used by modules in this package. -- other-extensions: diff --git a/LayeredHaskell-make/src/LHMake/Control/Superimposition.hs b/LayeredHaskell-make/src/LHMake/Control/Superimposition.hs index bbdb8d9..94acf2f 100644 --- a/LayeredHaskell-make/src/LHMake/Control/Superimposition.hs +++ b/LayeredHaskell-make/src/LHMake/Control/Superimposition.hs @@ -43,27 +43,28 @@ The following example illustrates its use on two Haskell files. module LHMake.Control.Superimposition ( -- * Superimposition Superimposable (..), Identifiable (..), + -- ** Parsing + parseMode, -- ** Identifiers - DeclId (..), DirectiveId (..), + PragmaId (..), DeclId (..), DirectiveId (..), -- ** Flattening lists - flattenDecls, flattenTokens, + flattenPragmas, flattenDecls, flattenTokens, -- ** Token precedences precs, groupPrecs ) where import Control.Applicative ((<|>)) import Data.Char (isSpace) +import Data.Functor (void) import Data.List (nub, partition) import Data.Map (Map) -import Data.Maybe (catMaybes) +import Data.Maybe (catMaybes, fromMaybe) import qualified Data.Map as Map import qualified Happy.Frontend.AbsSyn as Y import qualified Happy.Frontend.PrettyGrammar as Y -import qualified Language.Haskell.Parser as H -import qualified Language.Haskell.Pretty as H -import qualified Language.Haskell.Syntax as H +import qualified Language.Haskell.Exts as H import LHMake.Data.Error (LHsMakeError) @@ -96,7 +97,8 @@ class Identifiable a where identify :: a -> LHsMakeError (Identifier a) -- | Lists are superimposed element by element. --- Elements with the same identifier are superimposed, and elements that only the right list has are added at the end. +-- Elements with the same identifier are superimposed, +-- and elements that only the right list has are added at the end. instance (Identifiable a, Eq (Identifier a), Superimposable a) => Superimposable [a] where xs --> ys = do xids <- traverse identify xs @@ -109,29 +111,74 @@ instance (Identifiable a, Eq (Identifier a), Superimposable a) => Superimposable -- Haskell ------------------------------------------------------------------------------- -instance Superimposable H.HsQName -instance Superimposable H.HsCName -instance Superimposable H.HsConDecl -instance Superimposable H.HsMatch - -instance Identifiable H.HsQName where - type Identifier H.HsQName = H.HsQName +-- | 'H.defaultParseMode' but with 'H.fixities' set to 'Nothing'. +-- +-- Operator precedence resolution is disabled since superimposition does +-- not merge expressions (e.g., RHSs of function clauses). +parseMode :: H.ParseMode +parseMode = H.defaultParseMode { H.fixities = Nothing } + +-- All Haskell syntax trees here carry the annotation (), since the source +-- positions the parser records would otherwise make equal values compare as different. + +instance Superimposable (H.CName ()) +instance Superimposable (H.QualConDecl ()) +instance Superimposable (H.InstRule ()) +instance Superimposable (H.Match ()) + +instance Identifiable (H.CName ()) where + type Identifier (H.CName ()) = H.Name () + identify (H.VarName _ name) = Right name + identify (H.ConName _ name) = Right name + +-- | A constructor is identified by its name. +instance Identifiable (H.QualConDecl ()) where + type Identifier (H.QualConDecl ()) = H.Name () + identify (H.QualConDecl _ _ _ con) = case con of + H.ConDecl _ name _ -> Right name + H.InfixConDecl _ _ name _ -> Right name + H.RecDecl _ name _ -> Right name + +instance Identifiable (H.InstRule ()) where + type Identifier (H.InstRule ()) = H.InstRule () identify = Right -instance Identifiable H.HsCName where - type Identifier H.HsCName = H.HsName - identify (H.HsVarName name) = Right name - identify (H.HsConName name) = Right name - -instance Identifiable H.HsConDecl where - type Identifier H.HsConDecl = H.HsName - identify (H.HsConDecl _ name _) = Right name - identify (H.HsRecDecl _ name _) = Right name +-- | Splits a function clause into its name and patterns. +-- An infix definition such as @x ++ y = e@ is treated like @(++) x y = e@. +clause :: H.Match l -> (H.Name l, [H.Pat l]) +clause (H.Match _ name pats _ _) = (name, pats) +clause (H.InfixMatch _ pat name pats _ _) = (name, pat : pats) -- | A function is identified by its patterns. -instance Identifiable H.HsMatch where - type Identifier H.HsMatch = [H.HsPat] - identify (H.HsMatch _ _ pats _ _) = Right pats +instance Identifiable (H.Match ()) where + type Identifier (H.Match ()) = [H.Pat ()] + identify = Right . snd . clause + +-- Pragmas -------------------------------------------------------------------- + +-- | Identifiers for module pragmas. +data PragmaId + = Extension (H.Name ()) -- ^ A @LANGUAGE@ pragma. + | Options (Maybe H.Tool) [String] -- ^ An @OPTIONS@ pragma, such as @OPTIONS_GHC@. + | Annotated (H.ModulePragma ()) -- ^ An @ANN@ pragma, identified by its contents. + deriving Eq + +-- | Splits a @LANGUAGE@ pragma holding several extensions into one pragma per extension. +-- +-- For instance, @{-# LANGUAGE A, B #-}@ is flattened into @{-# LANGUAGE A #-}@ and @{-# LANGUAGE B #-}@. +-- All other pragmas are left as is. +flattenPragmas :: H.ModulePragma () -> [H.ModulePragma ()] +flattenPragmas (H.LanguagePragma _ names) = [H.LanguagePragma () [name] | name <- names] +flattenPragmas pragma = [pragma] + +instance Superimposable (H.ModulePragma ()) + +instance Identifiable (H.ModulePragma ()) where + type Identifier (H.ModulePragma ()) = PragmaId + identify (H.LanguagePragma _ [name]) = Right (Extension name) + identify (H.LanguagePragma _ _) = Left "Cannot merge a LANGUAGE pragma that holds several extensions" + identify (H.OptionsPragma _ tool opt) = Right (Options tool (words opt)) + identify pragma@(H.AnnModulePragma _ _) = Right (Annotated pragma) -- Modules -------------------------------------------------------------------- @@ -139,87 +186,127 @@ instance Identifiable H.HsMatch where -- Variable bindings (such as @x = e@) are also rewritten as function bindings, since they get parsed as a pattern binding. -- -- For instance, the Haskell type signature @f g :: A@ is flattened into @f :: A@ and @g :: A@. -flattenDecls :: H.HsDecl -> [H.HsDecl] -flattenDecls (H.HsTypeSig loc names ty) = [H.HsTypeSig loc [name] ty | name <- names] -flattenDecls (H.HsInfixDecl loc assoc prec ops) = [H.HsInfixDecl loc assoc prec [op] | op <- ops] -flattenDecls (H.HsPatBind loc (H.HsPVar name) rhs wheres) - = [H.HsFunBind [H.HsMatch loc name [] rhs wheres]] -flattenDecls (H.HsInstDecl loc ctx cls tys decls) - = [H.HsInstDecl loc ctx cls tys (concatMap flattenDecls decls)] +-- +-- Note that pragmas attached to declarations (such as @WARNING@) are dropped by 'flattenDecls'. +flattenDecls :: H.Decl () -> [H.Decl ()] +flattenDecls (H.TypeSig _ names ty) = [H.TypeSig () [name] ty | name <- names] +flattenDecls (H.InfixDecl _ assoc prec ops) = [H.InfixDecl () assoc prec [op] | op <- ops] +flattenDecls (H.PatBind _ (H.PVar _ name) rhs wheres) + = [H.FunBind () [H.Match () name [] rhs wheres]] +flattenDecls (H.InstDecl _ overlap rule decls) + = [H.InstDecl () overlap rule (fmap (concatMap flattenInstDecl) decls)] +flattenDecls H.InlineSig {} = [] +flattenDecls H.InlineConlikeSig {} = [] +flattenDecls H.SpecSig {} = [] +flattenDecls H.SpecInlineSig {} = [] +flattenDecls H.InstSig {} = [] +flattenDecls H.RulePragmaDecl {} = [] +flattenDecls H.DeprPragmaDecl {} = [] +flattenDecls H.WarnPragmaDecl {} = [] +flattenDecls H.AnnPragma {} = [] +flattenDecls H.MinimalPragma {} = [] flattenDecls decl = [decl] +-- | Flattens the declarations inside of an instance declaration. +flattenInstDecl :: H.InstDecl () -> [H.InstDecl ()] +flattenInstDecl (H.InsDecl _ decl) = map (H.InsDecl ()) (flattenDecls decl) +flattenInstDecl decl = [decl] + -- | To superimpose two Haskell modules, they must have the same name. --- Then, their exports and imports are merged. --- Declarations are flattened before they are merged (see 'flattenDecls'), -instance Superimposable H.HsModule where - H.HsModule loc mod1 exps1 imps1 decls1 --> H.HsModule _ mod2 exps2 imps2 decls2 +-- Then, their pragmas, exports, and imports are merged. +-- Pragmas and declarations are flattened before they are merged. See 'flattenPragmas' and 'flattenDecls'. +instance Superimposable (H.Module ()) where + H.Module _ head1 pragmas1 imps1 decls1 --> H.Module _ head2 pragmas2 imps2 decls2 = do + hd <- case (head1, head2) of + (Just h1, Just h2) -> fmap Just (h1 --> h2) + (Nothing, Nothing) -> Right Nothing + _ -> Left "Cannot merge a module that has a header with one that does not" + pragmas <- concatMap flattenPragmas pragmas1 --> concatMap flattenPragmas pragmas2 + imps <- imps1 --> imps2 + decls <- concatMap flattenDecls decls1 --> concatMap flattenDecls decls2 + return (H.Module () hd pragmas imps decls) + _ --> _ = Left "Cannot merge modules that are not plain Haskell modules" + +-- | A module header holds the module name and its exports. +-- The names must be the same, and then the exports are merged. +instance Superimposable (H.ModuleHead ()) where + H.ModuleHead _ mod1 warn1 exps1 --> H.ModuleHead _ mod2 _ exps2 | mod1 == mod2 = do - exps <- sequenceA (liftA2 (-->) exps1 exps2) - imps <- imps1 --> imps2 - decls <- concatMap flattenDecls decls1 --> concatMap flattenDecls decls2 - return (H.HsModule loc mod1 exps imps decls) + exps <- sequenceA (liftA2 (-->) exps1 exps2) + return (H.ModuleHead () mod1 warn1 exps) | otherwise = Left ("Cannot merge differing modules: " ++ H.prettyPrint mod1 ++ " and " ++ H.prettyPrint mod2) -- Exports -------------------------------------------------------------------- -instance Superimposable H.HsExportSpec where - x@(H.HsEThingAll _) --> _ = Right x - _ --> y@(H.HsEThingAll _) = Right y - H.HsEThingWith name xs --> H.HsEThingWith _ ys = fmap (H.HsEThingWith name) (xs --> ys) - H.HsEAbs _ --> y@(H.HsEThingWith _ _) = Right y - x --> _ = Right x - -instance Identifiable H.HsExportSpec where - type Identifier H.HsExportSpec = Either H.HsQName H.Module -- an entity, or a whole module - identify (H.HsEVar name) = Right (Left name) - identify (H.HsEAbs name) = Right (Left name) - identify (H.HsEThingAll name) = Right (Left name) - identify (H.HsEThingWith name _) = Right (Left name) - identify (H.HsEModuleContents modl) = Right (Right modl) +instance Superimposable (H.ExportSpecList ()) where + H.ExportSpecList _ xs --> H.ExportSpecList _ ys = fmap (H.ExportSpecList ()) (xs --> ys) + +instance Superimposable (H.ExportSpec ()) where + x@(H.EThingWith _ (H.EWildcard {}) _ _) --> _ + = Right x + _ --> y@(H.EThingWith _ (H.EWildcard {}) _ _) + = Right y + H.EThingWith _ wild name xs --> H.EThingWith _ _ _ ys + = fmap (H.EThingWith () wild name) (xs --> ys) + H.EAbs _ _ _ --> y@(H.EThingWith _ _ _ _) + = Right y + x --> _ + = Right x + +instance Identifiable (H.ExportSpec ()) where + -- An export spec is identified by an entity or a whole module. + type Identifier (H.ExportSpec ()) = Either (H.QName ()) (H.ModuleName ()) + identify (H.EVar _ name) = Right (Left name) + identify (H.EAbs _ _ name) = Right (Left name) + identify (H.EThingWith _ _ name _) = Right (Left name) + identify (H.EModuleContents _ modl) = Right (Right modl) -- Imports -------------------------------------------------------------------- -instance Superimposable H.HsImportDecl where +instance Superimposable (H.ImportDecl ()) where x --> y = do specs <- sequenceA (liftA2 (-->) (H.importSpecs x) (H.importSpecs y)) return (x { H.importSpecs = specs }) -instance Identifiable H.HsImportDecl where - type Identifier H.HsImportDecl = (H.Module, Bool, Maybe H.Module) +instance Identifiable (H.ImportDecl ()) where + type Identifier (H.ImportDecl ()) = (H.ModuleName (), Bool, Maybe (H.ModuleName ())) identify imp = Right (H.importModule imp, H.importQualified imp, H.importAs imp) --- | A list of module imports. --- @(False, xs)@ imports only @xs@, and @(True, xs)@ imports everything except @xs@. -type ImportList = (Bool, [H.HsImportSpec]) - -instance Superimposable ImportList where - (False, xs) --> (False, ys) = fmap ((,) False) (xs --> ys) - (True, xs) --> (True, ys) = do +-- Note that @ImportSpecList _ False xs@ imports only @xs@, +-- and @ImportSpecList _ True xs@ imports everything except @xs@. +instance Superimposable (H.ImportSpecList ()) where + H.ImportSpecList _ False xs --> H.ImportSpecList _ False ys = fmap (H.ImportSpecList () False) (xs --> ys) + H.ImportSpecList _ True xs --> H.ImportSpecList _ True ys = do xids <- traverse identify xs yids <- traverse identify ys - return (True, [x | (x, xid) <- zip xs xids, xid `elem` yids]) - (False, xs) --> (True, ys) = do + return (H.ImportSpecList () True [x | (x, xid) <- zip xs xids, xid `elem` yids]) + H.ImportSpecList _ False xs --> H.ImportSpecList _ True ys = do xids <- traverse identify xs yids <- traverse identify ys - return (True, [y | (y, yid) <- zip ys yids, yid `notElem` xids]) - (True, xs) --> (False, ys) = do + return (H.ImportSpecList () True [y | (y, yid) <- zip ys yids, yid `notElem` xids]) + H.ImportSpecList _ True xs --> H.ImportSpecList _ False ys = do xids <- traverse identify xs yids <- traverse identify ys - return (True, [x | (x, xid) <- zip xs xids, xid `notElem` yids]) - -instance Superimposable H.HsImportSpec where - x@(H.HsIThingAll _) --> _ = Right x - _ --> y@(H.HsIThingAll _) = Right y - H.HsIThingWith name xs --> H.HsIThingWith _ ys = fmap (H.HsIThingWith name) (xs --> ys) - H.HsIAbs _ --> y@(H.HsIThingWith _ _) = Right y - x --> _ = Right x - -instance Identifiable H.HsImportSpec where - type Identifier H.HsImportSpec = H.HsName - identify (H.HsIVar name) = Right name - identify (H.HsIAbs name) = Right name - identify (H.HsIThingAll name) = Right name - identify (H.HsIThingWith name _) = Right name + return (H.ImportSpecList () True [x | (x, xid) <- zip xs xids, xid `notElem` yids]) + +instance Superimposable (H.ImportSpec ()) where + x@(H.IThingAll _ _) --> _ + = Right x + _ --> y@(H.IThingAll _ _) + = Right y + H.IThingWith _ name xs --> H.IThingWith _ _ ys + = fmap (H.IThingWith () name) (xs --> ys) + H.IAbs _ _ _ --> y@(H.IThingWith _ _ _) + = Right y + x --> _ + = Right x + +instance Identifiable (H.ImportSpec ()) where + type Identifier (H.ImportSpec ()) = H.Name () + identify (H.IVar _ name) = Right name + identify (H.IAbs _ _ name) = Right name + identify (H.IThingAll _ name) = Right name + identify (H.IThingWith _ name _) = Right name -- Declarations --------------------------------------------------------------- @@ -228,14 +315,26 @@ instance Identifiable H.HsImportSpec where -- Only these declarations can be merged. Everything else (classes, default -- declarations, foreign declarations, pattern bindings) is rejected by 'identify'. data DeclId - = Value H.HsName -- ^ Functions and variables. - | Sig H.HsName -- ^ Type signatures. - | Type H.HsName -- ^ Type synonyms, datatype declarations, and @newtype@s. - | Fixity H.HsName -- ^ Fixity declarations. - | Instance H.HsQName [H.HsType] - -- ^ Typeclass instance declarations. + = Value (H.Name ()) -- ^ Functions and variables. + | Sig (H.Name ()) -- ^ Type signatures. + | Type (H.Name ()) -- ^ Type synonyms, datatype declarations, and @newtype@s. + | Fixity (H.Name ()) -- ^ Fixity declarations. + | Instance (H.InstHead ()) + -- ^ Typeclass instance declarations. deriving Eq +-- | Finds the name that a declaration head (such as @T a b@) declares. +headName :: H.DeclHead l -> H.Name l +headName (H.DHead _ name) = name +headName (H.DHInfix _ _ name) = name +headName (H.DHParen _ hd) = headName hd +headName (H.DHApp _ hd _) = headName hd + +-- | Finds the instance head (the class and its types) of an instance rule. +instHead :: H.InstRule l -> H.InstHead l +instHead (H.IRule _ _ _ hd) = hd +instHead (H.IParen _ rule) = instHead rule + -- | Only a subset of Haskell declarations have been given superimposition definitions. -- These are as follows. -- @@ -248,34 +347,54 @@ data DeclId -- * Typeclass instance declarations. -- -- See 'DeclId'. -instance Identifiable H.HsDecl where - type Identifier H.HsDecl = DeclId - identify (H.HsTypeDecl _ name _ _) = Right (Type name) - identify (H.HsDataDecl _ _ name _ _ _) = Right (Type name) - identify (H.HsNewTypeDecl _ _ name _ _ _) = Right (Type name) - identify (H.HsFunBind (H.HsMatch _ name _ _ _ : _)) = Right (Value name) - identify (H.HsTypeSig _ [name] _) = Right (Sig name) - identify (H.HsInfixDecl _ _ _ [H.HsVarOp name]) = Right (Fixity name) - identify (H.HsInfixDecl _ _ _ [H.HsConOp name]) = Right (Fixity name) - identify (H.HsInstDecl _ _ cls tys _) = Right (Instance cls tys) +instance Identifiable (H.Decl ()) where + type Identifier (H.Decl ()) = DeclId + identify (H.TypeDecl _ hd _) = Right (Type (headName hd)) + identify (H.DataDecl _ _ _ hd _ _) = Right (Type (headName hd)) + identify (H.FunBind _ (m : _)) = Right (Value (fst (clause m))) + identify (H.TypeSig _ [name] _) = Right (Sig name) + identify (H.InfixDecl _ _ _ [H.VarOp _ name]) = Right (Fixity name) + identify (H.InfixDecl _ _ _ [H.ConOp _ name]) = Right (Fixity name) + identify (H.InstDecl _ _ rule _) = Right (Instance (instHead rule)) identify decl = Left ("Cannot merge this declaration: " ++ takeWhile (/= '\n') (dropWhile isSpace (H.prettyPrint decl))) -- | Datatype declarations, functions, and typeclass instance declarations are merged. -- Type synonyms, @newtype@s, type signatures, and fixity declarations are overridden from the left. -instance Superimposable H.HsDecl where - H.HsDataDecl loc ctx name vars cons1 derivs1 --> H.HsDataDecl _ _ _ _ cons2 derivs2 = do +instance Superimposable (H.Decl ()) where + H.DataDecl _ dn@(H.DataType _) ctx hd cons1 derivs1 --> H.DataDecl _ (H.DataType _) _ _ cons2 derivs2 = do cons <- cons1 --> cons2 derivs <- derivs1 --> derivs2 - return (H.HsDataDecl loc ctx name vars cons derivs) - H.HsFunBind ms1 --> H.HsFunBind ms2 - | length (nub [length pats | H.HsMatch _ _ pats _ _ <- ms1 ++ ms2]) == 1 - = fmap H.HsFunBind (ms1 --> ms2) - H.HsInstDecl loc ctx cls tys decls1 --> H.HsInstDecl _ _ _ _ decls2 = do - decls <- decls1 --> decls2 - return (H.HsInstDecl loc ctx cls tys decls) + return (H.DataDecl () dn ctx hd cons derivs) + H.FunBind _ ms1 --> H.FunBind _ ms2 + | length (nub [length (snd (clause m)) | m <- ms1 ++ ms2]) == 1 + = fmap (H.FunBind ()) (ms1 --> ms2) + H.InstDecl _ overlap rule decls1 --> H.InstDecl _ _ _ decls2 = do + decls <- fromMaybe [] decls1 --> fromMaybe [] decls2 + return (H.InstDecl () overlap rule (if null decls then Nothing else Just decls)) x --> _ = Right x +instance Superimposable (H.InstDecl ()) where + H.InsDecl _ x --> H.InsDecl _ y = fmap (H.InsDecl ()) (x --> y) + x --> _ = Right x + +instance Identifiable (H.InstDecl ()) where + type Identifier (H.InstDecl ()) = DeclId + identify (H.InsDecl _ decl) = identify decl + identify decl = + Left ("Cannot merge this instance declaration: " ++ + takeWhile (/= '\n') (dropWhile isSpace (H.prettyPrint decl))) + +-- | A @deriving@ clause is identified by its strategy (e.g., 'H.DerivStock'). +-- Clauses with the same strategy are merged, and the classes they derive are merged by their names. +instance Superimposable (H.Deriving ()) where + H.Deriving _ strat rules1 --> H.Deriving _ _ rules2 + = fmap (H.Deriving () strat) (rules1 --> rules2) + +instance Identifiable (H.Deriving ()) where + type Identifier (H.Deriving ()) = Maybe (H.DerivStrategy ()) + identify (H.Deriving _ strat _) = Right strat + ------------------------------------------------------------------------------- -- Happy ------------------------------------------------------------------------------- @@ -416,17 +535,20 @@ instance Superimposable (Y.AbsSyn String) where -- Then, each rule is superimposed. instance Superimposable Y.BookendedAbsSyn where Y.BookendedAbsSyn opts1 head1 syn1 foot1 --> Y.BookendedAbsSyn opts2 head2 syn2 foot2 = do - modl1 <- parse head1 foot1 - modl2 <- parse head2 foot2 - H.HsModule loc name exps imps decls <- modl1 --> modl2 + modl1 <- parse head1 foot1 + modl2 <- parse head2 foot2 + merged <- modl1 --> modl2 + (shell, decls) <- case merged of + H.Module _ hd pragmas imps ds -> Right (H.Module () hd pragmas imps [], ds) + _ -> Left "Invalid Happy header or footer: not a plain Haskell module" syn <- syn1 --> syn2 return (Y.BookendedAbsSyn (opts1 <|> opts2) - -- The header contains the Haskell module declaration and imports. - (Just (H.prettyPrint (H.HsModule loc name exps imps []))) + -- The header contains the pragmas, the Haskell module declaration and imports. + (Just (H.prettyPrint shell)) syn -- The footer contains Haskell declarations. (Just (unlines (map H.prettyPrint decls)))) where - parse header footer = case H.parseModule (unlines (catMaybes [header, footer])) of - H.ParseOk modl -> Right modl + parse header footer = case H.parseModuleWithMode parseMode (unlines (catMaybes [header, footer])) of + H.ParseOk modl -> Right (void modl) H.ParseFailed _ msg -> Left ("Invalid Happy header or footer: " ++ msg) \ No newline at end of file diff --git a/LayeredHaskell-make/src/LHMake/Data/Feature.hs b/LayeredHaskell-make/src/LHMake/Data/Feature.hs index b5a22cb..f0d53fb 100644 --- a/LayeredHaskell-make/src/LHMake/Data/Feature.hs +++ b/LayeredHaskell-make/src/LHMake/Data/Feature.hs @@ -34,6 +34,7 @@ module LHMake.Data.Feature ( import Control.Monad (forM, forM_, unless, when) import Data.Bifunctor (first) +import Data.Functor (void) import Data.List (intercalate) import Data.Map (Map) import Data.Maybe (maybeToList) @@ -43,17 +44,15 @@ import System.Exit (die) import System.FilePath (takeDirectory, (), (<.>)) import System.IO (readFile') -import Happy.Frontend (parseYFileContents) +import Happy.Frontend (parseYFileContents) import Happy.Frontend.AbsSyn -import Language.Haskell.Syntax -import Language.Haskell.Parser (parseModule, ParseResult (..)) -import Language.Haskell.Pretty (prettyPrint) +import qualified Language.Haskell.Exts as H import qualified Data.Graph as Graph import qualified Data.Map as Map import qualified Data.Set as Set -import LHMake.Control.Superimposition ((-->)) +import LHMake.Control.Superimposition ((-->), parseMode) import LHMake.Data.Error (LHsMakeError) import LHMake.Text.Happy.Pretty (pprHappy) import LHMake.Text.Label (infoLabel, errLabel) @@ -254,34 +253,38 @@ resolve reg names = do -- -- The result of 'load' also carries around corresponding module names, -- since we only want to superimpose modules of the same name. -load :: Feature -> IO (LHsMakeError (Map ModuleName HsModule, Map ModuleName BookendedAbsSyn)) +load :: Feature -> IO (LHsMakeError (Map ModuleName (H.Module ()), Map ModuleName BookendedAbsSyn)) load feat = do haskellSrcs <- traverse loadFileWithPath (modules feat) happySrcs <- traverse loadFileWithPath (maybeToList (grammar feat)) return $ do haskell <- forM haskellSrcs (\(file, src) -> do - modl@(HsModule _ (Module name) _ _ _) <- parse file src + modl <- parse file src + name <- moduleName file modl return (name, modl)) happy <- forM happySrcs (\(file, src) -> do gram <- first ((file ++ ": ") ++) (parseYFileContents src) header <- case gram of BookendedAbsSyn _ (Just header) _ _ -> Right header _ -> Left (file ++ ": The grammar header is empty, so I can't identify it") - HsModule _ (Module name) _ _ _ <- parse file header + modl <- parse file header + name <- moduleName file modl return (name, gram)) return (Map.fromList haskell, Map.fromList happy) where loadFileWithPath file = do src <- readFile file return (file, src) - parse file src = case parseModule src of - ParseOk modl -> Right modl - ParseFailed (SrcLoc _ l c) err -> + parse file src = case H.parseModuleWithMode parseMode src of + H.ParseOk modl -> Right (void modl) + H.ParseFailed (H.SrcLoc _ l c) err -> Left (file ++ "@" ++ show l ++ ":" ++ show c ++ ": " ++ err) + moduleName _ (H.Module _ (Just (H.ModuleHead _ (H.ModuleName _ name) _ _)) _ _ _) = Right name + moduleName file _ = Left (file ++ ": The module has no header, so I can't identify it") -- | Resolves the dependencies inherent to a 'FeatureSet', then superimposes modules and grammars -- such that a single set of Haskell modules and at most one Happy grammar is produced. -merge :: Registry -> FeatureSet -> IO (LHsMakeError (Map ModuleName HsModule, Map ModuleName BookendedAbsSyn)) +merge :: Registry -> FeatureSet -> IO (LHsMakeError (Map ModuleName (H.Module ()), Map ModuleName BookendedAbsSyn)) merge reg names = case resolve reg names of Left err -> return (Left (errLabel err)) Right enabled -> do @@ -311,7 +314,7 @@ superimpose names dir = do forM_ (Map.toList haskell) $ \(name, modl) -> writeIfChanged (dir end name <.> "hs") - ("{-# OPTIONS_HADDOCK hide #-}\n" ++ prettyPrint modl) + (H.prettyPrint modl) forM_ (Map.toList happy) $ \(name, gram) -> writeIfChanged (dir end name <.> "y") diff --git a/LayeredHaskell-make/src/LHMake/Feature/E/AbsSyn.hs b/LayeredHaskell-make/src/LHMake/Feature/E/AbsSyn.hs index 381f526..2aac9f9 100644 --- a/LayeredHaskell-make/src/LHMake/Feature/E/AbsSyn.hs +++ b/LayeredHaskell-make/src/LHMake/Feature/E/AbsSyn.hs @@ -11,11 +11,12 @@ Stability : experimental This module provides abstract syntax definitions for E. -} +{-# OPTIONS_HADDOCK hide #-} module LH.Feature.AbsSyn ( -- * Identifiers Id, -- * Declarations - LHsDecl (..), + LHsDecl (..), -- ** Expressions and values LHsExpr (..), LHsVal (..), -- ** Patterns diff --git a/LayeredHaskell-make/src/LHMake/Feature/E/Parser.y b/LayeredHaskell-make/src/LHMake/Feature/E/Parser.y index 55cb988..8aa5a71 100644 --- a/LayeredHaskell-make/src/LHMake/Feature/E/Parser.y +++ b/LayeredHaskell-make/src/LHMake/Feature/E/Parser.y @@ -12,6 +12,7 @@ Stability : experimental This module provides a parser for Layered Haskell programs with E enabled. -} +{-# OPTIONS_HADDOCK hide #-} module LH.Feature.Parser ( -- * Parsing parseProgram diff --git a/LayeredHaskell-make/src/LHMake/Text/Happy/Pretty.hs b/LayeredHaskell-make/src/LHMake/Text/Happy/Pretty.hs index 1463942..233f6f5 100644 --- a/LayeredHaskell-make/src/LHMake/Text/Happy/Pretty.hs +++ b/LayeredHaskell-make/src/LHMake/Text/Happy/Pretty.hs @@ -30,14 +30,12 @@ pprHappy :: BookendedAbsSyn -> String pprHappy (BookendedAbsSyn options header (AbsSyn directives rules) footer) = concat [ maybe "" (\o -> "{-# " ++ o ++ " #-}\n\n") options - , maybe "" (\h -> braces' (pragmas ++ h) ++ "\n\n") header + , maybe "" (\h -> braces' h ++ "\n\n") header , unlines (map pprDirective directives) , "\n%%\n\n" , intercalate "\n" (map pprRule rules) , maybe "" (\f -> "\n" ++ braces' f ++ "\n") footer ] - where - pragmas = "{-# OPTIONS_HADDOCK hide #-}\n{-# LANGUAGE OverloadedStrings #-}\n" ------------------------------------------------------------------------------- -- Directives diff --git a/LayeredHaskell.cabal b/LayeredHaskell.cabal index 31a6be8..d736a18 100644 --- a/LayeredHaskell.cabal +++ b/LayeredHaskell.cabal @@ -57,6 +57,10 @@ extra-doc-files: -- Extra source files to be distributed with the package, such as examples, or a tutorial module. -- extra-source-files: +source-repository head + type: git + location: https://github.com/hshkk/LayeredHaskell + custom-setup setup-depends: , base ^>=4.18.3.0 @@ -117,7 +121,11 @@ executable LayeredHaskell main-is: Main.hs -- Modules included in this executable, other than Main. - -- other-modules: + other-modules: + Paths_LayeredHaskell + + autogen-modules: + Paths_LayeredHaskell -- LANGUAGE extensions used by modules in this package. -- other-extensions: diff --git a/README.md b/README.md index 8021419..348eb0d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # Layered Haskell +[![Tests](https://img.shields.io/github/actions/workflow/status/hshkk/LayeredHaskell/ci.yml?branch=main&label=tests)](https://github.com/hshkk/LayeredHaskell/actions/workflows/ci.yml) +[![Documentation](https://img.shields.io/badge/docs-Haddock-blue)](https://hshkk.github.io/LayeredHaskell/) + **Layered Haskell** is a _layered_ functional language in which users can enable and disable various language features at will. The modularity of Layered Haskell enables language variants that support a gentle introduction to functional programming for novices while also providing a means for exploring language extensions. @@ -10,9 +13,15 @@ The modularity of Layered Haskell enables language variants that support a gentl # Installation +Download the appropriate archive from the latest release. It should contain several executable files that you can run directly from the terminal. + +If an executable fails to run, your machine may not be compatible with the operating system environments used to build the binaries on GitHub's servers. **Solution forthcoming.** + +## Local Development + Clone the repository and execute `cd LayeredHaskell`. -It is _not_ recommended to use `cabal install` on either `LayeredHaskell` or `LayeredHaskell-make`, as the program as it exists will likely not function as intended, if at all. One should use `cabal run` as the [Usage](#usage) section describes, or write a (local) command alias. This may be changed in the future. +It is _not_ recommended to use `cabal install` on either `LayeredHaskell` or `LayeredHaskell-make`, as the program as it exists will likely not function as intended, if at all. One should use `cabal run` as the [Usage](#usage) section describes, or write a (local) command alias. # Usage diff --git a/cabal.project b/cabal.project index bb453e3..aa157e0 100644 --- a/cabal.project +++ b/cabal.project @@ -1,3 +1,5 @@ packages: . - LayeredHaskell-make \ No newline at end of file + LayeredHaskell-make + +tests: True \ No newline at end of file diff --git a/src-exe/Main.hs b/src-exe/Main.hs index c6b9a1e..bc3f3bd 100644 --- a/src-exe/Main.hs +++ b/src-exe/Main.hs @@ -1,5 +1,6 @@ module Main where +import Data.Version (showVersion) import System.Environment (getArgs) import System.Exit (die) @@ -8,6 +9,8 @@ import qualified Data.Text.IO as Text import LH.Data.Error (renderError) import LH.Feature.Parser (parseProgram) +import qualified Paths_LayeredHaskell as LH (version) + -- | Currently takes a single filepath, parses it, and prints out the AST. main :: IO () main = do @@ -20,4 +23,9 @@ main = do Text.putStrLn (renderError file src err) die "" Right ast -> print ast - _ -> die "1 filepath expected" \ No newline at end of file + _ -> die "1 filepath expected" + +-- | Prints the version of @LayeredHaskell@. +version :: IO () +version = do + putStrLn $ "LayeredHaskell version " ++ showVersion LH.version \ No newline at end of file diff --git a/src/LHMake/Feature/AbsSyn.hs b/src/LHMake/Feature/AbsSyn.hs deleted file mode 100644 index 87cfc83..0000000 --- a/src/LHMake/Feature/AbsSyn.hs +++ /dev/null @@ -1,57 +0,0 @@ -{-# OPTIONS_HADDOCK hide #-} -module LH.Feature.AbsSyn - (LHsExpr(..), LHsVal(..), LHsBin(..), LHsType(..), LHsPat(..), - LHsDecl(..), Id, LHsEnv) - where -import LH.Data.SrcLoc (L) -import Data.Sequence (Seq) -import Data.Map (Map) -import Data.Text (Text) - -data LHsExpr = LHsInt Int - | LHsBin LHsBin (L LHsExpr) (L LHsExpr) - | LHsPre LHsBin - | LHsNeg (L LHsExpr) - | LHsIf (L LHsExpr) (L LHsExpr) (L LHsExpr) - | LHsVar Id - | LHsCon Id - | LHsApp (L LHsExpr) (L LHsExpr) - | LHsLet (Seq (L LHsDecl)) (L LHsExpr) - deriving (Eq, Show) - -data LHsBin = LHsAdd - | LHsSub - | LHsMul - | LHsOr - | LHsAnd - | LHsLt - | LHsGt - | LHsLte - | LHsGte - | LHsEq - | LHsNeq - deriving (Eq, Show) - -data LHsVal = LHsVInt Int - | LHsVCon Id (Seq LHsVal) - | LHsClos LHsEnv (L LHsExpr) - deriving (Eq, Show) - -data LHsType = LHsTyCon Id (Seq (L LHsType)) - | LHsTyVar Id - deriving (Eq, Show) - -data LHsPat = LHsPInt Int - | LHsPCon Id (Seq (L LHsPat)) - | LHsPVar Id - deriving (Eq, Show) - -data LHsDecl = LHsData Id (Seq Id) (Seq (Id, Seq (L LHsType))) - | LHsType Id (Seq Id) (L LHsType) - | LHsEqn Id (Seq (L LHsPat)) (L LHsExpr) - | LHsSig Id (L LHsType) - deriving (Eq, Show) - -type Id = L Text - -type LHsEnv = Map Id LHsVal \ No newline at end of file diff --git a/src/LHMake/Feature/Parser.y b/src/LHMake/Feature/Parser.y deleted file mode 100644 index b9fd2dc..0000000 --- a/src/LHMake/Feature/Parser.y +++ /dev/null @@ -1,222 +0,0 @@ -{ -{-# OPTIONS_HADDOCK hide #-} -{-# LANGUAGE OverloadedStrings #-} -module LH.Feature.Parser (parseProgram) where -import Data.Sequence (Seq, (<|), (|>)) -import LH.Data.SrcLoc -import LH.Feature.AbsSyn -import LH.Text.Lexer -import LH.Text.Parser.Monad -import LH.Text.Token -import Control.Monad.Except (throwError) -import qualified Data.Sequence as Seq -import Data.Text (Text) -} - -%name program Block -%tokentype {LHsLexeme} -%monad {LHsParser} -%lexer {lexer} {LHsLexeme _ LHsTkEOF} -%error {parseError} -%expect 0 -%token - int {LHsLexeme _ (LHsTkInt _)} -%token - '+' {LHsLexeme _ LHsTkPlus} -%token - '-' {LHsLexeme _ LHsTkMinus} -%token - '*' {LHsLexeme _ LHsTkTimes} -%token - '||' {LHsLexeme _ LHsTkOr} -%token - '&&' {LHsLexeme _ LHsTkAnd} -%token - '<' {LHsLexeme _ LHsTkLt} -%token - '>' {LHsLexeme _ LHsTkGt} -%token - '<=' {LHsLexeme _ LHsTkLte} -%token - '>=' {LHsLexeme _ LHsTkGte} -%token - '==' {LHsLexeme _ LHsTkEqEq} -%token - '/=' {LHsLexeme _ LHsTkNotEq} -%token - 'if' {LHsLexeme _ LHsTkIf} -%token - 'then' {LHsLexeme _ LHsTkThen} -%token - 'else' {LHsLexeme _ LHsTkElse} -%token - '(' {LHsLexeme _ LHsTkLParen} -%token - ')' {LHsLexeme _ LHsTkRParen} -%token - var {LHsLexeme _ (LHsTkVar _)} -%token - con {LHsLexeme _ (LHsTkCon _)} -%token - 'data' {LHsLexeme _ LHsTkData} -%token - 'type' {LHsLexeme _ LHsTkType} -%token - '=' {LHsLexeme _ LHsTkEq} -%token - '|' {LHsLexeme _ LHsTkPipe} -%token - 'let' {LHsLexeme _ LHsTkLet} -%token - 'in' {LHsLexeme _ LHsTkIn} -%token - '::' {LHsLexeme _ LHsTkColonColon} -%token - OPEN {LHsLexeme _ LHsTkVOpen} -%token - SEMI {LHsLexeme _ LHsTkVSemi} -%token - CLOSE {LHsLexeme _ LHsTkVClose} -%right 'in' -%right 'else' -%left '||' -%left '&&' -%nonassoc '==' '/=' -%nonassoc '<' '>' '<=' '>=' -%left '+' '-' -%left '*' -%left NEG - -%% - -Expr :: {L LHsExpr} - : 'if' Expr 'then' Expr 'else' Expr {L ($1 >< $6) (LHsIf $2 $4 $6)} - | Expr '+' Expr {L ($1 >< $3) (LHsBin LHsAdd $1 $3)} - | Expr '-' Expr {L ($1 >< $3) (LHsBin LHsSub $1 $3)} - | Expr '*' Expr {L ($1 >< $3) (LHsBin LHsMul $1 $3)} - | Expr '||' Expr {L ($1 >< $3) (LHsBin LHsOr $1 $3)} - | Expr '&&' Expr {L ($1 >< $3) (LHsBin LHsAnd $1 $3)} - | Expr '<' Expr {L ($1 >< $3) (LHsBin LHsLt $1 $3)} - | Expr '>' Expr {L ($1 >< $3) (LHsBin LHsGt $1 $3)} - | Expr '<=' Expr {L ($1 >< $3) (LHsBin LHsLte $1 $3)} - | Expr '>=' Expr {L ($1 >< $3) (LHsBin LHsGte $1 $3)} - | Expr '==' Expr {L ($1 >< $3) (LHsBin LHsEq $1 $3)} - | Expr '/=' Expr {L ($1 >< $3) (LHsBin LHsNeq $1 $3)} - | '-' Expr %prec NEG {L ($1 >< $2) (LHsNeg $2)} - | 'let' Block 'in' Expr {L ($1><$4) (LHsLet $2 $4)} - | App {$1} - -Atom :: {L LHsExpr} - : int {int $1} - | '(' Bin ')' {L ($1 >< $3) (LHsPre $2)} - | var {L (toSpan $1) (LHsVar (ident $1))} - | con {L (toSpan $1) (LHsCon (ident $1))} - | '(' Expr ')' {L ($1><$3) (un $2)} - -Bin :: {LHsBin} - : '+' {LHsAdd} - | '-' {LHsSub} - | '*' {LHsMul} - | '||' {LHsOr} - | '&&' {LHsAnd} - | '<' {LHsLt} - | '>' {LHsGt} - | '<=' {LHsLte} - | '>=' {LHsGte} - | '==' {LHsEq} - | '/=' {LHsNeq} - -PatAtom :: {L LHsPat} - : int {pint $1} - | con {L (toSpan $1) (LHsPCon (ident $1) Seq.empty)} - | '(' Pat ')' {L ($1 >< $3) (un $2)} - -TyAtom :: {L LHsType} - : con {L (toSpan $1) (LHsTyCon (ident $1) Seq.empty)} - | var {L (toSpan $1) (LHsTyVar (ident $1))} - | '(' Type ')' {L ($1 >< $3) (un $2)} - -TyApp :: {L LHsType} - : con TyAtoms {L ($1 >< $2) (LHsTyCon (ident $1) (un $2))} - | TyAtom {$1} - -TyAtoms :: {L (Seq (L LHsType))} - : TyAtom {L (toSpan $1) (Seq.singleton $1)} - | TyAtoms TyAtom {L ($1 >< $2) (un $1 |> $2)} - -TyVars :: {Seq Id} - : var TyVars {ident $1 <| $2} - | {Seq.empty} - -Cons :: {Seq (L (Id, Seq (L LHsType)))} - : {Seq.empty} - | Con {Seq.singleton $1} - | Cons '|' Con {$1 |> $3} - -Con :: {L (Id, Seq (L LHsType))} - : con {L (toSpan $1) (ident $1, Seq.empty)} - | Con TyAtom {L ($1 >< $2) (let (c, xs) = un $1 in (c, xs |> $2))} - -Decl :: {L LHsDecl} - : 'data' con TyVars '=' Cons {L ($1 >< $4 ><* $5) (LHsData (ident $2) $3 (fmap un $5))} - | 'type' con TyVars '=' Type {L ($1 >< $5) (LHsType (ident $2) $3 $5)} - | var Pats '=' Expr {L ($1><$4) (LHsEqn (ident $1) $2 $4)} - | var '::' Type {L ($1><$3) (LHsSig (ident $1) $3)} - -Pat :: {L LHsPat} - : con PatApp {L ($1 >< $2) (LHsPCon (ident $1) (un $2))} - | PatAtom {$1} - -Block :: {Seq (L LHsDecl)} - : OPEN Decls End {$2} - -End :: {()} - : CLOSE {()} - | error {% popLayout} - -Decls :: {Seq (L LHsDecl)} - : {Seq.empty} - | Decl {Seq.singleton $1} - | Decls SEMI {$1} - | Decls SEMI Decl {$1 |> $3} - -App :: {L LHsExpr} - : App Atom {L ($1><$2) (LHsApp $1 $2)} - | Atom {$1} - -Pats :: {Seq (L LHsPat)} - : {Seq.empty} - -PatApp :: {L (Seq (L LHsPat))} - : PatAtom Pats {L ($1 ><* $2) ($1 <| $2)} - -Type :: {L LHsType} - : TyApp {$1} - -{ - -int :: LHsLexeme -> L LHsExpr -int (LHsLexeme sp (LHsTkInt n)) = L sp (LHsInt n) -int _ = undefined - -pint :: LHsLexeme -> L LHsPat -pint (LHsLexeme sp (LHsTkInt n)) = L sp (LHsPInt n) -pint _ = undefined - -lexer :: (LHsLexeme -> LHsParser a) -> LHsParser a -lexer f = scanToken >>= f - -parseProgram :: Text -> Either LHsTextError (Seq (L LHsDecl)) -parseProgram = runLHsParser (beginProgram >> program) - -parseError :: LHsLexeme -> LHsParser a -parseError (LHsLexeme sp tok) - = do end <- fmap aiPos getInput - throwError (ParseError sp tok) - -ident :: LHsLexeme -> Id -ident (LHsLexeme sp (LHsTkVar x)) = L sp x -ident (LHsLexeme sp (LHsTkCon c)) = L sp c -ident _ = undefined - -} diff --git a/test/LH/Test/Text/Parser.hs b/test/LH/Test/Text/Parser.hs index 7d0d5ad..42713e2 100644 --- a/test/LH/Test/Text/Parser.hs +++ b/test/LH/Test/Text/Parser.hs @@ -46,9 +46,9 @@ build :: IO () build = void (run "cabal" ["build", "lib:LayeredHaskell"]) -- Generates the source files for a feature combination. --- The tests then operate on a temporary directory named @lhs-parser-test@. +-- The tests then operate on a temporary directory named @LayeredHaskell-@. withBuild :: [FeatureName] -> (FilePath -> IO ()) -> IO () -withBuild args tests = withSystemTempDirectory "lhs-parser-test" $ \dir -> do +withBuild args tests = withSystemTempDirectory "LayeredHaskell-test" $ \dir -> do let featureDir = dir "LH" "Feature" -- Create ../LH/Feature/, which will then receive the superimposed files. createDirectoryIfMissing True featureDir