Skip to content

Commit

Permalink
Factor out language specifications (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
int-index authored Nov 4, 2019
1 parent db1058f commit 650fad9
Show file tree
Hide file tree
Showing 16 changed files with 615 additions and 421 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ dev/build:
cabal v2-build

dev/watch:
watchman-make -p '*.cabal' 'lib/**/*.hs' 'src/**/*.hs' -t dev/build
watchman-make -p '*.cabal' 'src/**/*.hs' -t dev/build

dev/run:
cabal v2-run -- foundry "./expr.morte"

fmt:
ormolu -c --mode inplace `find lib src -name "*.hs"`
ormolu -c --mode inplace `find src -name "*.hs"`

tags:
fast-tags -R lib src
fast-tags -R src

clean:
cabal v2-clean
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pkgs.stdenv.mkDerivation rec {
src = ./.;
buildCommand = ''
mkdir -p $out/bin $out/home
cp -r $src/foundry.cabal $src/lib $src/src .
cp -r $src/foundry.cabal $src/src .
HOME=$out/home \
cabal --offline --config-file /dev/null v2-install \
--builddir=$out/dist \
Expand Down
58 changes: 48 additions & 10 deletions foundry.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ name: foundry
version: 0.1.0.0
build-type: Simple

library source-layout
exposed-modules: Source.Layout
build-depends: base >=4.7, unordered-containers,
hashable, text,
sdam
hs-source-dirs: src/layout
default-language: Haskell2010
default-extensions: RankNTypes
ghc-options: -Wall -O2
ghc-prof-options: -fprof-auto
-auto-all
-caf-all

library

exposed-modules: Source
Expand Down Expand Up @@ -32,8 +45,9 @@ library
, slay-combinators
, slay-cairo
, sdam
, source-layout

hs-source-dirs: lib
hs-source-dirs: src/driver

default-language: Haskell2010

Expand All @@ -42,13 +56,37 @@ library
-auto-all
-caf-all

library source-language-haskell
exposed-modules: Source.Language.Haskell
build-depends: base >=4.7, regex-applicative,
unordered-containers,
sdam, source-layout
hs-source-dirs: src/lang/haskell
default-language: Haskell2010
ghc-options: -Wall -O2
ghc-prof-options: -fprof-auto
-auto-all
-caf-all

library source-language-morte
exposed-modules: Source.Language.Morte
build-depends: base >=4.7, regex-applicative,
unordered-containers,
sdam, source-layout
hs-source-dirs: src/lang/morte
default-language: Haskell2010
ghc-options: -Wall -O2
ghc-prof-options: -fprof-auto
-auto-all
-caf-all

executable foundry
main-is: Foundry.hs

build-depends: base, unordered-containers, megaparsec, regex-applicative,
sdam, foundry
sdam, source-language-morte, source-language-haskell, foundry

hs-source-dirs: src
hs-source-dirs: src/bin

default-language: Haskell2010

Expand All @@ -62,14 +100,14 @@ executable hask
main-is: Hask.hs

build-depends: base, unordered-containers, megaparsec, regex-applicative,
sdam, foundry
sdam, source-language-haskell, foundry

hs-source-dirs: src
hs-source-dirs: src/bin

default-language: Haskell2010

ghc-options: -Wall -threaded -O2
-Wno-missing-signatures

ghc-prof-options: -fprof-auto
-rtsopts
-auto-all
Expand All @@ -78,16 +116,16 @@ executable hask
executable morte-to-sdam
main-is: MorteToSdam.hs
build-depends: base, text, unordered-containers,
morte, sdam
hs-source-dirs: src
morte, sdam, source-language-morte
hs-source-dirs: src/bin
default-language: Haskell2010
ghc-options: -Wall -threaded -O2

executable haskell-to-sdam
main-is: HaskellToSdam.hs
build-depends: base, text, containers, unordered-containers,
split,
ghc-lib-parser, sdam
hs-source-dirs: src
ghc-lib-parser, sdam, source-language-haskell
hs-source-dirs: src/bin
default-language: Haskell2010
ghc-options: -Wall -threaded -O2
148 changes: 0 additions & 148 deletions src/Foundry.hs

This file was deleted.

32 changes: 32 additions & 0 deletions src/bin/Foundry.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}

module Main where

import Sdam.Parser (pValue, parse)
import Source
import Source.Language.Morte
import Source.NewGen
import System.Environment (getArgs)
import System.Exit (die)
import Text.Megaparsec as Megaparsec

main :: IO ()
main = do
mParsedValue <- getArgs >>= \case
[filepath] -> do
content <- readFile filepath
case parse pValue filepath content of
Left e -> die (Megaparsec.errorBundlePretty e)
Right a -> return (Just a)
[] -> return Nothing
_ -> die "Usage: foundry FILE.sd"
runSource foundryPlugin mParsedValue

foundryPlugin :: Plugin
foundryPlugin =
Plugin
{ _pluginSchema = morteSchema,
_pluginRecLayouts = morteRecLayouts
}
32 changes: 32 additions & 0 deletions src/bin/Hask.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedLists #-}
{-# LANGUAGE OverloadedStrings #-}

module Main where

import Sdam.Parser (pValue, parse)
import Source
import Source.Language.Haskell
import Source.NewGen
import System.Environment (getArgs)
import System.Exit (die)
import Text.Megaparsec as Megaparsec

main :: IO ()
main = do
mParsedValue <- getArgs >>= \case
[filepath] -> do
content <- readFile filepath
case parse pValue filepath content of
Left e -> die (Megaparsec.errorBundlePretty e)
Right a -> return (Just a)
[] -> return Nothing
_ -> die "Usage: hask FILE.sd"
runSource haskPlugin mParsedValue

haskPlugin :: Plugin
haskPlugin =
Plugin
{ _pluginSchema = haskellSchema,
_pluginRecLayouts = haskellRecLayouts
}
Loading

0 comments on commit 650fad9

Please sign in to comment.