5 Apr 2005 09:08
Re: Re: [groovy-user] Re: Strings: Regular Expression Patterns
I really like it! :)
On 5 Apr 2005, at 02:42, John Rose wrote:
> I implemented a straightforward version of our ideas about regexps.
> It's simply a third string syntax, as in 'foo', "foo", /foo/.
>
> The treatment of backslash escapes in /foo/ favors regular expression
> notation, but it's just a string to the language.
>
> It reads reasonably well:
>
> if ('abc' =~ /.../) whatever
> if ('abc' ==~ /.../) whatever
> 'abc'.eachMatch(/.../) { whatever }
> ['a','b','c'].grep(/a/)
> switch('abc'){
> case ~/.../ : whatever
> }
> assert 'EUOUAE'.matches(/^[aeiou]*$/)
> assert 'football'.replaceAll(/foo/, "Bar") == 'Bartball'
>
> It turns out that the division operators and regexp literals want to
> be in very different places, so there's no real ambiguity to the eye.
> It's easy enough to get over it in the lexer also.
> x = y / z
> x = /xyzzy/
>
> Also, uses of dollars and braces for GStrings are (luckily) quite
> distinct from uses of the same characters in the regexp language, so
> there seems to be a happy marriage possible between Groovy GStrings
> and regexps.
> x =~ /${word} ${word}/
> x =~ /^true$|^false$/
>
> Here are some test cases:
> http://cvs.codehaus.org/viewrep/groovy/groovy/groovy-core/src/test/
> groovy/GStringTest.groovy
>
> Comments?
>
> -- John
>
>
James
-------
http://radio.weblogs.com/0112098/
RSS Feed