Flowdock
method

compile

Importance_0
Ruby latest stable (v1_9_3_392) - 0 notes - Class: TokenPattern
compile(pattern) private

No documentation

This method has no description. You can help the Ruby community by adding new notes.

Hide source
# File ext/ripper/lib/ripper/lexer.rb, line 119
    def compile(pattern)
      if m = /[^\w\s$()\[\]{}?*+\.]/.match(pattern)
        raise CompileError, "invalid char in pattern: #{m[0].inspect}"
      end
      buf = ''
      pattern.scan(/(?:\w+|\$\(|[()\[\]\{\}?*+\.]+)/) do |tok|
        case tok
        when /\w/
          buf.concat map_token(tok)
        when '$('
          buf.concat '('
        when '('
          buf.concat '(?:'
        when /[?*\[\])\.]/
          buf.concat tok
        else
          raise 'must not happen'
        end
      end
      Regexp.compile(buf)
    rescue RegexpError => err
      raise CompileError, err.message
    end
Register or log in to add new notes.