A subclass of Ripper::TokenPattern that binds matches to the beginning and end of the matched string.
the token pattern's source string
Compile the token pattern into a Regexp
# File lib/inversion/template/codetag.rb, line 49
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