Commit f64d1f0e authored by Jan Koniarik's avatar Jan Koniarik
Browse files

formatting changes to parser

parent f7ba24c0
Pipeline #101232 failed with stage
in 8 minutes and 51 seconds
......@@ -19,6 +19,7 @@ import qualified Data.Map as Map
import Data.Maybe
import Debug.Trace ( traceShow
, traceShowM
, traceShowId
)
import qualified Language.OpenSCAD as LS
import qualified Schpin.SCAD as SC
......@@ -30,9 +31,6 @@ import System.IO.Unsafe
import Schpin.Walker
import Data.Hashable ( hash )
import Debug.Trace (traceShowId)
import System.Directory
data ExprRes = RNum Double | RString String | RBool Bool | RVec [ExprRes] | RUndef deriving (Show, Eq)
type Arg = (String, ExprRes)
data ObjectRes = RUnion [ObjectRes] | RTranslate [Arg] (Maybe ObjectRes) | RRotate [Arg] (Maybe ObjectRes) | RPart {
......@@ -62,44 +60,34 @@ emptyScope :: Scope
emptyScope = Scope HM.empty HM.empty HM.empty Nothing []
getScopeVar :: String -> EvalM (Maybe ExprRes)
getScopeVar key = do
lift $ gets (\s -> HM.lookup key $ vars s)
getScopeVar key = lift $ gets (HM.lookup key vars)
insertScopeVar :: String -> ExprRes -> EvalM ()
insertScopeVar key val = do
lift $ modify (\s -> s { vars = HM.insert key val $ vars s })
insertScopeVar key val = lift $ modify (\s -> s { vars = HM.insert key val $ vars s })
getScopeModule :: String -> EvalM (Maybe ModuleDefContent)
getScopeModule key = do
lift $ gets (\s -> HM.lookup key $ mods s)
getScopeModule key = lift $ gets (HM.lookup key mods)
insertScopeModule :: String -> ModuleDefContent -> EvalM ()
insertScopeModule k v = do
lift $ modify (\s -> s { mods = HM.insert k v $ mods s })
insertScopeModule k v = lift $ modify (\s -> s { mods = HM.insert k v $ mods s })
getScopeFunc :: String -> EvalM (Maybe ([LS.Ident], LS.Expr))
getScopeFunc k = do
lift $ gets (\s -> HM.lookup k $ func s)
getScopeFunc k = lift $ gets (HM.lookup k func)
insertScopeFunc :: String -> ([LS.Ident], LS.Expr) -> EvalM ()
insertScopeFunc k v = do
lift $ modify (\s -> s { func = HM.insert k v $ func s })
insertScopeFunc k v = lift $ modify (\s -> s { func = HM.insert k v $ func s })
getScopeChildren :: EvalM (Maybe ObjectRes)
getScopeChildren = do
lift $ gets (\s -> children s)
getScopeChildren = lift $ gets children
insertScopeChildren :: ObjectRes -> EvalM ()
insertScopeChildren ch = do
lift $ modify (\s -> s { children = Just ch })
insertScopeChildren ch = lift $ modify (\s -> s { children = Just ch })
pushStack :: String -> EvalM ()
pushStack msg = do
lift $ modify (\s -> s { call_stack = call_stack s ++ [msg] })
pushStack msg = lift $ modify (\s -> s { call_stack = call_stack s ++ [msg] })
popStack :: EvalM ()
popStack = do
lift $ modify (\s -> s { call_stack = init $ call_stack s })
popStack = lift $ modify (\s -> s { call_stack = init $ call_stack s })
withCallStack :: String -> EvalM a -> EvalM a
withCallStack msg rec = do
......@@ -110,7 +98,7 @@ withCallStack msg rec = do
printModuleScope :: EvalM ()
printModuleScope = do
s <- lift $ gets (\s -> HM.keys $ mods s)
s <- lift $ gets (HM.keys mods)
traceShowM ("Scope: " ++ show s)
raiseError :: String -> EvalM a
......@@ -133,20 +121,18 @@ loadScope cmp = withCallStack "load_scope" $ do
f (x : xs) = do
case x of
LS.TopLevelScope obj -> case obj of
LS.ModuleDef (LS.Ident name) args body -> do
insertScopeModule name (args, body)
LS.ModuleDef (LS.Ident name) args body -> insertScopeModule name (args, body)
LS.VarDef (LS.Ident name) expr -> do
e <- evalExpr expr
insertScopeVar name e
LS.FuncDef (LS.Ident name) args body -> do
insertScopeFunc name (args, body)
LS.FuncDef (LS.Ident name) args body -> insertScopeFunc name (args, body)
_ -> return ()
_ -> return ()
f xs
localScope :: EvalM a -> EvalM a
localScope sub = do
s <- lift $ get
s <- lift get
let x = evalState (runExceptT sub) s
case x of
Left err -> throwError err
......@@ -175,13 +161,13 @@ evalUntilParts root_file obj cmap = case res of
[ ExtrPart { ex_name = name
, ex_model = model
, ex_print_file = if printed
then Just $ filename
then Just filename
else Nothing
}
]
where
filename :: String
filename = module_name model ++ "_" ++ (show $ hash name `mod` 9068 )
filename = module_name model ++ "_" ++ show ( hash name `mod` 9068 )
evalExpr :: LS.Expr -> EvalM ExprRes
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment