mirror of
https://github.com/Haskell-Things/ImplicitCAD.git
synced 2024-09-19 08:57:33 +03:00
make CSG in the expression engine disableable, and use it disabled when performing tests on evaluation.
This commit is contained in:
parent
f96e7712e0
commit
40771b5324
@ -9,7 +9,7 @@
|
||||
-- An executor, which parses openscad code, and executes it.
|
||||
module Graphics.Implicit.ExtOpenScad (runOpenscad) where
|
||||
|
||||
import Prelude(String, IO, ($), (<$>), pure, either, (.), Applicative)
|
||||
import Prelude(String, IO, ($), (<$>), pure, either, (.), Applicative, Bool(True))
|
||||
|
||||
import Graphics.Implicit.Definitions (SymbolicObj2, SymbolicObj3)
|
||||
|
||||
@ -36,7 +36,7 @@ import Data.Foldable (traverse_)
|
||||
-- | Small wrapper of our parser to handle parse errors, etc.
|
||||
runOpenscad :: ScadOpts -> [String] -> String -> IO (VarLookup, [SymbolicObj2], [SymbolicObj3], [Message])
|
||||
runOpenscad scadOpts constants source = do
|
||||
(initialObjects, initialMessages) <- addConstants constants
|
||||
(initialObjects, initialMessages) <- addConstants constants True
|
||||
let
|
||||
err :: Applicative f => ParseError -> f (VarLookup, [SymbolicObj2], [SymbolicObj3], [Message])
|
||||
err e = pure (initialObjects, [], [], mesg e : initialMessages)
|
||||
|
@ -20,14 +20,14 @@ import Data.Map (Map, fromList, insert)
|
||||
import Data.List (genericIndex, genericLength, intercalate)
|
||||
import Data.Foldable (for_)
|
||||
|
||||
defaultObjects :: VarLookup
|
||||
defaultObjects = VarLookup $ fromList $
|
||||
defaultObjects :: Bool -> VarLookup
|
||||
defaultObjects withCSG = VarLookup $ fromList $
|
||||
defaultConstants
|
||||
<> defaultFunctions
|
||||
<> defaultFunctions2
|
||||
<> defaultFunctionsSpecial
|
||||
<> defaultPolymorphicFunctions
|
||||
<> primitiveModules
|
||||
<> (if withCSG then primitiveModules else [])
|
||||
<> varArgModules
|
||||
|
||||
-- FIXME: Missing standard ones(which standard?):
|
||||
|
@ -49,10 +49,10 @@ import Graphics.Implicit.ExtOpenScad.Parser.Util (patternMatcher)
|
||||
import Graphics.Implicit.ExtOpenScad.Parser.Lexer (matchTok)
|
||||
|
||||
-- | Define variables used during the extOpenScad run.
|
||||
addConstants :: [String] -> IO (VarLookup, [Message])
|
||||
addConstants constants = do
|
||||
addConstants :: [String] -> Bool -> IO (VarLookup, [Message])
|
||||
addConstants constants withCSG = do
|
||||
path <- getCurrentDirectory
|
||||
(_, s) <- liftIO . runStateT (execAssignments constants) $ CompState defaultObjects [] path [] opts
|
||||
(_, s) <- liftIO . runStateT (execAssignments constants) $ CompState (defaultObjects withCSG) [] path [] opts
|
||||
pure (scadVars s, messages s)
|
||||
where
|
||||
opts = ScadOpts False False
|
||||
@ -70,11 +70,11 @@ addConstants constants = do
|
||||
parseAssignment = parse $ (,) <$> patternMatcher <* matchTok '=' <*> expr0
|
||||
|
||||
-- | Evaluate an expression.
|
||||
runExpr :: String -> (OVal, [Message])
|
||||
runExpr expression = do
|
||||
runExpr :: String -> Bool -> (OVal, [Message])
|
||||
runExpr expression withCSG = do
|
||||
either oUndefined run $ parse expr0 "raw_expression" expression
|
||||
where
|
||||
run expr = rawRunExpr initPos defaultObjects expr
|
||||
run expr = rawRunExpr initPos (defaultObjects withCSG) expr
|
||||
initPos = SourcePosition 1 1 "raw_expression"
|
||||
show' = showErrorMessages "or" "unknown parse error" "expecting" "unexpected" "end of input" . errorMessages
|
||||
oUndefined e = (OUndefined, [Message SyntaxError initPos $ show' e])
|
||||
|
Loading…
Reference in New Issue
Block a user