class Mustermann::AST::Compiler
Regexp compilation logic. @!visibility private
Public Class Methods
compile(ast, **options)
click to toggle source
Compiles an AST
to a regular expression. @param [Mustermann::AST::Node] ast the tree @return [Regexp] corresponding regular expression.
@!visibility private
# File lib/mustermann/ast/compiler.rb, line 142 def self.compile(ast, **options) new.compile(ast, **options) end
Public Instance Methods
compile(ast, except: nil, **options)
click to toggle source
Compiles an AST
to a regular expression. @param [Mustermann::AST::Node] ast the tree @return [Regexp] corresponding regular expression.
@!visibility private
# File lib/mustermann/ast/compiler.rb, line 151 def compile(ast, except: nil, **options) except &&= "(?!#{translate(except, no_captures: true, **options)}\\Z)" Regexp.new("#{except}#{translate(ast, **options)}") end
encoded(char, uri_decode: true, space_matches_plus: true, **options)
click to toggle source
@return [String] Regular
expression for matching the given character in all representations @!visibility private
# File lib/mustermann/ast/compiler.rb, line 126 def encoded(char, uri_decode: true, space_matches_plus: true, **options) return Regexp.escape(char) unless uri_decode encoded = escape(char, escape: /./) list = [escape(char), encoded.downcase, encoded.upcase].uniq.map { |c| Regexp.escape(c) } if char == " " list << encoded('+') if space_matches_plus list << " " end "(?:%s)" % list.join("|") end