Ilmari Heikkinen
1/24/2005 4:49:00 PM
Aahhh and 10 seconds after I sent that, another way surfaced:
Parser::Token configurators could use define_method instead of
@class_ivar, that way they'd be inherited.
Mmh. I'm not really happy with either of my suggestions. Oh well, may
others have better ways.
On 24.1.2005, at 18:40, Ilmari Heikkinen wrote:
> Hi,
> On 24.1.2005, at 18:15, Trans wrote:
>
>> |class Marker < Parser::Token
>> |
>> | exclusive false
>> | start { %r{ \< (.*?) \> }mx }
>> | stop { |match| %r{ \< [ ]* (#{esc(match[1])}) (.*?) \. \> }mx }
>> |
>> | #... user's optional methods ...
>>
>> It toke me some time to work this out in itself. And I thought I had
>> finally gotten a fairly nice interface here. But to my dismay, I just
>> discovered that I can't subclass Marker b/c I loose the definitions of
>> the above attributes (ie. exclusive, start, stop). So now I'm back to
>> rethinking the whole setup. (Also note that if the user's methods
>> redefine #initialize or the other Token methods, it might cause the
>> parser that uses it to break --another slight down side and a possible
>> use case for RCR #198)
>>
>> So how does one properly build something like this in a nice neat way?
>>
>
> This is the first thought that entered my mind: turn the configuration
> methods into instance methods, move the method calls to #initialize,
> and call super there:
>
> class Marker < Parser::Token
> def initialize
> super
> exclusive false
> start { %r{ \< (.*?) \> }mx }
> stop { |match| %r{ \< [ ]* (#{esc(match[1])}) (.*?) \. \> }mx }
> end
> end
>
> class ExclusiveMarker < Marker
> def initialize
> super
> exclusive true
> end
> end
>
>
> Maybe that would work?
>
> --
> Ilmari Heikkinen
>
>
>