11module HaskellCI.ShVersionRange (
22 compilerVersionPredicate ,
33 compilerVersionArithPredicate ,
4+ compilerVersionPredicateImpl ,
5+ freeToArith ,
6+ ExprConfig (.. ),
47 roundDown ,
58) where
69
@@ -21,11 +24,11 @@ import HaskellCI.Compiler
2124-- >>> import qualified Distribution.Version as C
2225
2326compilerVersionPredicate :: Set CompilerVersion -> CompilerRange -> String
24- compilerVersionPredicate = compilerVersionPredicateImpl (toTest . freeToArith ) where
27+ compilerVersionPredicate = compilerVersionPredicateImpl (toTest . shFreeToArith ) where
2528 toTest expr = " [ " ++ expr ++ " -ne 0 ]"
2629
2730compilerVersionArithPredicate :: Set CompilerVersion -> CompilerRange -> String
28- compilerVersionArithPredicate = compilerVersionPredicateImpl freeToArith
31+ compilerVersionArithPredicate = compilerVersionPredicateImpl shFreeToArith
2932
3033compilerVersionPredicateImpl
3134 :: (Free String -> String )
@@ -197,14 +200,25 @@ roundDown = go S.empty . S.toList where
197200-- Arithmetic expression
198201-------------------------------------------------------------------------------
199202
200- freeToArith :: Free String -> String
201- freeToArith z
203+ shWrapExpr :: String -> String
204+ shWrapExpr expr = " $((" ++ expr ++ " ))"
205+
206+ shFreeToArith :: Free String -> String
207+ shFreeToArith = freeToArith $ ExprConfig shWrapExpr id
208+
209+ data ExprConfig = ExprConfig {
210+ _exprWrap :: String -> String
211+ , _varWrap :: String -> String
212+ }
213+
214+ freeToArith :: ExprConfig -> Free String -> String
215+ freeToArith (ExprConfig exprWrap varWrap) z
202216 | z == top = " 1"
203217 | z == bottom = " 0"
204- | otherwise = " $(( " ++ go 0 z ++ " )) "
218+ | otherwise = exprWrap $ go 0 z
205219 where
206220 go :: Int -> Free String -> String
207- go _ (Var x) = x
221+ go _ (Var x) = varWrap x
208222 go _ F. Bottom = " 1"
209223 go _ F. Top = " 0"
210224
0 commit comments