Ruby Legacy Parser has problems parsing all caps method names

20 views
Skip to first unread message

bwil...@blurb.com

unread,
May 16, 2013, 1:40:10 PM5/16/13
to yar...@googlegroups.com
We have some code that uses a dubious, but apparently legal coding style, which causes the legacy parser methodname regex to go haywire.

class CoverType < ActiveRecord::Base
  class << self
    def ALL_COVER_TYPES
      @all_cover_types ||= find(:all)
    end
    def HARDCOVER
      @hardcover ||= self.ALL_COVER_TYPES.detect{|x| x.bookserve_value =~/hard/}
    end
    def IMAGEWRAP
      @imagewrap ||= self.ALL_COVER_TYPES.detect{|x| x.bookserve_value =~/litho/}
    end
    def COVER_TYPES_WITHOUT_SADDLESTITCH
      @cover_types_without_saddlestitch ||= [  self.HARDCOVER, self.IMAGEWRAP ].freeze
    end
  end
end

because the method names are all caps, the regex in


   if statement.tokens.to_s =~ /^def\s+(#{METHODMATCH})(?:(?:\s+|\s*\()(.*)(?:\)\s*$)?)?/m

starts doing some serious backtracking - consuming 100% CPU - I haven't waited around to see how long it would take to finish

I was able to fix this by changing the following regex

    CONSTANTMATCH = /[A-Z]\w*/

to

    CONSTANTMATCH = /[A-Z]\w*\b/

I wasn't able to fork yard (or submit an issue), otherwise I'd submit a proper pull request.  I tried running the specs locally with this change, but I'm getting lots of failures even before I make my change.

Reply all
Reply to author
Forward
0 new messages