55-- Allow us to use string literals for Text
66{-# LANGUAGE OverloadedStrings #-}
77
8+ -- Allow us to treat incomplete tuples as function references.
9+ {-# LANGUAGE TupleSections #-}
10+
811module Graphics.Implicit.ExtOpenScad.Eval.Expr (evalArgs , evalExpr , rawRunExpr , matchPat , StateE , ExprState (ExprState ), addMessage ) where
912
1013import Prelude (String , Monoid , Maybe (Just , Nothing ), Bool (False , True ), ($) , elem , mempty , pure , show , zip , (&&) , const , (<>) , foldr , foldMap , (.) , (<$>) , traverse )
@@ -72,14 +75,14 @@ type StateE a = ImplicitCadM Input [Message] ExprState Identity a
7275runStateE :: Input -> ExprState -> StateE a -> (a , [Message ], ExprState )
7376runStateE r s m = runIdentity $ runImplicitCadM r s m
7477
75- -- Add a message to our list of messages contained in the StatE monad.
78+ -- | Add a message to our list of messages contained in the StateE monad.
7679addMessage :: MessageType -> SourcePosition -> Text -> StateE ()
7780addMessage mtype pos text = addMesg $ Message mtype pos text
7881 where
7982 addMesg :: Message -> StateE ()
8083 addMesg = tell . pure
8184
82- -- Log an error condition.
85+ -- | Log an error condition.
8386errorE :: SourcePosition -> Text -> StateE ()
8487errorE = addMessage Error
8588
@@ -122,10 +125,10 @@ evalExpr sourcePos expr = case expr of
122125 evalExprStateC sourcePos expr
123126 _ -> evalExprStateC sourcePos expr
124127 where
125- isModule (OUModule _ _ _ ) = True
126- isModule (ONModule _ _ _ ) = True
127- isModule (ONModuleWithSuite _ _ _ ) = True
128- isModule (OVargsModule _ _ ) = True
128+ isModule (OUModule {} ) = True
129+ isModule (ONModule {} ) = True
130+ isModule (ONModuleWithSuite {} ) = True
131+ isModule (OVargsModule {} ) = True
129132 isModule _ = False
130133 -- FIXME: We may need a better result cannonicalizer here.
131134 canonicalizeRes (OList [oneItem]) = oneItem
@@ -136,7 +139,7 @@ runExprModule :: SourcePosition -> OVal -> [Expr] -> StateC [OVal]
136139runExprModule sourcePos mod argExprsRaw = do
137140 let
138141 -- Mark all of our arguments as unnamed. There are no named arguments in expressions.
139- argExprs = (\ a -> ( Nothing , a) ) <$> argExprsRaw
142+ argExprs = (Nothing ,) <$> argExprsRaw
140143 -- Common error messages.
141144 noSuiteError ,notModError :: (Monoid a ) => StateC a
142145 noSuiteError = do
@@ -151,10 +154,10 @@ runExprModule sourcePos mod argExprsRaw = do
151154
152155 -- We can't handle any suites, either.
153156 _ <- case mod of
154- (OUModule _ _ _ ) -> pure mempty :: StateC ()
155- (ONModule _ _ _ ) -> pure mempty
156- (ONModuleWithSuite _ _ _ ) -> noSuiteError
157- (OVargsModule _ _ ) -> noSuiteError
157+ (OUModule {} ) -> pure mempty :: StateC ()
158+ (ONModule {} ) -> pure mempty
159+ (ONModuleWithSuite {} ) -> noSuiteError
160+ (OVargsModule {} ) -> noSuiteError
158161 _ -> notModError
159162
160163 -- Perform any per-module-type specific housework, and call the module.
@@ -169,8 +172,8 @@ runExprModule sourcePos mod argExprsRaw = do
169172 (ONModule _ implementation _) -> do
170173 -- Run the module.
171174 runModule sourcePos $ argMap evaluatedArgs $ implementation sourcePos
172- (ONModuleWithSuite _ _ _ ) -> noSuiteError
173- (OVargsModule _ _ ) -> noSuiteError
175+ (ONModuleWithSuite {} ) -> noSuiteError
176+ (OVargsModule {} ) -> noSuiteError
174177 _ -> notModError
175178
176179-- | The inner monadic entry point. Evaluates an expression, pureing the result, and moving any error messages generated into the calling StateC.
@@ -185,7 +188,7 @@ evalExprStateC pos expr = do
185188 traverse_ moveMessage messages
186189 pure $ valf []
187190
188- -- A more raw entry point, that does not depend on IO.
191+ -- A pure entry point, that does not do module calls, and does not depend on IO.
189192rawRunExpr :: SourcePosition -> VarLookup -> Expr -> (OVal , [Message ])
190193rawRunExpr pos vars expr = do
191194 let
@@ -241,7 +244,7 @@ evalExpr' (fexpr :$ argExprs) = do
241244 app f l = case (getErrors f, getErrors $ OList l) of
242245 (Nothing , Nothing ) -> app' f l
243246 where
244- -- apply function to the list of its arguments until we run out
247+ -- Apply a function to the list of its arguments until we run out
245248 -- of them
246249 app' (OFunc f') (x: xs) = app (f' x) xs
247250 app' a [] = a
0 commit comments