module Pione::Lang::DataExprCompiler
DataExpr::Compiler is a regexp compiler for data expression.
Constants
- TABLE
Public Class Methods
compile(pattern)
click to toggle source
Compiles data name into regular expression.
# 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)
click to toggle source
Define a string matcher.
# File lib/pione/lang/data-expr.rb, line 8 def self.define_matcher(matcher, replace) TABLE[Regexp.escape(matcher)] = replace end
Private Instance Methods
compile(pattern)
click to toggle source
Compiles data name into regular expression.
# 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