Hi Keith
At 06:25 AM 1/4/00 -0500, you wrote:
>Hi, just wondering about regular expressions in Rebol.
>
>1. Is there any support for regular expressions planned
I doubt that very much (but only REBOL Tech can tell you for sure). Parse -
and even more so the version Carl announced for REBOL/View - is much more
powerful and at the same time more user friendly.
>(or is Rebol only
>going to support 'parse for everything regular expressions might be used for
>that isn't already taken care of by words like 'find.)?
IMHO parse can easily replace regular expressions. But parse has by far
more capabilities than regular expresssions.
>
>2. I've heard that 'parse actually supports a superset of regular
>expressions. Is this true?
IMHO definitely.
>
>3. If there are no plans to build regular expressions into the language,
>would anyone be interested if someone were to develop a regular expression
>capability?
No idea.
>
>4. If there is interest, what are your thoughts on it? How would it work,
>look, etc?
If you are familiar with regexs, then I think you know how it should look
and work.
>
>maybe there could be a 'regex word, or possibly have it as a refinement to
>'parse, as in parse/regex. (Is it even possible to add a refinement to a
>native word?)
use [_parse] [
_parse: :parse
parse: func [string [any-string!] rule [string! block! none!] /regex] [
either regex [print "regex"] [_parse string rule]
]
] ;- close use
>> parse "abc" none
== ["abc"]
>> parse/regex "abc" none
regex
>
>a skeleton of 'regex might look like this:
>
>regex: make function! [
> string [string!] "The string to run the regex on"
> pattern [string! block!] "The regular expression pattern"
>]
>[
> ;do matching
>]
>
>'regex could return a block of values for patterns that have parentheses in
>them, so with
>
>string: "Hello, World. This is your captain speaking."
>regex string "(H.+),.+(c.+) "
>
>regex returns ["Hello" "captain"]
What you propose here would be a dialect.
>
>Maybe the 'regex could work purely by translating regular expressions into
>parse dialects and use 'parse internally? (that is, if parse contains
>everything necessary to do this).
Yes.
>
>Anyway, these are just some quick sketches. Does anyone think it would be
>worth it were someone to develop it?
Go ahead.
>Would it be so slow that it would be
>useless?
No. BTW, it should be a breeze to implement regexs using parse.
>Does anyone have any other thoughts they want to share?
>
Quite a few. But not on the topic of regexs ;-).
>Also, quick question about 'parse... does 'parse ever return a true value
>for anything other than simple splitting?
Parse always returns true when it works off the complete string that is
being parsed. To force parse to complete parsing the string, either include
to end
as part of your rule, whereupon parse, having evaluated your other rules,
will skip to the end of the input string and return true
or include an option
| skip
as part of your rule, whereupon parse will skip any character that has not
been handled by your other rules, ultimately reaching the end of the input
string and returning true.
;- Elan >> [: - )]