Class: Inversion::Template::CodeTag::TokenPattern
- Inherits:
-
Ripper::TokenPattern
- Object
- Ripper::TokenPattern
- Inversion::Template::CodeTag::TokenPattern
- Extended by:
- Loggability
- Defined in:
- lib/inversion/template/codetag.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Expose the source attribute.
Instance Method Summary collapse
-
#compile(pattern) ⇒ Object
Overloaded to generate a bound regex.
Instance Attribute Details
#source ⇒ Object (readonly)
Expose the source attribute
50 51 52 |
# File 'lib/inversion/template/codetag.rb', line 50 def source @source end |
Instance Method Details
#compile(pattern) ⇒ Object
Overloaded to generate a bound regex.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/inversion/template/codetag.rb', line 54 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. end |