[Haskell-cafe] Re: Has anybody replicated =~ s/../../ or even
something more basic for doing replacements with pcre haskell regexen?
Thomas Hartman
tphyahoo at gmail.com
Tue Mar 17 15:15:57 EDT 2009
2009/3/16 ChrisK <haskell at list.mightyreason.com>:
>
> Let me open the discussion with all the questions I can quickly ask:
>
> What should the "subRegex" function do, exactly?
> (Single replacement,global replacement,once per line,...)
Try to do the same thing as =~ s/../../ in perl.
For a version 1: Global replacements, don't treat newlines separately,
^ and $ anchor at start and end of string.
There could be a Bool option to support multiline replacement modes.
>
> What should the replacement template be able to specify?
> (Can it refer to all text before a match or all text after?)
> (Can it access the start/stop offsets as numbers?)
Again, follow =~ s/../../
I'm not sure what =~ allows in this dimension though.
My instinct is
> (Can it refer to all text before a match or all text after?)
no
> (Can it access the start/stop offsets as numbers?)
no
But maybe that's just because I've never needed the above functionality.
I basically think of =~ s as "quick cleanup for dirty text" solution,
nothing approaching full-fledged parsing.
> Should the replacement template be specif~ied in a "String"?
Sure, just like it is in Text.Regex.subRegex now. No combinators,
\numbered capture references are fine.
> As an abstract
> data type or syntax tree? With combinators?
Just a string I think.
> What happens if the referenced capture was not made? Empty text?
Return the original string. Isn't that what subRegex already does?
> How will syntax errors in the template be handled (e.g. referring to a
> capture that does not exist in the regular expression)?
runtime error
> Will the output text be String? ByteString? ByteString.Lazy? Seq Char?
> Note: String and Strict Bytestrings are poor with concatenation.
String. Add support for others if users holler for it
>
> Can the output text type differ from the input text type?
Nah.
My 2c.
>
> --
> Chris
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
More information about the Haskell-Cafe
mailing list