Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lts-19.24 #16

Merged
merged 9 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 18 additions & 28 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,39 @@ jobs:
build:

runs-on: ubuntu-latest
continue-on-error: true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

required?

Copy link
Contributor Author

@ishiy1993 ishiy1993 Sep 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. If it is false, when some LTS versions fail, other versions will be cancelled.

true: https://github.com/ishiy1993/haiji/actions/runs/3088873538
false: https://github.com/ishiy1993/haiji/actions/runs/3087777392

strategy:
matrix:
resolver-version:
- 'lts-4'
- 'lts-5'
- 'lts-6'
- 'lts-7'
- 'lts-8'
- 'lts-9'
- 'lts-10'
- 'lts-11'
- 'lts-12'
- 'lts-13'
- 'lts-14'
- 'lts-15'
- 'lts-16'
- 'lts-17'
- 'lts-18'
- 'lts-19'
- 'nightly'
env:
STACK_YAML: stack-travis.yaml
steps:
- uses: actions/checkout@v2
- name: Setup stack-travis.yaml
run: |
export RESOLVER=${{ matrix.resolver-version }}
./latest $RESOLVER > stack-travis.yaml
- name: Cache .stack
id: cache-stack
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.stack
key: ${{ runner.os }}-stack-${{ matrix.resolver-version }}
restore-keys: |
${{ runner.os }}-stack-
key: ${{ runner.os }}-stack-${{ hashFiles('stack-travis.yaml') }}
- name: Cache .local
id: cache-local
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/.local
key: ${{ runner.os }}-local-${{ matrix.resolver-version }}
restore-keys: |
${{ runner.os }}-local-
key: ${{ runner.os }}-local-${{ hashFiles('stack-travis.yaml') }}
# - uses: actions/setup-haskell@v1
# with:
# ghc-version: '8.8.2'
Expand All @@ -49,18 +48,9 @@ jobs:
run: |
mkdir -p ~/.local/bin
export PATH=~/.local/bin:$PATH
export RESOLVER=${{ matrix.resolver-version }}
./latest $RESOLVER > stack-travis.yaml
export STACK_YAML=stack-travis.yaml
if [ ${RESOLVER/lts-/} -lt 10 ]
then
curl -L https://github.com/commercialhaskell/stack/releases/download/v1.9.1/stack-1.9.1-linux-x86_64.tar.gz | \
tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'
else
curl -L https://www.stackage.org/stack/linux-x86_64 | \
tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'
stack update
fi
curl -L https://www.stackage.org/stack/linux-x86_64 | \
tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'
stack update
stack --no-terminal --skip-ghc-check setup
- name: Install deps
run: |
Expand Down
4 changes: 4 additions & 0 deletions haiji.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ library
Text.Haiji.Syntax.Expression
Text.Haiji.Syntax.Literal
Text.Haiji.Syntax.Literal.String
Text.Haiji.Utils
build-depends: base >=4.7 && <5
, text
, attoparsec >=0.10
Expand All @@ -91,6 +92,9 @@ test-suite doctests
hs-source-dirs: test
ghc-options: -Wall -threaded
default-language: Haskell2010
-- Skip doctest for GHC 9. https://github.com/sol/doctest/issues/327
if impl(ghc >= 9.0) && impl(ghc < 9.3)
buildable: False

test-suite tests
type: exitcode-stdio-1.0
Expand Down
6 changes: 3 additions & 3 deletions src/Text/Haiji/Dictionary.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ module Text.Haiji.Dictionary
, retrieve
) where

import Data.Aeson
import Data.Aeson (ToJSON(..), Value(..), encode, object, (.=))
import Data.Dynamic
import qualified Data.HashMap.Strict as M
import Data.Maybe
#if MIN_VERSION_base(4,11,0)
#else
import Data.Monoid
#endif
import qualified Data.Text as T
import qualified Data.Text.Lazy as LT
import qualified Data.Text.Lazy.Encoding as LT
import Data.Type.Bool
Expand All @@ -38,6 +37,7 @@ import Data.Kind
#define STAR *
#endif
import GHC.TypeLits
import Text.Haiji.Utils (toKey)

