Hello,

Thanks to those who pointed out that my previous function p was not tail
recursive.
I think "exclude" (below) is. It seems to work on large files, although
on a 160K
file garbage collection fails to get enough space. 

What I am trying to do is find, in input such as an HTML file, like
"ab<table>c",
the string before the keyword such as "table".  So I try the keyword
parsers
(in the list "ps" below) at each point in the input, and add the
character to
my answer if all the parsers fail.  Something like a Boyer-Moore string
search might
be used to, though that would add complexity.  I couldn't find such an
algorithm
in any Hugs library.

---------------------------- program -----------------------------

import ParseLib

exclude ans parsers  = P (\inp -> case inp of
           []      -> [(reverse ans,"")]
           (c:cs)  -> case papply try inp of
                                [(_,remaining)] -> [(reverse ans,remaining)]
                                []                -> papply (exclude (c:ans) parsers) 
cs
                         )
  where try = commonSubstring >> foldr1 (+++) parsers


test  = papply (exclude "" ps) "ab<table>c" 

commonSubstring = string "<"

ps = [string "table>",string "/table>" ]

ww.hs

Reply via email to