Module: Pione::Lang::DataExprCompiler
- Defined in:
- lib/pione/lang/data-expr.rb
Overview
DataExpr::Compiler is a regexp compiler for data expression.
Constant Summary collapse
- TABLE =
{}
Class Method Summary collapse
-
.compile(pattern) ⇒ Object
Compiles data name into regular expression.
-
.define_matcher(matcher, replace) ⇒ Object
Define a string matcher.
Class Method Details
.compile(pattern) ⇒ Object
Compiles data name into regular expression.
19 20 21 22 23 24 25 |
# File 'lib/pione/lang/data-expr.rb', line 19 def compile(pattern) s = "^#{Regexp.escape(pattern)}$" TABLE.keys.each {|key| s.gsub!(key, TABLE)} s.gsub!(/\\\[(!|\\\^)?(.*)\\\]/){"[#{'^' if $1}#{$2.gsub('\-','-')}]"} s.gsub!(/\\{(.*)\\}/){"(#{$1.split(',').join('|')})"} Regexp.new(s) end |
.define_matcher(matcher, replace) ⇒ Object
Define a string matcher.
8 9 10 |
# File 'lib/pione/lang/data-expr.rb', line 8 def self.define_matcher(matcher, replace) TABLE[Regexp.escape(matcher)] = replace end |