data Key (k :: Symbol) where
Key :: KnownSymbol k => Key k
Expand Down Expand Up @@ -74,7 +74,7 @@ instance ToJSON (Dict '[]) where
instance (ToJSON (Dict d), ToJSON v, KnownSymbol k, Typeable v) => ToJSON (Dict ((k :-> v) ': d)) where
toJSON dict = Object (a <> b) where
(x, v, xs) = headKV dict
Object a = object [ T.pack (keyVal x) .= v ]
Object a = object [ toKey (keyVal x) .= v ]
Object b = toJSON xs
headKV :: (KnownSymbol k, Typeable v) => Dict ((k :-> v) ': d) -> (Key k, v, Dict d)
headKV (Dict d) = (k, fromJust $ fromDynamic $ d M.! keyVal k, Dict $ M.delete (keyVal k) d) where
Expand Down
12 changes: 6 additions & 6 deletions src/Text/Haiji/Runtime.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import Control.Monad.Trans.Reader
import qualified Data.Aeson as JSON
import qualified Data.Aeson.Types as JSON
import Data.Maybe
import qualified Data.HashMap.Strict as HM
import Data.Scientific
import qualified Data.Text as T
import qualified Data.Text.Lazy as LT
import qualified Data.Vector as V
import Text.Haiji.Parse
import Text.Haiji.Syntax
import Text.Haiji.Types
import Text.Haiji.Utils

-- | Dynamically template loader (for template development use)
readTemplateFile :: Environment -> FilePath -> IO (Template JSON.Value)
Expand Down Expand Up @@ -71,8 +71,8 @@ haijiAST env parentBlock children (Foreach k xs loopBody elseBody) =
[ runReader (haijiASTs env parentBlock children loopBody)
(let JSON.Object obj = p
in JSON.Object
$ HM.insert "loop" (loopVariables len ix)
$ HM.insert (T.pack $ show k) x obj)
$ insertValue "loop" (loopVariables len ix)
$ insertValue (toKey $ show k) x obj)
| (ix, x) <- zip [0..] (V.toList dicts)
]
else maybe (return "") (haijiASTs env parentBlock children) elseBody
Expand All @@ -89,7 +89,7 @@ haijiAST env parentBlock children (Set lhs rhs scopes) =
do val <- eval rhs
p <- ask
return $ runReader (haijiASTs env parentBlock children scopes)
(let JSON.Object obj = p in JSON.Object $ HM.insert (T.pack $ show lhs) val obj)
(let JSON.Object obj = p in JSON.Object $ insertValue (toKey $ show lhs) val obj)

loopVariables :: Integer -> Integer -> JSON.Value
loopVariables len ix = JSON.object [ "first" JSON..= (ix == 0)
Expand All @@ -108,7 +108,7 @@ eval (Expression expression) = go expression where
go (ExprIntegerLiteral n) = return $ JSON.Number $ scientific n 0
go (ExprStringLiteral s) = return $ JSON.String $ T.pack $ unwrap s
go (ExprBooleanLiteral b) = return $ JSON.Bool b
go (ExprVariable v) = either error id . JSON.parseEither (JSON.withObject (show v) (JSON..: (T.pack $ show v))) <$> ask
go (ExprVariable v) = either error id . JSON.parseEither (JSON.withObject (show v) (JSON..: (toKey $ show v))) <$> ask
go (ExprParen e) = go e
go (ExprRange [stop]) = do
sstop <- either error id . JSON.parseEither (JSON.withScientific "range" return) <$> go stop
Expand All @@ -130,7 +130,7 @@ eval (Expression expression) = go expression where
_ -> error "range"
go (ExprRange _) = error "unreachable"
go (ExprAttributed e []) = go e
go (ExprAttributed e attrs) = either error id . JSON.parseEither (JSON.withObject (show $ last attrs) (JSON..: (T.pack $ show $ last attrs))) <$> go (ExprAttributed e $ init attrs)
go (ExprAttributed e attrs) = either error id . JSON.parseEither (JSON.withObject (show $ last attrs) (JSON..: (toKey $ show $ last attrs))) <$> go (ExprAttributed e $ init attrs)
go (ExprFiltered e []) = go e
go (ExprFiltered e filters) = applyFilter (last filters) $ ExprFiltered e $ init filters where
applyFilter FilterAbs e' = either error id . JSON.parseEither (JSON.withScientific "abs" (return . JSON.Number . abs)) <$> go e'
Expand Down
28 changes: 28 additions & 0 deletions src/Text/Haiji/Utils.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{-# LANGUAGE CPP #-}
module Text.Haiji.Utils where

import qualified Data.Aeson as JSON

#if MIN_VERSION_aeson(2,0,0)
import Data.String (fromString)
import qualified Data.Aeson.KeyMap as JSON

toKey :: String -> JSON.Key
toKey = fromString

insertValue :: JSON.Key -> JSON.Value -> JSON.KeyMap JSON.Value -> JSON.KeyMap JSON.Value
insertValue = JSON.insert

#else
import qualified Data.Text as T
import qualified Data.HashMap.Strict as HM

toKey :: String -> T.Text
toKey = T.pack

insertValue :: T.Text -> JSON.Value -> HM.HashMap T.Text JSON.Value -> HM.HashMap T.Text JSON.Value
insertValue = HM.insert
#endif



2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# For more information, see: https://github.com/commercialhaskell/stack/blob/release/doc/yaml_configuration.md

# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2)
resolver: lts-15.2
resolver: lts-19.24

# Local packages, usually specified by relative directory name
packages:
Expand Down