Regexp arity revisited

Discussion in 'Ruby' started by trans. (T. Onoma), Oct 20, 2004.

  1. 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})/
    end
    # ...
    end

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

    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
    lookahead.

    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.

    T.
     
    trans. (T. Onoma), Oct 20, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Howard Gardner
    Replies:
    4
    Views:
    362
    Howard Gardner
    Jul 20, 2006
  2. Michael Feathers
    Replies:
    3
    Views:
    293
    Roland Pibinger
    Aug 4, 2006
  3. ðÅÔÒÏ× áÌÅËÓÁÎÄÒ

    Why the expression "(1)" is not an one-arity tuple, but int ?

    ðÅÔÒÏ× áÌÅËÓÁÎÄÒ, Dec 4, 2009, in forum: Python
    Replies:
    0
    Views:
    280
    ðÅÔÒÏ× áÌÅËÓÁÎÄÒ
    Dec 4, 2009
  4. trans.  (T. Onoma)

    Regexp Arity

    trans. (T. Onoma), Sep 22, 2004, in forum: Ruby
    Replies:
    15
    Views:
    284
    Robert Klemme
    Sep 23, 2004
  5. Joao Silva
    Replies:
    16
    Views:
    390
    7stud --
    Aug 21, 2009
Loading...

Share This Page