|
| 1 | +{-# LANGUAGE MultiWayIf #-} |
1 | 2 | {-# LANGUAGE FlexibleContexts #-} |
2 | 3 | {-# LANGUAGE LambdaCase #-} |
3 | 4 | {-# LANGUAGE OverloadedStrings #-} |
@@ -66,7 +67,7 @@ main = do |
66 | 67 | (filePaths opts) |
67 | 68 | ) |
68 | 69 | (\ x -> |
69 | | - -- use Text as in the base case, requires changing FilePath -> Text |
| 70 | + -- We can start use Text as in the base case, requires changing FilePath -> Text |
70 | 71 | traverse_ (processFile opts) . lines =<< liftIO |
71 | 72 | (case x of |
72 | 73 | "-" -> getContents -- get user input |
@@ -129,57 +130,36 @@ main = do |
129 | 130 | (evaluate opts) |
130 | 131 |
|
131 | 132 | process opts mpath expr |
132 | | - | evaluate opts |
133 | | - , tracing opts |
134 | | - = evaluateExpression mpath Nix.nixTracingEvalExprLoc printer expr |
135 | | - | evaluate opts |
136 | | - , Just path <- reduce opts |
137 | | - = evaluateExpression mpath (reduction path) printer expr |
138 | | - | evaluate opts |
139 | | - , not (null (arg opts) && null (argstr opts)) |
140 | | - = evaluateExpression mpath Nix.nixEvalExprLoc printer expr |
141 | | - | evaluate opts |
142 | | - = processResult printer =<< Nix.nixEvalExprLoc mpath expr |
143 | | - | xml opts |
144 | | - = error "Rendering expression trees to XML is not yet implemented" |
145 | | - | json opts |
146 | | - = error "Rendering expression trees to JSON is not implemented" |
147 | | - | verbose opts >= DebugInfo |
148 | | - = liftIO $ putStr $ PS.ppShow $ stripAnnotation expr |
| 133 | + | evaluate opts = |
| 134 | + if |
| 135 | + | tracing opts -> evaluateExpression mpath Nix.nixTracingEvalExprLoc printer expr |
| 136 | + | Just path <- reduce opts -> evaluateExpression mpath (reduction path) printer expr |
| 137 | + | not ( null (arg opts) |
| 138 | + && null (argstr opts) |
| 139 | + ) -> evaluateExpression mpath Nix.nixEvalExprLoc printer expr |
| 140 | + | otherwise -> processResult printer =<< Nix.nixEvalExprLoc mpath expr |
| 141 | + | xml opts = error "Rendering expression trees to XML is not yet implemented" |
| 142 | + | json opts = error "Rendering expression trees to JSON is not implemented" |
| 143 | + | verbose opts >= DebugInfo = liftIO $ putStr $ PS.ppShow $ stripAnnotation expr |
149 | 144 | | cache opts |
150 | | - , Just path <- mpath |
151 | | - = liftIO $ writeCache (addExtension (dropExtension path) "nixc") expr |
152 | | - | parseOnly opts |
153 | | - = void $ liftIO $ Exc.evaluate $ Deep.force expr |
154 | | - | otherwise |
155 | | - = liftIO |
156 | | - $ renderIO stdout |
157 | | - . layoutPretty (LayoutOptions $ AvailablePerLine 80 0.4) |
158 | | - . prettyNix |
159 | | - . stripAnnotation |
160 | | - $ expr |
| 145 | + , Just path <- mpath = liftIO $ writeCache (addExtension (dropExtension path) "nixc") expr |
| 146 | + | parseOnly opts = void $ liftIO $ Exc.evaluate $ Deep.force expr |
| 147 | + | otherwise = |
| 148 | + liftIO $ |
| 149 | + renderIO |
| 150 | + stdout |
| 151 | + . layoutPretty (LayoutOptions $ AvailablePerLine 80 0.4) |
| 152 | + . prettyNix |
| 153 | + . stripAnnotation $ |
| 154 | + expr |
161 | 155 | where |
162 | 156 | printer |
163 | | - | finder opts |
164 | | - = fromValue @(AttrSet (StdValue (StandardT (StdIdT IO)))) >=> findAttrs |
165 | | - | xml opts |
166 | | - = liftIO |
167 | | - . putStrLn |
168 | | - . Text.unpack |
169 | | - . stringIgnoreContext |
170 | | - . toXML |
171 | | - <=< normalForm |
172 | | - | json opts |
173 | | - = liftIO |
174 | | - . Text.putStrLn |
175 | | - . stringIgnoreContext |
176 | | - <=< nvalueToJSONNixString |
177 | | - | strict opts |
178 | | - = liftIO . print . prettyNValue <=< normalForm |
179 | | - | values opts |
180 | | - = liftIO . print . prettyNValueProv <=< removeEffects |
181 | | - | otherwise |
182 | | - = liftIO . print . prettyNValue <=< removeEffects |
| 157 | + | finder opts = findAttrs <=< fromValue @(AttrSet (StdValue (StandardT (StdIdT IO)))) |
| 158 | + | xml opts = liftIO . putStrLn . Text.unpack . stringIgnoreContext . toXML <=< normalForm |
| 159 | + | json opts = liftIO . Text.putStrLn . stringIgnoreContext <=< nvalueToJSONNixString |
| 160 | + | strict opts = liftIO . print . prettyNValue <=< normalForm |
| 161 | + | values opts = liftIO . print . prettyNValueProv <=< removeEffects |
| 162 | + | otherwise = liftIO . print . prettyNValue <=< removeEffects |
183 | 163 | where |
184 | 164 | findAttrs |
185 | 165 | :: AttrSet (StdValue (StandardT (StdIdT IO))) |
|
0 commit comments