On 22.02.2007 04:26, James Edward Gray II wrote:
> On Feb 21, 2007, at 8:15 PM, S. Robert James wrote:
> 
>> I'm parsing a large file, currently using compound regexen:
>>
>> PREAMBLE = 'AA'
>> USERID = '\d{8}'
>> USER_HELLO = "#{PREMABLE}(#{USERID})"
>>
>> Is there a simple way to do this using a parser such as ANTLR?  I've
>> never used one before, so if it requires a learning curve, I'll stick
>> to my regexen.
> 
> I really don't think there's any value in going all the way to a parser 
> generator here.  This job looks to be squarely in the Regexp domain, so 
> there's no reason to feel bad about using them.

Agree.  Also, in Ruby Regexp objects can nicely be used to build larger 
expressions because Regexp#to_s is nicely implemented to retain all the 
settings:

irb(main):001:0> PREAMBLE = /AA/
=> /AA/
irb(main):002:0> USERID = /\d{8}/
=> /\d{8}/
irb(main):003:0> USER_HELLO = /#{PREAMBLE}(#{USERID})/
=> /(?-mix:AA)((?-mix:\d{8}))/

That way you can make sure that all sub expressions are valid and you 
can nicely mix options - if you need to (for example, preamble case 
insensitive).

Kind regards

	robert