js_regex 3.13.0 → 3.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/js_regex/conversion.rb +2 -1
- data/lib/js_regex/converter/anchor_converter.rb +4 -2
- data/lib/js_regex/converter/assertion_converter.rb +2 -0
- data/lib/js_regex/converter/backreference_converter.rb +33 -12
- data/lib/js_regex/converter/base.rb +38 -27
- data/lib/js_regex/converter/conditional_converter.rb +12 -4
- data/lib/js_regex/converter/context.rb +54 -8
- data/lib/js_regex/converter/escape_converter.rb +6 -30
- data/lib/js_regex/converter/freespace_converter.rb +2 -0
- data/lib/js_regex/converter/group_converter.rb +18 -16
- data/lib/js_regex/converter/keep_converter.rb +2 -0
- data/lib/js_regex/converter/literal_converter.rb +16 -46
- data/lib/js_regex/converter/meta_converter.rb +15 -13
- data/lib/js_regex/converter/property_converter.rb +4 -20
- data/lib/js_regex/converter/set_converter.rb +10 -37
- data/lib/js_regex/converter/subexpression_converter.rb +2 -0
- data/lib/js_regex/converter/type_converter.rb +45 -39
- data/lib/js_regex/converter/unsupported_token_converter.rb +2 -0
- data/lib/js_regex/converter.rb +2 -0
- data/lib/js_regex/error.rb +2 -0
- data/lib/js_regex/node/checks.rb +70 -0
- data/lib/js_regex/node/conditional_parts.rb +17 -0
- data/lib/js_regex/node/quantifier.rb +134 -0
- data/lib/js_regex/node/stringification.rb +14 -0
- data/lib/js_regex/node/transformations.rb +56 -0
- data/lib/js_regex/node/traversal.rb +24 -0
- data/lib/js_regex/node.rb +49 -40
- data/lib/js_regex/second_pass/alternate_conditional_permutations.rb +89 -0
- data/lib/js_regex/second_pass/delimit_backrefs.rb +31 -0
- data/lib/js_regex/second_pass/expand_bounded_capture_loops.rb +79 -0
- data/lib/js_regex/second_pass/expand_constant_capture_loops.rb +287 -0
- data/lib/js_regex/second_pass/expand_nullable_captures.rb +327 -0
- data/lib/js_regex/second_pass/handle_non_participating_backrefs.rb +69 -0
- data/lib/js_regex/second_pass/preserve_repeated_captures.rb +370 -0
- data/lib/js_regex/second_pass/resolve_capture_references.rb +116 -0
- data/lib/js_regex/second_pass/substitute_root_level_keep_mark.rb +26 -0
- data/lib/js_regex/second_pass.rb +364 -107
- data/lib/js_regex/target.rb +2 -0
- data/lib/js_regex/utils/captures.rb +46 -0
- data/lib/js_regex/utils/char_sets.rb +34 -0
- data/lib/js_regex/utils/char_types.rb +18 -0
- data/lib/js_regex/utils/escapes.rb +32 -0
- data/lib/js_regex/utils/literals.rb +53 -0
- data/lib/js_regex/utils/properties.rb +19 -0
- data/lib/js_regex/{converter → utils}/property_map.csv +31 -5
- data/lib/js_regex/utils.rb +8 -0
- data/lib/js_regex/version.rb +3 -1
- data/lib/js_regex.rb +5 -3
- metadata +29 -10
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../node'
|
|
4
|
+
require 'character_set'
|
|
5
|
+
|
|
6
|
+
class JsRegex
|
|
7
|
+
module Utils
|
|
8
|
+
module Literals
|
|
9
|
+
ASTRAL_PLANE_CODEPOINT_PATTERN = /[\u{10000}-\u{10FFFF}]/.freeze
|
|
10
|
+
|
|
11
|
+
class << self
|
|
12
|
+
def convert_data(data, context)
|
|
13
|
+
if !context.u? && data.match?(ASTRAL_PLANE_CODEPOINT_PATTERN)
|
|
14
|
+
if context.enable_u_option
|
|
15
|
+
escape_incompatible_bmp_literals(data)
|
|
16
|
+
else
|
|
17
|
+
convert_astral_data(data)
|
|
18
|
+
end
|
|
19
|
+
else
|
|
20
|
+
escape_incompatible_bmp_literals(data)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def escape_incompatible_bmp_literals(data)
|
|
25
|
+
data.gsub(LITERAL_REQUIRING_ESCAPE_PATTERN, ESCAPES)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
LITERAL_REQUIRING_ESCAPE_PATTERN = /[\/\f\n\r\t\v\u2028\u2029]/.freeze
|
|
31
|
+
|
|
32
|
+
ESCAPES = Hash.new { |h, k| raise KeyError, "#{h}[#{k.inspect}]" }
|
|
33
|
+
.merge("\f\n\r\t\v".chars.to_h { |c| [c, Regexp.escape(c)] })
|
|
34
|
+
.merge('/' => '\\/')
|
|
35
|
+
.merge("\u2028" => '\\u2028', "\u2029" => '\\u2029')
|
|
36
|
+
|
|
37
|
+
def convert_astral_data(data)
|
|
38
|
+
data.each_char.each_with_object(JsRegex::Node.new) do |char, node|
|
|
39
|
+
if char.ord > 0xFFFF
|
|
40
|
+
node << surrogate_substitution_for(char)
|
|
41
|
+
else
|
|
42
|
+
node << escape_incompatible_bmp_literals(char)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def surrogate_substitution_for(char)
|
|
48
|
+
CharacterSet::Writer.write_surrogate_ranges([], [char.codepoints])
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class JsRegex
|
|
4
|
+
module Utils
|
|
5
|
+
module Properties
|
|
6
|
+
class << self
|
|
7
|
+
def name_in_js(name_in_ruby)
|
|
8
|
+
map[name_in_ruby.to_s.delete('_')]
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def map
|
|
14
|
+
@map ||= File.read("#{__dir__}/property_map.csv").scan(/(.+),(.+)/).to_h
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
ascii,ASCII
|
|
3
3
|
asciihexdigit,ASCII_Hex_Digit
|
|
4
4
|
adlam,Script=Adlam
|
|
5
|
+
ahom,Script=Ahom
|
|
5
6
|
anatolianhieroglyphs,Script=Anatolian_Hieroglyphs
|
|
6
7
|
armenian,Script=Armenian
|
|
7
8
|
avestan,Script=Avestan
|
|
9
|
+
balinese,Script=Balinese
|
|
8
10
|
bamum,Script=Bamum
|
|
9
11
|
bassavah,Script=Bassa_Vah
|
|
10
12
|
batak,Script=Batak
|
|
@@ -12,21 +14,28 @@ bengali,Script=Bengali
|
|
|
12
14
|
bhaiksuki,Script=Bhaiksuki
|
|
13
15
|
bidicontrol,Bidi_Control
|
|
14
16
|
bopomofo,Script=Bopomofo
|
|
17
|
+
brahmi,Script=Brahmi
|
|
15
18
|
braille,Script=Braille
|
|
16
19
|
buginese,Script=Buginese
|
|
17
20
|
buhid,Script=Buhid
|
|
21
|
+
canadianaboriginal,Script=Canadian_Aboriginal
|
|
18
22
|
carian,Script=Carian
|
|
19
23
|
caucasianalbanian,Script=Caucasian_Albanian
|
|
20
24
|
chakma,Script=Chakma
|
|
21
25
|
cham,Script=Cham
|
|
22
26
|
cherokee,Script=Cherokee
|
|
23
27
|
chorasmian,Script=Chorasmian
|
|
28
|
+
closepunctuation,Close_Punctuation
|
|
24
29
|
connectorpunctuation,Connector_Punctuation
|
|
25
30
|
control,Control
|
|
26
31
|
coptic,Script=Coptic
|
|
27
32
|
cuneiform,Script=Cuneiform
|
|
28
33
|
cypriot,Script=Cypriot
|
|
34
|
+
cyprominoan,Script=Cypro_Minoan
|
|
29
35
|
cyrillic,Script=Cyrillic
|
|
36
|
+
dash,Dash
|
|
37
|
+
dashpunctuation,Dash_Punctuation
|
|
38
|
+
defaultignorablecodepoint,Default_Ignorable_Code_Point
|
|
30
39
|
deprecated,Deprecated
|
|
31
40
|
deseret,Script=Deseret
|
|
32
41
|
devanagari,Script=Devanagari
|
|
@@ -38,9 +47,13 @@ elbasan,Script=Elbasan
|
|
|
38
47
|
elymaic,Script=Elymaic
|
|
39
48
|
emojicomponent,Emoji_Component
|
|
40
49
|
emojimodifier,Emoji_Modifier
|
|
50
|
+
emojimodifierbase,Emoji_Modifier_Base
|
|
41
51
|
enclosingmark,Enclosing_Mark
|
|
52
|
+
ethiopic,Script=Ethiopic
|
|
42
53
|
finalpunctuation,Final_Punctuation
|
|
54
|
+
format,Format
|
|
43
55
|
georgian,Script=Georgian
|
|
56
|
+
glagolitic,Script=Glagolitic
|
|
44
57
|
gothic,Script=Gothic
|
|
45
58
|
grantha,Script=Grantha
|
|
46
59
|
greek,Script=Greek
|
|
@@ -53,6 +66,7 @@ hanunoo,Script=Hanunoo
|
|
|
53
66
|
hatran,Script=Hatran
|
|
54
67
|
hebrew,Script=Hebrew
|
|
55
68
|
hexdigit,Hex_Digit
|
|
69
|
+
hiragana,Script=Hiragana
|
|
56
70
|
idsbinaryoperator,IDS_Binary_Operator
|
|
57
71
|
idstrinaryoperator,IDS_Trinary_Operator
|
|
58
72
|
imperialaramaic,Script=Imperial_Aramaic
|
|
@@ -61,6 +75,9 @@ inscriptionalpahlavi,Script=Inscriptional_Pahlavi
|
|
|
61
75
|
inscriptionalparthian,Script=Inscriptional_Parthian
|
|
62
76
|
javanese,Script=Javanese
|
|
63
77
|
joincontrol,Join_Control
|
|
78
|
+
kaithi,Script=Kaithi
|
|
79
|
+
katakana,Script=Katakana
|
|
80
|
+
kawi,Script=Kawi
|
|
64
81
|
kayahli,Script=Kayah_Li
|
|
65
82
|
kharoshthi,Script=Kharoshthi
|
|
66
83
|
khitansmallscript,Script=Khitan_Small_Script
|
|
@@ -69,7 +86,6 @@ khojki,Script=Khojki
|
|
|
69
86
|
khudawadi,Script=Khudawadi
|
|
70
87
|
lao,Script=Lao
|
|
71
88
|
lepcha,Script=Lepcha
|
|
72
|
-
letternumber,Letter_Number
|
|
73
89
|
limbu,Script=Limbu
|
|
74
90
|
lineseparator,Line_Separator
|
|
75
91
|
lineara,Script=Linear_A
|
|
@@ -85,8 +101,6 @@ mandaic,Script=Mandaic
|
|
|
85
101
|
manichaean,Script=Manichaean
|
|
86
102
|
marchen,Script=Marchen
|
|
87
103
|
masaramgondi,Script=Masaram_Gondi
|
|
88
|
-
math,Math
|
|
89
|
-
mathsymbol,Math_Symbol
|
|
90
104
|
medefaidrin,Script=Medefaidrin
|
|
91
105
|
meeteimayek,Script=Meetei_Mayek
|
|
92
106
|
mendekikakui,Script=Mende_Kikakui
|
|
@@ -94,10 +108,13 @@ meroiticcursive,Script=Meroitic_Cursive
|
|
|
94
108
|
meroitichieroglyphs,Script=Meroitic_Hieroglyphs
|
|
95
109
|
miao,Script=Miao
|
|
96
110
|
modi,Script=Modi
|
|
111
|
+
modifiersymbol,Modifier_Symbol
|
|
112
|
+
mongolian,Script=Mongolian
|
|
97
113
|
mro,Script=Mro
|
|
98
114
|
multani,Script=Multani
|
|
99
115
|
myanmar,Script=Myanmar
|
|
100
116
|
nabataean,Script=Nabataean
|
|
117
|
+
nagmundari,Script=Nag_Mundari
|
|
101
118
|
nandinagari,Script=Nandinagari
|
|
102
119
|
newtailue,Script=New_Tai_Lue
|
|
103
120
|
newa,Script=Newa
|
|
@@ -115,6 +132,8 @@ oldpersian,Script=Old_Persian
|
|
|
115
132
|
oldsogdian,Script=Old_Sogdian
|
|
116
133
|
oldsoutharabian,Script=Old_South_Arabian
|
|
117
134
|
oldturkic,Script=Old_Turkic
|
|
135
|
+
olduyghur,Script=Old_Uyghur
|
|
136
|
+
openpunctuation,Open_Punctuation
|
|
118
137
|
oriya,Script=Oriya
|
|
119
138
|
osage,Script=Osage
|
|
120
139
|
osmanya,Script=Osmanya
|
|
@@ -136,12 +155,13 @@ rejang,Script=Rejang
|
|
|
136
155
|
runic,Script=Runic
|
|
137
156
|
samaritan,Script=Samaritan
|
|
138
157
|
saurashtra,Script=Saurashtra
|
|
158
|
+
sentenceterminal,Sentence_Terminal
|
|
139
159
|
separator,Separator
|
|
140
|
-
sharada,Script=Sharada
|
|
141
160
|
shavian,Script=Shavian
|
|
142
161
|
siddham,Script=Siddham
|
|
143
162
|
signwriting,Script=SignWriting
|
|
144
163
|
sinhala,Script=Sinhala
|
|
164
|
+
softdotted,Soft_Dotted
|
|
145
165
|
sogdian,Script=Sogdian
|
|
146
166
|
sorasompeng,Script=Sora_Sompeng
|
|
147
167
|
soyombo,Script=Soyombo
|
|
@@ -149,20 +169,26 @@ spaceseparator,Space_Separator
|
|
|
149
169
|
sundanese,Script=Sundanese
|
|
150
170
|
sylotinagri,Script=Syloti_Nagri
|
|
151
171
|
syriac,Script=Syriac
|
|
172
|
+
tagalog,Script=Tagalog
|
|
152
173
|
tagbanwa,Script=Tagbanwa
|
|
153
174
|
taile,Script=Tai_Le
|
|
154
175
|
taitham,Script=Tai_Tham
|
|
155
176
|
taiviet,Script=Tai_Viet
|
|
177
|
+
takri,Script=Takri
|
|
156
178
|
tamil,Script=Tamil
|
|
157
|
-
|
|
179
|
+
tangsa,Script=Tangsa
|
|
180
|
+
terminalpunctuation,Terminal_Punctuation
|
|
158
181
|
thaana,Script=Thaana
|
|
159
182
|
thai,Script=Thai
|
|
160
183
|
tibetan,Script=Tibetan
|
|
161
184
|
tifinagh,Script=Tifinagh
|
|
162
185
|
tirhuta,Script=Tirhuta
|
|
163
186
|
titlecaseletter,Titlecase_Letter
|
|
187
|
+
toto,Script=Toto
|
|
164
188
|
ugaritic,Script=Ugaritic
|
|
165
189
|
vai,Script=Vai
|
|
190
|
+
variationselector,Variation_Selector
|
|
191
|
+
vithkuqi,Script=Vithkuqi
|
|
166
192
|
wancho,Script=Wancho
|
|
167
193
|
warangciti,Script=Warang_Citi
|
|
168
194
|
whitespace,White_Space
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Utilities for analyzing Regexp::Expression::* instances emitted by regexp_parser
|
|
2
|
+
|
|
3
|
+
require_relative 'utils/captures'
|
|
4
|
+
require_relative 'utils/char_sets'
|
|
5
|
+
require_relative 'utils/char_types'
|
|
6
|
+
require_relative 'utils/escapes'
|
|
7
|
+
require_relative 'utils/literals'
|
|
8
|
+
require_relative 'utils/properties'
|
data/lib/js_regex/version.rb
CHANGED
data/lib/js_regex.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# JsRegex converts ::Regexp instances to JavaScript.
|
|
2
4
|
#
|
|
3
5
|
# Usage:
|
|
@@ -7,9 +9,9 @@
|
|
|
7
9
|
# js_regex.to_s # for direct injection into JavaScript
|
|
8
10
|
#
|
|
9
11
|
class JsRegex
|
|
10
|
-
require_relative
|
|
11
|
-
require_relative
|
|
12
|
-
require_relative
|
|
12
|
+
require_relative 'js_regex/conversion'
|
|
13
|
+
require_relative 'js_regex/error'
|
|
14
|
+
require_relative 'js_regex/version'
|
|
13
15
|
require 'json'
|
|
14
16
|
|
|
15
17
|
attr_reader :source, :options, :warnings, :target
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: js_regex
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.15.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Janosch Müller
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: character_set
|
|
@@ -30,14 +29,14 @@ dependencies:
|
|
|
30
29
|
requirements:
|
|
31
30
|
- - "~>"
|
|
32
31
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '2.
|
|
32
|
+
version: '2.11'
|
|
34
33
|
type: :runtime
|
|
35
34
|
prerelease: false
|
|
36
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
36
|
requirements:
|
|
38
37
|
- - "~>"
|
|
39
38
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '2.
|
|
39
|
+
version: '2.11'
|
|
41
40
|
- !ruby/object:Gem::Dependency
|
|
42
41
|
name: regexp_property_values
|
|
43
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -76,21 +75,42 @@ files:
|
|
|
76
75
|
- lib/js_regex/converter/literal_converter.rb
|
|
77
76
|
- lib/js_regex/converter/meta_converter.rb
|
|
78
77
|
- lib/js_regex/converter/property_converter.rb
|
|
79
|
-
- lib/js_regex/converter/property_map.csv
|
|
80
78
|
- lib/js_regex/converter/set_converter.rb
|
|
81
79
|
- lib/js_regex/converter/subexpression_converter.rb
|
|
82
80
|
- lib/js_regex/converter/type_converter.rb
|
|
83
81
|
- lib/js_regex/converter/unsupported_token_converter.rb
|
|
84
82
|
- lib/js_regex/error.rb
|
|
85
83
|
- lib/js_regex/node.rb
|
|
84
|
+
- lib/js_regex/node/checks.rb
|
|
85
|
+
- lib/js_regex/node/conditional_parts.rb
|
|
86
|
+
- lib/js_regex/node/quantifier.rb
|
|
87
|
+
- lib/js_regex/node/stringification.rb
|
|
88
|
+
- lib/js_regex/node/transformations.rb
|
|
89
|
+
- lib/js_regex/node/traversal.rb
|
|
86
90
|
- lib/js_regex/second_pass.rb
|
|
91
|
+
- lib/js_regex/second_pass/alternate_conditional_permutations.rb
|
|
92
|
+
- lib/js_regex/second_pass/delimit_backrefs.rb
|
|
93
|
+
- lib/js_regex/second_pass/expand_bounded_capture_loops.rb
|
|
94
|
+
- lib/js_regex/second_pass/expand_constant_capture_loops.rb
|
|
95
|
+
- lib/js_regex/second_pass/expand_nullable_captures.rb
|
|
96
|
+
- lib/js_regex/second_pass/handle_non_participating_backrefs.rb
|
|
97
|
+
- lib/js_regex/second_pass/preserve_repeated_captures.rb
|
|
98
|
+
- lib/js_regex/second_pass/resolve_capture_references.rb
|
|
99
|
+
- lib/js_regex/second_pass/substitute_root_level_keep_mark.rb
|
|
87
100
|
- lib/js_regex/target.rb
|
|
101
|
+
- lib/js_regex/utils.rb
|
|
102
|
+
- lib/js_regex/utils/captures.rb
|
|
103
|
+
- lib/js_regex/utils/char_sets.rb
|
|
104
|
+
- lib/js_regex/utils/char_types.rb
|
|
105
|
+
- lib/js_regex/utils/escapes.rb
|
|
106
|
+
- lib/js_regex/utils/literals.rb
|
|
107
|
+
- lib/js_regex/utils/properties.rb
|
|
108
|
+
- lib/js_regex/utils/property_map.csv
|
|
88
109
|
- lib/js_regex/version.rb
|
|
89
110
|
homepage: https://github.com/jaynetics/js_regex
|
|
90
111
|
licenses:
|
|
91
112
|
- MIT
|
|
92
113
|
metadata: {}
|
|
93
|
-
post_install_message:
|
|
94
114
|
rdoc_options: []
|
|
95
115
|
require_paths:
|
|
96
116
|
- lib
|
|
@@ -98,15 +118,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
98
118
|
requirements:
|
|
99
119
|
- - ">="
|
|
100
120
|
- !ruby/object:Gem::Version
|
|
101
|
-
version: 2.
|
|
121
|
+
version: 2.6.0
|
|
102
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
123
|
requirements:
|
|
104
124
|
- - ">="
|
|
105
125
|
- !ruby/object:Gem::Version
|
|
106
126
|
version: '0'
|
|
107
127
|
requirements: []
|
|
108
|
-
rubygems_version:
|
|
109
|
-
signing_key:
|
|
128
|
+
rubygems_version: 4.0.23
|
|
110
129
|
specification_version: 4
|
|
111
130
|
summary: Converts Ruby regexes to JavaScript regexes.
|
|
112
131
|
test_files: []
|