Module: Deplate::Rx
- Defined in:
- lib/deplate/etc.rb
Class Method Summary collapse
-
.builder(rx_source, rx_opts = nil, depth = 5, sol = true) ⇒ Object
This function builds recursive regular expressions that are used for parsing macros and skeletons.
Class Method Details
.builder(rx_source, rx_opts = nil, depth = 5, sol = true) ⇒ Object
This function builds recursive regular expressions that are used for parsing macros and skeletons. The optional argument defines the depth of nested macros for which the regular expression is being built. The default is 5 which should be sufficient due to the primitivity of the macro language. The string “#” is replaced with the regexp itself.
19 20 21 22 23 24 25 26 27 |
# File 'lib/deplate/etc.rb', line 19 def builder(rx_source, rx_opts=nil, depth=5, sol=true) rxr = rx_source.gsub('\\', '\\\\\\\\') for i in 1..depth rx_source.gsub!(/\{#\}/, rxr) end rx_source.gsub!(/\{#\}/, '[^{}]+?') rx_source = '^' + rx_source if sol return Regexp.new(rx_source, rx_opts) end |