I am new to haskell and I need to create a simple word processor. It needs to read text from the cmd and implement functions that would edit functions found in the text so some other text.All functions in the text are odered. Each function i.e section,table,figures and ref must be located and numbered independently based on the order of occurence. Since tables and figures are within the sections function(just like a book), when a new section is encountered you will reset the value of tables and figures. So i did a loop where the tables and figures are inside the section loop when searching for the functions. The functions all start with this '' character (escape character) and must be replaced with text using this method: \Section{title}{id}: -> "Section n: title". Where n is the section number. \table{title}{id} : -> "Table n.m : title". Where n is the number of the last section encountered and m is the table number. And so on. So I first imported a text document from the command line using this code:
import System.Environment (getArgs)
import System.IO (openFile, ReadWriteMode, hGetContents)
import Text.Format
import Data.Text.Internal.Search
import Data.Text
main = do
args <- getArgs -- reading and writing files from CMD
file <- openFile (head args) ReadWriteMode
text <- hGetContents file
Then, I counted the number of times section,tables and figures appeard on the text so that I could implement a loop:
s = count . "section" -- count number of occurences of a certain word
t = count . "table"
f = count . "Figure"
r = count . "ref"
I finally implemented a formart text function inside a loop changing the functions according to the number of times they appeared:
i = 1
for i in range s format "\Section{title}{id}" [show i, show {title}] --change the text
for j in range t format "\table{title}{id}" [show i.j, show {title}]
for k in range f format "\figure{title}{id}" [show i.k, show {title}]
I however know this code is wrong and I'm stuck and need help.