Add close parens

This commit is contained in:
Chris Done 2017-12-10 16:17:53 +00:00
parent 0491980569
commit 27b63e51ae
2 changed files with 31 additions and 18 deletions

View File

@ -79,7 +79,7 @@ makeState ident expr =
instance Flux.StoreData State where
type StoreAction State = Action
transform action state = do
-- putStrLn ("Action: " ++ show action)
putStrLn ("Action: " ++ show action)
-- putStrLn ("State before: " ++ show state)
state' <- execStateT (interpretAction action) state
-- putStrLn ("State after: " ++ show state')

View File

@ -333,23 +333,8 @@ interpretKeyPress k = do
43 -> interpretOperator '+' (stateCursor s) (stateAST s)
45 -> interpretOperator '-' (stateCursor s) (stateAST s)
47 -> interpretOperator '/' (stateCursor s) (stateAST s)
40 -> do
ast <-
transformExpression
(cursorUUID (stateCursor s))
(const
(\e ->
case e of
(ConstantExpression _ (Identifier "_")) -> do
l' <- liftIO newParens
case l' of
ParensExpression _ e' ->
focusNode (expressionLabel e')
_ -> pure ()
pure l'
_ -> pure e))
(stateAST s)
modify (\s' -> s' {stateAST = ast})
40 -> interpretOpenParen s
41 -> interpretCloseParen s
_ ->
case stateCursor s of
cursor ->
@ -360,6 +345,34 @@ interpretKeyPress k = do
where
isSpaceCode = (== 32)
interpretCloseParen :: Monad m => State -> StateT State m ()
interpretCloseParen s =
case findNodeParent (cursorUUID (stateCursor s)) (stateAST s) of
Nothing -> pure ()
Just p ->
case findNodeParent (nodeUUID p) (stateAST s) of
Just p'@(ExpressionNode (ParensExpression{})) -> focusNode (nodeLabel p')
_ -> focusNode (nodeLabel p)
interpretOpenParen :: MonadIO m => State -> StateT State m ()
interpretOpenParen s = do
ast <-
transformExpression
(cursorUUID (stateCursor s))
(const
(\e ->
case e of
(ConstantExpression _ (Identifier "_")) -> do
l' <- liftIO newParens
case l' of
ParensExpression _ e' ->
focusNode (expressionLabel e')
_ -> pure ()
pure l'
_ -> pure e))
(stateAST s)
modify (\s' -> s' {stateAST = ast})
interpretOperator :: Char -> Cursor -> Node -> StateT State IO ()
interpretOperator c cursor ast = do
(ast', mparent) <-