compile error (macosx intel), test failure, and few questions
Chris Kuklewicz
haskell at list.mightyreason.com
Fri Aug 11 13:56:00 EDT 2006
[ I am copying my reply to the libraries mailing list ]
Georgios Siganos wrote:
> Hi Chris,
> I am checking your library and i have found some problems with the head
> version on my system (macosx intel with ghc 6.5)
>
> First, I get a compile error when I build regex-tre
> Wrap.hsc:120:23: error: tre/regex.h: No such file or directory
> I can build the remaining modules with no errors.
The current README file suggest that you
"edit list of BACKENDS in Makefile if you want to exclude regex-tre or regex-pcre"
Since you do not have libtre, you can remove it from the BACKENDS near the top
of the main Makefile.
Theoretically, if you edited regex-tre/regex-tre.cabal to not define
-DHAVE_TRE_H then regex-tre would compile and install, but using it would be an
error. This is not going to work at the moment since I have not recently tested
that part of the source. But it could be handy if you want the module to exist,
but not depend on compiling against libtre.
> Second, I can successfully run your examples, but when i run
> TestTextRegexLazy I get a segmentation fault
> ...
> "StringPCRE"
> Us (backrefs):
> Cases: 15 Tried: 15 Errors: 0 Failures: 0
> Us (lazy patterns):
> Cases: 31 Tried: 31 Errors: 0 Failures: 0
> Us (possessive patterns):
> Cases: 27 Tried: 27 Errors: 0 Failures: 0
> Us (shared):
> Cases: 344 Tried: 50 Errors: 0 Failures: 0Segmentation fault
> I am not sure how helpful this can be, let me know if you want more
> details to find the cause
> of the segmentation fault. Note, that the stable version passes all the
> tests.
Hmmm....I just uploaded (about 10 minutes before your e-mail) version 0.70 to
both http://evenmere.org/~chrisk/trl/head/ and
http://evenmere.org/~chrisk/trl/stable. There was a pcre segfault that was
fixed back in version 0.66 or 0.67. (The FunPtr to pcre_free was null, so it
died randomly whenever the garbage collector ran.)
>
> Regarding the documentation, is there an easy way to produce it, or are
> you still working on it?
./setup haddock in each of the regex-* subdirectories will build ./dist/doc/*
but I don't have an automatic documentation installer.
>
> Finally, do you have any suggestion on how I can use sth similar to
> splitRegex on a ByteString? I want to split a ByteString using "\n\n" as
> a delimiter, and i am not sure what
> is the best way to do it.
I will eventually expand the compatibility API to provide that.
If you needed the split to be lazy, you can copy what
regex-compat/Text/Regex/New.hs does:
> splitRegex :: Regex -> String -> [String]
> splitRegex _ [] = []
> splitRegex delim str =
> case matchM delim str of
> Nothing -> [str]
> Just (firstline, _, remainder, _) ->
> if remainder == ""
> then firstline : [] : []
> else firstline : splitRegex delim remainder
But a more efficient way would be to get all the matches from PCRE in one pass
and then return all the intermediate parts:
> import Data.ByteString.Char8
> import Text.Regex.Base
> import Text.Regex.PCRE
>
> split' :: Regex -> ByteString -> [ByteString]
> split' regex source =
> let matches :: [(MatchOffset,MatchLength)]
> matches = match regex source
> process pos _ | pos `seq` False = undefined
> process pos [] = [after pos source]
> process pos ((s,o):rest) = extract (pos,s-pos) source : process (s+o) rest
> in process 0 matches
> *Main> split' (makeRegex "l|d") (pack "Hello World")
> ["He","","o Wor","",""]
> *Main> split' (makeRegex "l|o.") (pack "Hello World")
> ["He","","","W","","d"]
> *Main> split' (makeRegex ".o|\?") (pack "Hello World, how are you?")
> <interactive>:1:24: lexical error in string/character literal
> *Main> split' (makeRegex ".o") (pack "Hello World, how are you?")
> ["Hel"," ","rld, ","w are ","u?"]
> *Main> split' (makeRegex "l|.o") (pack "Hello World, how are you?")
> ["He","","o ","r","d, ","w are ","u?"]
> *Main> split' (makeRegex "H") (pack "Hello World, how are you?")
> ["","ello World, how are you?"]
> *Main> split' (makeRegex "H|h") (pack "Hello World, how are you?")
> ["","ello World, ","ow are you?"]
> *Main> split' (makeRegex "\n\n") (pack "Hello \nWorld,\n\n how\n are you?")
> ["Hello \nWorld,"," how\n are you?"]
> Keep on the good work,
> Georgos
>
:)
More information about the Libraries
mailing list