js_regex 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/js_regex/converter/backreference_converter.rb +1 -2
- data/lib/js_regex/converter/context.rb +4 -10
- data/lib/js_regex/converter/group_converter.rb +6 -2
- data/lib/js_regex/converter/literal_converter.rb +14 -1
- data/lib/js_regex/converter/meta_converter.rb +1 -1
- data/lib/js_regex/converter/set_converter.rb +26 -2
- data/lib/js_regex/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0d3967319afceb3aaf95fbb0b107f4c2facf675
|
4
|
+
data.tar.gz: 40ade866a8c49d767f9006fc9db8a3a52b43732a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e8c66d97c6564e4c72f75f38e28ac6dfbdeddd03d7906c7ce81b497b064b0ef65b17c6452c8ac1d23393f56dcfef5c4102c48838fe9601d26e6552620483b44
|
7
|
+
data.tar.gz: 35e0bea37b8d7f1142f216c1168ec449dfaf8cb8fd0718edc2198eaa15cd132e0bce99bb20943c43b5ab4ab676f287ec5f3427eae2457f070ed1d48ab5e64846
|
@@ -24,8 +24,7 @@ class JsRegex
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def convert_number_ref
|
27
|
-
|
28
|
-
"\\#{context.new_capturing_group_position(Integer(data[/\d+/]))}"
|
27
|
+
"\\#{context.new_capturing_group_position(Integer(expression.number))}"
|
29
28
|
end
|
30
29
|
|
31
30
|
def convert_number_rel_ref
|
@@ -10,10 +10,10 @@ class JsRegex
|
|
10
10
|
class Context
|
11
11
|
attr_reader :buffered_set_extractions,
|
12
12
|
:buffered_set_members,
|
13
|
+
:case_insensitive_root,
|
13
14
|
:in_atomic_group,
|
14
15
|
:named_group_positions,
|
15
16
|
:negative_base_set,
|
16
|
-
:root_options,
|
17
17
|
:warnings
|
18
18
|
|
19
19
|
def initialize(ruby_regex)
|
@@ -22,14 +22,8 @@ class JsRegex
|
|
22
22
|
self.named_group_positions = {}
|
23
23
|
self.warnings = []
|
24
24
|
|
25
|
-
self.
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
# option context
|
30
|
-
|
31
|
-
def multiline?
|
32
|
-
root_options.fetch(:m)
|
25
|
+
self.case_insensitive_root =
|
26
|
+
!(ruby_regex.options & Regexp::IGNORECASE).equal?(0)
|
33
27
|
end
|
34
28
|
|
35
29
|
# set context
|
@@ -96,10 +90,10 @@ class JsRegex
|
|
96
90
|
|
97
91
|
attr_writer :buffered_set_extractions,
|
98
92
|
:buffered_set_members,
|
93
|
+
:case_insensitive_root,
|
99
94
|
:in_atomic_group,
|
100
95
|
:named_group_positions,
|
101
96
|
:negative_base_set,
|
102
|
-
:root_options,
|
103
97
|
:warnings
|
104
98
|
end
|
105
99
|
end
|
@@ -41,8 +41,12 @@ class JsRegex
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def build_options_group
|
44
|
-
|
45
|
-
|
44
|
+
unless (encoding_options = data.scan(/[adu]/)).empty?
|
45
|
+
warn_of_unsupported_feature("encoding options #{encoding_options}")
|
46
|
+
end
|
47
|
+
# TODO: replace this check in Regexp::Parser v1
|
48
|
+
switch_only = !data.include?(':')
|
49
|
+
switch_only ? drop_without_warning : build_group(head: '(')
|
46
50
|
end
|
47
51
|
|
48
52
|
def build_passive_group
|
@@ -43,7 +43,20 @@ class JsRegex
|
|
43
43
|
private
|
44
44
|
|
45
45
|
def convert_data
|
46
|
-
self.class.convert_data(data)
|
46
|
+
result = self.class.convert_data(data)
|
47
|
+
if context.case_insensitive_root && !expression.case_insensitive?
|
48
|
+
warn_of_unsupported_feature('nested case-sensitive literal')
|
49
|
+
elsif !context.case_insensitive_root && expression.case_insensitive?
|
50
|
+
return handle_locally_case_insensitive_literal(result)
|
51
|
+
end
|
52
|
+
result
|
53
|
+
end
|
54
|
+
|
55
|
+
HAS_CASE_PATTERN = /[\p{lower}\p{upper}]/
|
56
|
+
|
57
|
+
def handle_locally_case_insensitive_literal(literal)
|
58
|
+
return literal unless literal =~ HAS_CASE_PATTERN
|
59
|
+
"[#{literal}#{literal.swapcase}]"
|
47
60
|
end
|
48
61
|
end
|
49
62
|
end
|
@@ -52,8 +52,7 @@ class JsRegex
|
|
52
52
|
when PROPERTY_PATTERN
|
53
53
|
handle_property($1, $2, $3)
|
54
54
|
else
|
55
|
-
|
56
|
-
buffer_set_member(literal_conversion)
|
55
|
+
handle_literal(utf8_data)
|
57
56
|
end
|
58
57
|
end
|
59
58
|
|
@@ -85,6 +84,31 @@ class JsRegex
|
|
85
84
|
end
|
86
85
|
end
|
87
86
|
|
87
|
+
def handle_literal(utf8_data)
|
88
|
+
conversion = LiteralConverter.convert_data(utf8_data)
|
89
|
+
if context.case_insensitive_root && !expression.case_insensitive?
|
90
|
+
warn_of_unsupported_feature('nested case-sensitive set member')
|
91
|
+
elsif !context.case_insensitive_root && expression.case_insensitive?
|
92
|
+
return handle_locally_case_insensitive_literal(conversion)
|
93
|
+
end
|
94
|
+
buffer_set_member(conversion)
|
95
|
+
end
|
96
|
+
|
97
|
+
DESCENDING_CASE_RANGE_PATTERN = /\p{upper}-\p{lower}/
|
98
|
+
|
99
|
+
def handle_locally_case_insensitive_literal(literal)
|
100
|
+
buffer_set_member(
|
101
|
+
if literal =~ DESCENDING_CASE_RANGE_PATTERN
|
102
|
+
warn_of_unsupported_feature(
|
103
|
+
'nested case-insensitive range going from upper to lower case'
|
104
|
+
)
|
105
|
+
literal
|
106
|
+
else
|
107
|
+
[literal, literal.swapcase].uniq
|
108
|
+
end
|
109
|
+
)
|
110
|
+
end
|
111
|
+
|
88
112
|
def standardize_property_name(name)
|
89
113
|
Regexp::Parser.parse("\\p{#{name}}").expressions.first.token
|
90
114
|
end
|
data/lib/js_regex/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: js_regex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janosch Müller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: regexp_parser
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.4.
|
19
|
+
version: 0.4.7
|
20
20
|
- - "<="
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 0.5.0
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.4.
|
29
|
+
version: 0.4.7
|
30
30
|
- - "<="
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 0.5.0
|