[Haskell-cafe] simple word processor

Dennis Gaita gaitadennis at gmail.com
Tue Oct 26 16:13:36 UTC 2021


-1
<https://stackoverflow.com/posts/69702739/timeline>

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.

I need help because my code isn't running.This is the code:

import Text.Format
import Data.Text.Internal.Search
import Data.Text

s = count . "section" -- count number of occurences of a certain word
t = count . "table"
f = count .  "Figure"
r = count . "ref"


forLoop :: Int - Int - Int - Int

forLoop  s value =
    if  i < s
        then forLoop (i + 1) format "Section{title}{id}" [show i, show
{title}]
then replace "Section{i}{title}" "Section {i}:{title}"
        else value


forLoop  t value =
if  j < t
        then forLoop (j + 1) format "table{title}{id}" [show i.j, show
{title}] --change the text
then replace "table{i}.{j}{title}" "Table {i}.{j} : {title}"
        else value

forLoop  f value =
if  k < f
        then forLoop (k + 1) format "figure{title}{id}" [show i.k, show
{title}] --change the text
then replace "Figure{title}{id}" "Figure {i}.{k} : {title}"
else value


if "ref{id}" == "table{title}"
then forLoop  r value =
    if  l < r
        then forLoop (l + 1) format "ref{id}" [show {title}] --change the
text
then replace "ref{id}" "see {title} {i}.{j}"
        else value
else Nothing

if "ref{id}" == "Figure{title}"
then forLoop  r value =
    if  m < r
        then forLoop (m + 1) format "ref{id}" [show {title}] --change the
text
then replace "ref{id}" "see {title} {i}.{m}"
        else value
else Nothing

if "ref{id}" == "Section{title}"
then forLoop r value =
if n < r
then forLoop(n+1) format "ref{id}" [show{title}]
then replace "ref{id}" "see {title} {i}"
else value
else nothing
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20211026/6daa537e/attachment.html>


More information about the Haskell-Cafe mailing list