Inversion::Template::CodeTag::

TokenPattern class

Attributes

source R

Expose the source attribute

Public Instance Methods

compile( pattern )

Overloaded to generate a bound regex.

# File lib/inversion/template/codetag.rb, line 53
def compile( pattern )
        self.log.debug "Compiling token pattern from: %p" % [ pattern ]

        if m = /[^\w\s$()\[\]{}?*+\.]/.match( pattern )
                raise Ripper::TokenPattern::CompileError, "invalid char in pattern: #{m[0].inspect}"
        end

        buf = +'\\A'
        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
        buf.concat( '\z' )

        self.log.debug "  resulting token pattern is: %p" % [ buf ]
        return Regexp.compile( buf )

rescue RegexpError => err
        raise Ripper::TokenPattern::CompileError, err.message
end