class JsRegex::Converter::TypeConverter
Template class implementation.
Constants
- ES2018_HEX_EXPANSION
- ES2018_NONHEX_EXPANSION
- ES2018_XGRAPHEME_EXPANSION
- HEX_EXPANSION
- I_MODE_HEX_EXPANSION
- I_MODE_NONHEX_EXPANSION
- LINEBREAK_EXPANSION
- NONHEX_EXPANSION
Public Class Methods
directly_compatible?(expression, _context = nil)
click to toggle source
# File lib/js_regex/converter/type_converter.rb, line 18 def self.directly_compatible?(expression, _context = nil) case expression.token when :space, :nonspace !expression.ascii_classes? when :digit, :nondigit, :word, :nonword !expression.unicode_classes? end end
Private Instance Methods
character_set()
click to toggle source
# File lib/js_regex/converter/type_converter.rb, line 76 def character_set CharacterSet.of_expression(expression) end
convert_data()
click to toggle source
# File lib/js_regex/converter/type_converter.rb, line 29 def convert_data case subtype when :hex then hex_expansion when :nonhex then nonhex_expansion when :linebreak then LINEBREAK_EXPANSION when :xgrapheme then xgrapheme when :digit, :space, :word return pass_through if self.class.directly_compatible?(expression) set_substitution when :nondigit, :nonspace, :nonword return pass_through if self.class.directly_compatible?(expression) negative_set_substitution else warn_of_unsupported_feature end end
hex_expansion()
click to toggle source
# File lib/js_regex/converter/type_converter.rb, line 46 def hex_expansion if context.es_2018_or_higher? && context.enable_u_option ES2018_HEX_EXPANSION elsif context.case_insensitive_root I_MODE_HEX_EXPANSION else HEX_EXPANSION end end
negative_set_substitution()
click to toggle source
# File lib/js_regex/converter/type_converter.rb, line 66 def negative_set_substitution # ::of_expression returns an inverted set for negative expressions, # so we need to un-invert before wrapping in [^ and ]. Kinda lame. "[^#{character_set.inversion.bmp_part}]" end
nonhex_expansion()
click to toggle source
# File lib/js_regex/converter/type_converter.rb, line 56 def nonhex_expansion if context.es_2018_or_higher? && context.enable_u_option ES2018_NONHEX_EXPANSION elsif context.case_insensitive_root I_MODE_NONHEX_EXPANSION else NONHEX_EXPANSION end end
set_substitution()
click to toggle source
# File lib/js_regex/converter/type_converter.rb, line 72 def set_substitution character_set.bmp_part.to_s(in_brackets: true) end
xgrapheme()
click to toggle source
# File lib/js_regex/converter/type_converter.rb, line 80 def xgrapheme if context.es_2018_or_higher? && context.enable_u_option ES2018_XGRAPHEME_EXPANSION else warn_of_unsupported_feature end end