@@ -8,51 +8,6 @@ module Converter
88 # Template class implementation.
99 #
1010 class TypeConverter < JsRegex ::Converter ::Base
11- HEX_EXPANSION = '[0-9A-Fa-f]'
12- NONHEX_EXPANSION = '[^0-9A-Fa-f]'
13- I_MODE_HEX_EXPANSION = '[0-9A-F]'
14- I_MODE_NONHEX_EXPANSION = '[^0-9A-F]'
15- LINEBREAK_EXPANSION = '(?:\r\n|[\n\v\f\r\u0085\u2028\u2029])'
16- ES2018_HEX_EXPANSION = '\p{AHex}'
17- ES2018_NONHEX_EXPANSION = '\P{AHex}'
18- # partially taken from https://unicode.org/reports/tr51/#EBNF_and_Regex
19- ES2018_XGRAPHEME_EXPANSION = <<-'REGEXP' . gsub ( /\s +/ , '' )
20- (?:
21- \r\n
22- |
23- \p{RI}\p{RI}
24- |
25- \p{Emoji}
26- (?:
27- \p{EMod}
28- |
29- \uFE0F\u20E3?
30- |
31- [\u{E0020}-\u{E007E}]+\u{E007F}
32- )?
33- (?:
34- \u200D
35- (?:
36- \p{RI}\p{RI}
37- |
38- \p{Emoji}(?:\p{EMod}|\uFE0F\u20E3?|[\u{E0020}-\u{E007E}]+\u{E007F})?
39- )
40- )*
41- |
42- [\P{M}\P{Lm}](?:\u200d|\p{M}|\p{Lm}|\p{Emoji_Modifier})*
43- )
44- REGEXP
45-
46-
47- def self . directly_compatible? ( expression , _context = nil )
48- case expression . token
49- when :space , :nonspace
50- !expression . ascii_classes?
51- when :digit , :nondigit , :word , :nonword
52- !expression . unicode_classes?
53- end
54- end
55-
5611 private
5712
5813 def convert_data
@@ -62,10 +17,12 @@ def convert_data
6217 when :linebreak then linebreak_expansion
6318 when :xgrapheme then xgrapheme
6419 when :digit , :space , :word
65- return pass_through if self . class . directly_compatible? ( expression )
20+ return pass_through if Utils ::CharTypes . directly_compatible? ( expression )
21+
6622 set_substitution
6723 when :nondigit , :nonspace , :nonword
68- return pass_through if self . class . directly_compatible? ( expression )
24+ return pass_through if Utils ::CharTypes . directly_compatible? ( expression )
25+
6926 negative_set_substitution
7027 else
7128 warn_of_unsupported_feature
@@ -82,6 +39,10 @@ def hex_expansion
8239 end
8340 end
8441
42+ ES2018_HEX_EXPANSION = '\p{AHex}'
43+ I_MODE_HEX_EXPANSION = '[0-9A-F]'
44+ HEX_EXPANSION = '[0-9A-Fa-f]'
45+
8546 def nonhex_expansion
8647 if context . es_2018_or_higher? && context . enable_u_option
8748 ES2018_NONHEX_EXPANSION
@@ -92,10 +53,16 @@ def nonhex_expansion
9253 end
9354 end
9455
56+ NONHEX_EXPANSION = '[^0-9A-Fa-f]'
57+ I_MODE_NONHEX_EXPANSION = '[^0-9A-F]'
58+ ES2018_NONHEX_EXPANSION = '\P{AHex}'
59+
9560 def linebreak_expansion
9661 wrap_in_backrefed_lookahead ( LINEBREAK_EXPANSION )
9762 end
9863
64+ LINEBREAK_EXPANSION = '(?:\r\n|[\n\v\f\r\u0085\u2028\u2029])'
65+
9966 def negative_set_substitution
10067 # ::of_expression returns an inverted set for negative expressions,
10168 # so we need to un-invert before wrapping in [^ and ]. Kinda lame.
@@ -117,6 +84,34 @@ def xgrapheme
11784 warn_of_unsupported_feature
11885 end
11986 end
87+
88+ # partially taken from https://unicode.org/reports/tr51/#EBNF_and_Regex
89+ ES2018_XGRAPHEME_EXPANSION = <<-'REGEXP' . gsub ( /\s +/ , '' )
90+ (?:
91+ \r\n
92+ |
93+ \p{RI}\p{RI}
94+ |
95+ \p{Emoji}
96+ (?:
97+ \p{EMod}
98+ |
99+ \uFE0F\u20E3?
100+ |
101+ [\u{E0020}-\u{E007E}]+\u{E007F}
102+ )?
103+ (?:
104+ \u200D
105+ (?:
106+ \p{RI}\p{RI}
107+ |
108+ \p{Emoji}(?:\p{EMod}|\uFE0F\u20E3?|[\u{E0020}-\u{E007E}]+\u{E007F})?
109+ )
110+ )*
111+ |
112+ [\P{M}\P{Lm}](?:\u200d|\p{M}|\p{Lm}|\p{Emoji_Modifier})*
113+ )
114+ REGEXP
120115 end
121116 end
122117end
0 commit comments