Skip to content

Commit

Permalink
Replace mode (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
wzwietering authored Apr 4, 2022
1 parent cc9f840 commit ce753e7
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
1 change: 1 addition & 0 deletions backend/team-proj-abbr/data/test_file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello world. This file is written to test the expansions of kb_example.csv. We should see that @@hl is expanded to hello. This is a @@thm, which we cannot @@prf. No @@lmm or @@ax can be used, because this is not a scientific theorem.
1 change: 1 addition & 0 deletions backend/team-proj-abbr/data/test_file_target.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello world. This file is written to test the expansions of kb_example.csv. We should see that hello is expanded to hello. This is a theorem, which we cannot proof. No lemma or axiom can be used, because this is not a scientific theorem.
23 changes: 20 additions & 3 deletions backend/team-proj-abbr/lib-cli/LibCli/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ Stability : experimental

module LibCli.Main where

import qualified LibCli.Spec as CS (ShortHndr (..), cliModes)
import qualified System.Console.CmdArgs as CMD
import LibCli.Spec (ShortHndr (input, out))
import qualified LibCli.Spec as CS (ShortHndr (..), cliModes)
import LibCore.Decoder (decode)
import LibCore.KnowledgeBase (getKnowledgeBase)
import LibCore.Mapper (mapParseStructure)
import LibCore.OutputInterface (returnOutput)
import LibCore.Parser (doParse)
import qualified System.Console.CmdArgs as CMD

-----------------------
-- Command Handlers: --
Expand All @@ -19,13 +25,24 @@ import qualified System.Console.CmdArgs as CMD
-- TODO(tech-debt): define a typeclass for the modes instead of the pattern matching
-- TODO: (future task) implement the actual handlers with the business logic.
mockCliHandler :: CS.ShortHndr -> IO ()
mockCliHandler c@CS.Replace{} = print $ "replacing! --> " ++ show c
-- mockCliHandler [email protected]{} = print $ "replacing! --> " ++ show c
mockCliHandler c@CS.Replace{} = replaceMode c
mockCliHandler c@CS.Expand{} = print $ "expanding! --> " ++ show c
mockCliHandler c@CS.List{} = print $ "listing! --> " ++ show c
mockCliHandler c@CS.Add{} = print $ "adding! --> " ++ show c
mockCliHandler c@CS.Update{} = print $ "updating! --> " ++ show c
mockCliHandler c@CS.Delete{} = print $ "deleting! --> " ++ show c

replaceMode :: ShortHndr -> IO ()
replaceMode c@CS.Replace {} = do
case input c of
Nothing -> error "No input file was found"
Just f -> do
s <- readFile f
returnOutput (out c) (decode $ mapParseStructure getKnowledgeBase $ doParse s)
-- Impossible case because of the mockCliHandler
replaceMode _ = undefined

----------------------------
-- Executable entrypoiny: --
----------------------------
Expand Down
7 changes: 6 additions & 1 deletion backend/team-proj-abbr/lib-core/LibCore/Decoder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ Stability : experimental

module LibCore.Decoder where

import LibCore.Models (Keyword (Keyword), Token (DoMap, NoToken))
import LibCore.Parser (ParseStructure)

decode :: ParseStructure -> String
decode = undefined
decode s = unwords $ map tokenToString s

tokenToString :: Token -> String
tokenToString (NoToken s) = s
tokenToString (DoMap (Keyword k _)) = k
4 changes: 2 additions & 2 deletions backend/team-proj-abbr/lib-core/LibCore/KnowledgeBase.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ Stability : experimental

module LibCore.KnowledgeBase where

import Data.Map (Map)
import Data.Map (Map, empty)
import LibCore.Models (Keyword)

type KnowledgeBaseStructure = Map Keyword Keyword

getKnowledgeBase :: KnowledgeBaseStructure
getKnowledgeBase = undefined
getKnowledgeBase = empty
6 changes: 4 additions & 2 deletions backend/team-proj-abbr/lib-core/LibCore/OutputInterface.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ Stability : experimental

module LibCore.OutputInterface where

returnOutput :: String -> IO ()
returnOutput = undefined
returnOutput :: Maybe FilePath -> String -> IO ()
returnOutput f = case f of
Nothing -> error "No output file found"
Just s -> writeFile s

0 comments on commit ce753e7

Please sign in to comment.