js_regex 1.1.0 → 1.2.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/converter/base.rb +3 -2
- data/lib/js_regex/converter/conditional_converter.rb +1 -1
- data/lib/js_regex/converter/context.rb +10 -3
- data/lib/js_regex/converter/escape_converter.rb +24 -20
- data/lib/js_regex/converter/quantifier_converter.rb +1 -9
- data/lib/js_regex/converter/set_converter.rb +6 -12
- data/lib/js_regex/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1383333a8a9683ea2e63c0871c90006fcd9c6be3
|
4
|
+
data.tar.gz: 3da33cae25a5f9fa0012f94f36b21031577b8922
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25707387666a8aaef307676e48aa75098e875e5808e58e3dbe00e8bd3b43caaed4f1ce37260ac1a8f6a39e32e02cfde09dc6d4d418329048e457f900f520ddaf
|
7
|
+
data.tar.gz: ddf9bb15777c6bef8e620840160296dedd05d160bfec8e1f1ea457936e5632448628fc3e5c2197361e319a464481dfe88fcf877206cf583417b398d549095892
|
@@ -31,8 +31,9 @@ class JsRegex
|
|
31
31
|
alias pass_through data
|
32
32
|
|
33
33
|
def warn_of_unsupported_feature(description = nil)
|
34
|
-
description ||= "#{subtype} #{token_class}
|
35
|
-
|
34
|
+
description ||= "#{subtype} #{token_class}".tr('_', ' ')
|
35
|
+
full_description = "#{description} '#{data}'"
|
36
|
+
target.warnings << "Dropped unsupported #{full_description} "\
|
36
37
|
"at index #{start_index}...#{end_index}"
|
37
38
|
''
|
38
39
|
end
|
@@ -8,8 +8,6 @@ class JsRegex
|
|
8
8
|
# The Converters themselves are stateless.
|
9
9
|
#
|
10
10
|
class Context
|
11
|
-
attr_accessor :previous_quantifier_end # , :previous_quantifier_type
|
12
|
-
|
13
11
|
attr_reader :buffered_set_extractions,
|
14
12
|
:buffered_set_members,
|
15
13
|
:captured_group_count,
|
@@ -30,6 +28,12 @@ class JsRegex
|
|
30
28
|
!negative_lookbehind
|
31
29
|
end
|
32
30
|
|
31
|
+
def stacked_quantifier?(quantifier_start_index, quantifier_end_index)
|
32
|
+
is_stacked = last_quantifier_end_index.equal?(quantifier_start_index)
|
33
|
+
self.last_quantifier_end_index = quantifier_end_index
|
34
|
+
is_stacked
|
35
|
+
end
|
36
|
+
|
33
37
|
# set context
|
34
38
|
|
35
39
|
def open_set
|
@@ -113,7 +117,10 @@ class JsRegex
|
|
113
117
|
|
114
118
|
private
|
115
119
|
|
116
|
-
attr_accessor :group_level,
|
120
|
+
attr_accessor :group_level,
|
121
|
+
:last_quantifier_end_index,
|
122
|
+
:negative_set_levels,
|
123
|
+
:set_level
|
117
124
|
|
118
125
|
attr_writer :buffered_set_extractions,
|
119
126
|
:buffered_set_members,
|
@@ -11,30 +11,34 @@ class JsRegex
|
|
11
11
|
class EscapeConverter < JsRegex::Converter::Base
|
12
12
|
private
|
13
13
|
|
14
|
+
ESCAPES_SHARED_BY_RUBY_AND_JS = [
|
15
|
+
:backslash,
|
16
|
+
:bol,
|
17
|
+
:carriage,
|
18
|
+
:codepoint,
|
19
|
+
:dot,
|
20
|
+
:eol,
|
21
|
+
:form_feed,
|
22
|
+
:hex,
|
23
|
+
:interval_close,
|
24
|
+
:interval_open,
|
25
|
+
:newline,
|
26
|
+
:octal,
|
27
|
+
:one_or_more,
|
28
|
+
:set_close,
|
29
|
+
:set_open,
|
30
|
+
:tab,
|
31
|
+
:vertical_tab,
|
32
|
+
:zero_or_more,
|
33
|
+
:zero_or_one
|
34
|
+
].freeze
|
35
|
+
|
14
36
|
def convert_data
|
15
37
|
case subtype
|
16
|
-
when :backslash,
|
17
|
-
:bol,
|
18
|
-
:carriage,
|
19
|
-
:codepoint,
|
20
|
-
:dot,
|
21
|
-
:eol,
|
22
|
-
:form_feed,
|
23
|
-
:hex,
|
24
|
-
:interval_close,
|
25
|
-
:interval_open,
|
26
|
-
:newline,
|
27
|
-
:octal,
|
28
|
-
:one_or_more,
|
29
|
-
:set_close,
|
30
|
-
:set_open,
|
31
|
-
:tab,
|
32
|
-
:vertical_tab,
|
33
|
-
:zero_or_more,
|
34
|
-
:zero_or_one
|
35
|
-
pass_through
|
36
38
|
when :literal
|
37
39
|
LiteralConverter.convert_data(data)
|
40
|
+
when *ESCAPES_SHARED_BY_RUBY_AND_JS
|
41
|
+
pass_through
|
38
42
|
else
|
39
43
|
# Bell, Escape, HexWide, Control, Meta, MetaControl, ...
|
40
44
|
warn_of_unsupported_feature
|
@@ -11,11 +11,9 @@ class JsRegex
|
|
11
11
|
private
|
12
12
|
|
13
13
|
def convert_data
|
14
|
-
if
|
14
|
+
if context.stacked_quantifier?(start_index, end_index)
|
15
15
|
warn_of_unsupported_feature('adjacent quantifiers')
|
16
16
|
else
|
17
|
-
# context.previous_quantifier_type = subtype
|
18
|
-
context.previous_quantifier_end = end_index
|
19
17
|
convert_quantifier
|
20
18
|
end
|
21
19
|
end
|
@@ -28,12 +26,6 @@ class JsRegex
|
|
28
26
|
pass_through
|
29
27
|
end
|
30
28
|
end
|
31
|
-
|
32
|
-
def multiplicative_interval?
|
33
|
-
# subtype == :interval &&
|
34
|
-
# context.previous_quantifier_type == :interval &&
|
35
|
-
context.previous_quantifier_end.equal?(start_index)
|
36
|
-
end
|
37
29
|
end
|
38
30
|
end
|
39
31
|
end
|
@@ -25,18 +25,13 @@ class JsRegex
|
|
25
25
|
when :open then convert_open_subtype
|
26
26
|
when :negate then convert_negate_subtype
|
27
27
|
when :close then convert_close_subtype
|
28
|
-
when :member, :range, :escape
|
28
|
+
when :member, :member_hex, :range, :range_hex, :escape
|
29
|
+
convert_member_subtype
|
29
30
|
when /\Aclass_/ then convert_class_subtype
|
30
31
|
when /\Atype_/ then convert_type_subtype
|
31
32
|
when :backspace then convert_backspace_subtype
|
32
|
-
when :intersection
|
33
|
-
|
34
|
-
else
|
35
|
-
# Note that, within sets, Regexp::Scanner returns
|
36
|
-
# - positive property tokens in the \p{-style with class :set
|
37
|
-
# - negative property tokens in the \P{-style with class :set
|
38
|
-
# - negative property tokens in the \p{^-style with class :nonproperty
|
39
|
-
try_replacing_potential_property_subtype
|
33
|
+
when :intersection then warn_of_unsupported_feature('set intersection')
|
34
|
+
else try_replacing_potential_property_subtype
|
40
35
|
end
|
41
36
|
end
|
42
37
|
|
@@ -80,11 +75,10 @@ class JsRegex
|
|
80
75
|
end
|
81
76
|
|
82
77
|
def try_replacing_property(name, negated)
|
83
|
-
replacement = PropertyConverter.property_replacement(name, negated)
|
84
|
-
if replacement
|
78
|
+
if (replacement = PropertyConverter.property_replacement(name, negated))
|
85
79
|
buffer_set_extraction(replacement)
|
86
80
|
else
|
87
|
-
warn_of_unsupported_feature
|
81
|
+
warn_of_unsupported_feature('property')
|
88
82
|
end
|
89
83
|
end
|
90
84
|
|
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: 1.
|
4
|
+
version: 1.2.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: 2016-
|
11
|
+
date: 2016-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: regexp_parser
|