Methods

Inversion::Template::CodeTag::TokenPattern

A subclass of Ripper::TokenPattern that binds matches to the beginning and end of the matched string.

Attributes

source[R]

the token pattern's source string

Protected Instance Methods

compile( pattern ) click to toggle source

Compile the token pattern into a Regexp

# File lib/inversion/template/codetag.rb, line 50
def compile( pattern )
        if m = /[^\w\s$()\[\]{}?*+\.]/.match( pattern )
                raise Ripper::TokenPattern::CompileError,
                        "invalid char in pattern: #{m[0].inspect}"
        end

        buf = '^'
        pattern.scan( /(?:\w+|\$\(|[()\[\]\{\}?*+\.]+)/ ) do |tok|
                case tok
                when /\w/
                        buf << map_token( tok )
                when '$('
                        buf << '('
                when '('
                        buf << '(?:'
                when /[?*\[\])\.]/
                        buf << tok
                else
                        raise ScriptError, "invalid token in pattern: %p" % [ tok ]
                end
        end
        buf << '$'

        Regexp.compile( buf )
rescue RegexpError => err
        raise Ripper::TokenPattern::CompileError, err.message
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.