js_regex 1.0.10 → 1.0.11
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c4a6863b83e153ca634f1bacc95617a69714079
|
4
|
+
data.tar.gz: 167deca0ba9f16ee72ebcb515c96a6633c2e37f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c75ae7b1fdb1efb48fa59a12cfe5f17d1475a8a2087f6f73b062dec88b7cb5b87e4d42ad8786d77d4bfae3f8c00d53bdf8496f34e935ae61876c000b6901476
|
7
|
+
data.tar.gz: bcd94e25831bb768e86c51cdd2aabf3952ec84580b76495a70710a58a2d926aa97443112df05730b3a5101fec7560da36c3236e30d1391261ce4ef8401b2f540
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class JsRegex
|
2
|
+
#
|
3
|
+
module Converter
|
4
|
+
require_relative 'base'
|
5
|
+
#
|
6
|
+
# Template class implementation.
|
7
|
+
#
|
8
|
+
class BackrefConverter < JsRegex::Converter::Base
|
9
|
+
private
|
10
|
+
|
11
|
+
def convert_data
|
12
|
+
case subtype
|
13
|
+
when :number
|
14
|
+
convert_number_backref
|
15
|
+
else
|
16
|
+
warn_of_unsupported_feature
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def convert_number_backref
|
21
|
+
if context.group_count_changed
|
22
|
+
warn_of_unsupported_feature('number backreference following a '\
|
23
|
+
'feature that changes the group count (such as an atomic group)')
|
24
|
+
else
|
25
|
+
pass_through
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -8,12 +8,13 @@ class JsRegex
|
|
8
8
|
class Context
|
9
9
|
attr_accessor :buffered_set_members,
|
10
10
|
:buffered_set_extractions,
|
11
|
+
:captured_groups,
|
12
|
+
:group_count_changed,
|
11
13
|
:group_level,
|
12
14
|
:group_level_for_backreference,
|
13
15
|
:group_number_for_backreference,
|
14
16
|
:negative_lookbehind,
|
15
17
|
:negative_set_levels,
|
16
|
-
:opened_groups,
|
17
18
|
:previous_quantifier_subtype,
|
18
19
|
:previous_quantifier_end,
|
19
20
|
:set_level
|
@@ -21,10 +22,11 @@ class JsRegex
|
|
21
22
|
def initialize
|
22
23
|
self.buffered_set_members = []
|
23
24
|
self.buffered_set_extractions = []
|
25
|
+
self.captured_groups = 0
|
26
|
+
self.group_count_changed = false
|
24
27
|
self.group_level = 0
|
25
28
|
self.negative_lookbehind = false
|
26
29
|
self.negative_set_levels = []
|
27
|
-
self.opened_groups = 0
|
28
30
|
self.set_level = 0
|
29
31
|
end
|
30
32
|
|
@@ -11,11 +11,12 @@ class JsRegex
|
|
11
11
|
def convert_data
|
12
12
|
case subtype
|
13
13
|
when :atomic then open_atomic_group
|
14
|
-
when :capture
|
14
|
+
when :capture then open_group
|
15
15
|
when :close then close_group
|
16
16
|
when :comment then '' # drop whole group w/o warning
|
17
17
|
when :named_ab, :named_sq then open_group('(') # drop name w/o warning
|
18
18
|
when :options then open_options_group
|
19
|
+
when :passive then open_group('(?:', false)
|
19
20
|
else
|
20
21
|
warn_of_unsupported_feature
|
21
22
|
open_group('(')
|
@@ -27,7 +28,7 @@ class JsRegex
|
|
27
28
|
# http://instanceof.me/post/52245507631
|
28
29
|
# regex-emulate-atomic-grouping-with-lookahead
|
29
30
|
context.group_level_for_backreference = context.group_level
|
30
|
-
context.group_number_for_backreference = context.
|
31
|
+
context.group_number_for_backreference = context.captured_groups + 1
|
31
32
|
open_assertion('(?=(')
|
32
33
|
end
|
33
34
|
|
@@ -36,9 +37,9 @@ class JsRegex
|
|
36
37
|
open_group('(')
|
37
38
|
end
|
38
39
|
|
39
|
-
def open_group(group_head = pass_through)
|
40
|
+
def open_group(group_head = pass_through, capturing = true)
|
40
41
|
context.group_level += 1
|
41
|
-
context.
|
42
|
+
context.captured_groups += 1 if capturing
|
42
43
|
group_head
|
43
44
|
end
|
44
45
|
|
@@ -71,6 +72,7 @@ class JsRegex
|
|
71
72
|
|
72
73
|
def close_atomic_group
|
73
74
|
context.group_level_for_backreference = nil
|
75
|
+
context.group_count_changed = true
|
74
76
|
# the empty passive group (?:) is appended in case literal digits follow
|
75
77
|
"))\\#{context.group_number_for_backreference}(?:)"
|
76
78
|
end
|
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.0.
|
4
|
+
version: 1.0.11
|
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: 2015-
|
11
|
+
date: 2015-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: regexp_parser
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- lib/js_regex/conversion.rb
|
93
93
|
- lib/js_regex/converter/anchor_converter.rb
|
94
94
|
- lib/js_regex/converter/assertion_converter.rb
|
95
|
+
- lib/js_regex/converter/backref_converter.rb
|
95
96
|
- lib/js_regex/converter/base.rb
|
96
97
|
- lib/js_regex/converter/conditional_converter.rb
|
97
98
|
- lib/js_regex/converter/context.rb
|