Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Regexp arity revisited

Thread Tools

Regexp arity revisited

trans. (T. Onoma)
Posts: n/a
Okay, I'm back to needing Regexp arity, and then some --I also need to know if
a particular subexpression if a zero-width positive lookahead. Why?

Have a look at this lovely interface:

class SplitToken < Token
def_attr :start_token, :end_token
def_attr :start_pattern, :end_pattern
def_attr :start_char, :end_char
def initialize( name, start_token, end_token, start_char=''..'',
end_char=''..'', opt=[] )
super( name, opt )
@start_token = start_token
@end_token = end_token
@start_char = start_char
@end_char = end_char
@start_pattern = /(#{start_char.first})(#{Regexp.escape(start_token) })
(#{'?=' if start_reuse?}#{start_char.last})/
@end_pattern = /(#{end_char.first})(#{Regexp.escape(end_token)})(# {'?='
if end_reuse?}#{end_char.last})/
# ...

class BlockToken < SplitToken
def initialize( name, start_pattern, opt=[] )
super( name, start_pattern, '', '\n\s*'..'', ''...'\n\ *\n' , opt |
[ :NEWLINE ] )
# ...

Notice the tricky way I use Ranges. #start_reuse? and #end_reuse? actually
just check @start_char.exclude_end? and @end_char.exclude_end? respectively.

I really don't want to do this. I'd rather just let the interface accept
Regexps directly, but then I would like to a) check for arity == 3 to make
sure they are valid and b) need to know if last subexpression is zero-width

I'll have to work around. But I think this represents the real use case --when
an interface accepts regexp and it wants to make sure they are valid.


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Why the expression "(1)" is not an one-arity tuple, but int ? Петров Александр Python 0 12-04-2009 12:17 PM
[regexp] How to convert string "/regexp/i" to /regexp/i - ? Joao Silva Ruby 16 08-21-2009 05:52 PM
Detecting the arity of a constructor at compile time Michael Feathers C++ 3 08-04-2006 04:18 PM
overloading on the template parameter arity of a template templateparameter Howard Gardner C++ 4 07-19-2006 11:10 PM
Regexp Arity trans. (T. Onoma) Ruby 15 09-23-2004 09:30 AM