regexp_parser 0.3.4 → 0.3.5
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/ChangeLog +6 -0
- data/lib/regexp_parser/syntax/ruby/1.9.1.rb +1 -1
- data/lib/regexp_parser/syntax/tokens/escape.rb +2 -0
- data/lib/regexp_parser/version.rb +1 -1
- data/test/expression/test_base.rb +32 -34
- data/test/expression/test_clone.rb +49 -47
- data/test/expression/test_conditionals.rb +40 -40
- data/test/expression/test_free_space.rb +4 -2
- data/test/expression/test_set.rb +16 -16
- data/test/expression/test_strfregexp.rb +74 -74
- data/test/expression/test_subexpression.rb +2 -2
- data/test/expression/test_tests.rb +57 -57
- data/test/expression/test_to_h.rb +11 -6
- data/test/expression/test_to_s.rb +22 -15
- data/test/expression/test_traverse.rb +26 -29
- data/test/lexer/test_all.rb +9 -7
- data/test/lexer/test_conditionals.rb +35 -11
- data/test/lexer/test_keep.rb +6 -6
- data/test/lexer/test_literals.rb +20 -10
- data/test/lexer/test_nesting.rb +14 -7
- data/test/lexer/test_refcalls.rb +12 -5
- data/test/parser/test_all.rb +15 -13
- data/test/parser/test_alternation.rb +29 -26
- data/test/parser/test_anchors.rb +7 -8
- data/test/parser/test_conditionals.rb +43 -41
- data/test/parser/test_escapes.rb +18 -16
- data/test/parser/test_free_space.rb +33 -33
- data/test/parser/test_groups.rb +46 -46
- data/test/parser/test_keep.rb +4 -4
- data/test/parser/test_properties.rb +18 -16
- data/test/parser/test_quantifiers.rb +184 -163
- data/test/parser/test_refcalls.rb +48 -32
- data/test/parser/test_sets.rb +102 -88
- data/test/parser/test_types.rb +7 -8
- data/test/scanner/test_all.rb +6 -4
- data/test/scanner/test_anchors.rb +8 -5
- data/test/scanner/test_conditionals.rb +38 -20
- data/test/scanner/test_escapes.rb +8 -6
- data/test/scanner/test_free_space.rb +89 -65
- data/test/scanner/test_groups.rb +27 -32
- data/test/scanner/test_keep.rb +24 -22
- data/test/scanner/test_literals.rb +11 -7
- data/test/scanner/test_meta.rb +11 -7
- data/test/scanner/test_properties.rb +16 -14
- data/test/scanner/test_quantifiers.rb +8 -9
- data/test/scanner/test_refcalls.rb +26 -23
- data/test/scanner/test_scripts.rb +11 -10
- data/test/scanner/test_sets.rb +8 -5
- data/test/scanner/test_types.rb +17 -15
- data/test/scanner/test_unicode_blocks.rb +11 -10
- data/test/syntax/ruby/test_1.8.rb +4 -8
- data/test/syntax/ruby/test_1.9.1.rb +1 -7
- data/test/syntax/ruby/test_1.9.3.rb +3 -7
- data/test/syntax/ruby/test_2.0.0.rb +1 -7
- data/test/syntax/ruby/test_2.2.0.rb +1 -7
- data/test/token/test_token.rb +29 -31
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed3e75e40ac66c7485636e6fe3b0c63b8d3d3aa5
|
4
|
+
data.tar.gz: d72567776c9934caa47fe2ecb503855e3c45b70d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 624065b3e707c4869ed67012bde66544d6682b577f826f7089090a070c46bc4e7f4895efabb665cd8b797f5616dc2151c7a820a5b84ae3a88ac242a3737f846f
|
7
|
+
data.tar.gz: 6b745fc5a79f260879e4415077e9754f19cb8db608132a5892833dfe5ba85f56c15b5ba3c33cc7c203ff6277cc8ded82beded0996b6376a065a210a593082583
|
data/ChangeLog
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
Mon May 30 2016 Ammar Ali <ammarabuali@gmail.com>
|
2
|
+
|
3
|
+
* Thanks to John Backus (https://github.com/backus):
|
4
|
+
- Fix parsing of /\xFF/n (hex:escape) (PR #24)
|
5
|
+
* Bumped version to 0.3.5
|
6
|
+
|
1
7
|
Wed May 25 2016 Ammar Ali <ammarabuali@gmail.com>
|
2
8
|
|
3
9
|
* Thanks to John Backus (https://github.com/backus):
|
@@ -7,10 +7,10 @@ class ExpressionBase < Test::Unit::TestCase
|
|
7
7
|
|
8
8
|
re = RP.parse(re_text).to_re
|
9
9
|
|
10
|
-
assert
|
11
|
-
|
10
|
+
assert re.is_a?(::Regexp),
|
11
|
+
'Not a Regexp, but should be'
|
12
12
|
|
13
|
-
assert_equal
|
13
|
+
assert_equal re.source, re_text
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_expression_level
|
@@ -18,51 +18,51 @@ class ExpressionBase < Test::Unit::TestCase
|
|
18
18
|
root = RP.parse(regexp)
|
19
19
|
|
20
20
|
%w{^ a (b(c(d))) e $}.each_with_index do |t, i|
|
21
|
-
assert_equal
|
22
|
-
assert_equal
|
21
|
+
assert_equal t, root[i].to_s
|
22
|
+
assert_equal 0, root[i].level
|
23
23
|
end
|
24
24
|
|
25
|
-
assert_equal
|
26
|
-
assert_equal
|
25
|
+
assert_equal 'b', root[2][0].to_s
|
26
|
+
assert_equal 1, root[2][0].level
|
27
27
|
|
28
|
-
assert_equal
|
29
|
-
assert_equal
|
28
|
+
assert_equal 'c', root[2][1][0].to_s
|
29
|
+
assert_equal 2, root[2][1][0].level
|
30
30
|
|
31
|
-
assert_equal
|
32
|
-
assert_equal
|
31
|
+
assert_equal 'd', root[2][1][1][0].to_s
|
32
|
+
assert_equal 3, root[2][1][1][0].level
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_expression_terminal?
|
36
36
|
root = RP.parse('^a([b]+)c$')
|
37
37
|
|
38
|
-
assert_equal
|
38
|
+
assert_equal false, root.terminal?
|
39
39
|
|
40
|
-
assert_equal
|
41
|
-
assert_equal
|
42
|
-
assert_equal
|
43
|
-
assert_equal
|
44
|
-
assert_equal
|
45
|
-
assert_equal
|
40
|
+
assert_equal true, root[0].terminal?
|
41
|
+
assert_equal true, root[1].terminal?
|
42
|
+
assert_equal false, root[2].terminal?
|
43
|
+
assert_equal true, root[2][0].terminal?
|
44
|
+
assert_equal true, root[3].terminal?
|
45
|
+
assert_equal true, root[4].terminal?
|
46
46
|
end
|
47
47
|
|
48
48
|
def test_expression_alt_terminal?
|
49
49
|
root = RP.parse('^(ab|cd)$')
|
50
50
|
|
51
|
-
assert_equal
|
51
|
+
assert_equal false, root.terminal?
|
52
52
|
|
53
|
-
assert_equal
|
54
|
-
assert_equal
|
55
|
-
assert_equal
|
56
|
-
assert_equal
|
57
|
-
assert_equal
|
58
|
-
assert_equal
|
59
|
-
assert_equal
|
53
|
+
assert_equal true, root[0].terminal?
|
54
|
+
assert_equal false, root[1].terminal?
|
55
|
+
assert_equal false, root[1][0].terminal?
|
56
|
+
assert_equal false, root[1][0][0].terminal?
|
57
|
+
assert_equal true, root[1][0][0][0].terminal?
|
58
|
+
assert_equal false, root[1][0][1].terminal?
|
59
|
+
assert_equal true, root[1][0][1][0].terminal?
|
60
60
|
end
|
61
61
|
|
62
62
|
def test_expression_coded_offset
|
63
63
|
root = RP.parse('^a*(b+(c?))$')
|
64
64
|
|
65
|
-
assert_equal
|
65
|
+
assert_equal '@0+12', root.coded_offset
|
66
66
|
|
67
67
|
# All top level offsets
|
68
68
|
checks = [
|
@@ -72,20 +72,18 @@ class ExpressionBase < Test::Unit::TestCase
|
|
72
72
|
['@11+1', '$' ],
|
73
73
|
].each_with_index do |check, i|
|
74
74
|
against = [ root[i].coded_offset, root[i].to_s ]
|
75
|
-
|
75
|
+
|
76
|
+
assert_equal check, against
|
76
77
|
end
|
77
78
|
|
78
79
|
# Nested expression
|
79
|
-
assert_equal
|
80
|
-
[root[2][0].coded_offset, root[2][0].to_s])
|
80
|
+
assert_equal ['@4+2', 'b+'], [root[2][0].coded_offset, root[2][0].to_s]
|
81
81
|
|
82
82
|
# Nested subexpression
|
83
|
-
assert_equal
|
84
|
-
[root[2][1].coded_offset, root[2][1].to_s])
|
83
|
+
assert_equal ['@6+4', '(c?)'], [root[2][1].coded_offset, root[2][1].to_s]
|
85
84
|
|
86
85
|
# Nested subexpression expression
|
87
|
-
assert_equal
|
88
|
-
[root[2][1][0].coded_offset, root[2][1][0].to_s])
|
86
|
+
assert_equal ['@7+2', 'c?'], [root[2][1][0].coded_offset, root[2][1][0].to_s]
|
89
87
|
end
|
90
88
|
|
91
89
|
end
|
@@ -6,57 +6,57 @@ class ExpressionClone < Test::Unit::TestCase
|
|
6
6
|
root = RP.parse(/^(?i:a)b+$/i)
|
7
7
|
copy = root.clone
|
8
8
|
|
9
|
-
|
9
|
+
refute_equal copy.object_id, root.object_id
|
10
10
|
|
11
11
|
# The text content is equal but the objects are not.
|
12
|
-
assert_equal
|
13
|
-
|
12
|
+
assert_equal copy.text, root.text
|
13
|
+
refute_equal copy.text.object_id, root.text.object_id
|
14
14
|
|
15
15
|
root_1 = root.expressions[1]
|
16
16
|
copy_1 = copy.expressions[1]
|
17
17
|
|
18
18
|
# The options hash contents are equal but the objects are not.
|
19
|
-
assert_equal
|
20
|
-
|
21
|
-
root_1.options.object_id)
|
19
|
+
assert_equal copy_1.options, root_1.options
|
20
|
+
refute_equal copy_1.options.object_id, root_1.options.object_id
|
22
21
|
|
23
22
|
root_2 = root.expressions[2]
|
24
23
|
copy_2 = copy.expressions[2]
|
25
24
|
|
26
|
-
assert
|
27
|
-
assert
|
25
|
+
assert root_2.quantified?
|
26
|
+
assert copy_2.quantified?
|
28
27
|
|
29
28
|
# The quantifier contents are equal but the objects are not.
|
30
|
-
assert_equal
|
29
|
+
assert_equal copy_2.quantifier.text,
|
30
|
+
root_2.quantifier.text
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
refute_equal copy_2.quantifier.text.object_id,
|
33
|
+
root_2.quantifier.text.object_id
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
refute_equal copy_2.quantifier.object_id,
|
36
|
+
root_2.quantifier.object_id
|
37
37
|
end
|
38
38
|
|
39
39
|
def test_expression_clone_subexpression
|
40
40
|
root = RP.parse(/^a(b([cde])f)g$/)
|
41
41
|
copy = root.clone
|
42
42
|
|
43
|
-
assert
|
44
|
-
assert
|
43
|
+
assert root.respond_to?(:expressions)
|
44
|
+
assert copy.respond_to?(:expressions)
|
45
45
|
|
46
46
|
# The expressions arrays are not equal.
|
47
|
-
|
48
|
-
|
47
|
+
refute_equal copy.expressions.object_id,
|
48
|
+
root.expressions.object_id
|
49
49
|
|
50
50
|
# The expressions in the arrays are not equal.
|
51
|
-
copy.expressions.each_with_index do |
|
52
|
-
|
53
|
-
|
51
|
+
copy.expressions.each_with_index do |exp, index|
|
52
|
+
refute_equal exp.object_id,
|
53
|
+
root.expressions[index].object_id
|
54
54
|
end
|
55
55
|
|
56
56
|
# The expressions in nested expressions are not equal.
|
57
|
-
copy.expressions[2].each_with_index do |
|
58
|
-
|
59
|
-
|
57
|
+
copy.expressions[2].each_with_index do |exp, index|
|
58
|
+
refute_equal exp.object_id,
|
59
|
+
root.expressions[2][index].object_id
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -69,21 +69,20 @@ class ExpressionClone < Test::Unit::TestCase
|
|
69
69
|
copy_1 = copy.expressions[1]
|
70
70
|
|
71
71
|
# The names are equal but their objects are not.
|
72
|
-
assert_equal
|
73
|
-
|
74
|
-
root_1.name.object_id)
|
72
|
+
assert_equal copy_1.name, root_1.name
|
73
|
+
refute_equal copy_1.name.object_id, root_1.name.object_id
|
75
74
|
|
76
75
|
# Verify super: text objects should be different.
|
77
|
-
assert_equal
|
76
|
+
assert_equal copy_1.text, root_1.text
|
78
77
|
|
79
78
|
# Verify super: expressions arrays are not equal.
|
80
|
-
|
81
|
-
|
79
|
+
refute_equal copy_1.expressions.object_id,
|
80
|
+
root_1.expressions.object_id
|
82
81
|
|
83
82
|
# Verify super: expressions in the arrays are not equal.
|
84
|
-
copy_1.expressions.each_with_index do |
|
85
|
-
|
86
|
-
|
83
|
+
copy_1.expressions.each_with_index do |exp, index|
|
84
|
+
refute_equal exp.object_id,
|
85
|
+
root_1.expressions[index].object_id
|
87
86
|
end
|
88
87
|
end
|
89
88
|
|
@@ -93,15 +92,17 @@ class ExpressionClone < Test::Unit::TestCase
|
|
93
92
|
|
94
93
|
root_2_1 = root.expressions[2][1]
|
95
94
|
|
96
|
-
copy.expressions[2][1].each_with_index do |
|
97
|
-
assert
|
95
|
+
copy.expressions[2][1].each_with_index do |exp, index|
|
96
|
+
assert exp.respond_to?(:members)
|
98
97
|
|
99
98
|
# The members arrays are not equal.
|
100
|
-
|
99
|
+
refute_equal exp.members.object_id,
|
100
|
+
root_2_1[index].members.object_id
|
101
101
|
|
102
102
|
# The members in the arrays are not equal.
|
103
|
-
|
104
|
-
|
103
|
+
exp.members.each_with_index do |member, member_index|
|
104
|
+
refute_equal member.object_id,
|
105
|
+
root_2_1[index].members[member_index].object_id
|
105
106
|
end
|
106
107
|
end
|
107
108
|
end
|
@@ -119,25 +120,26 @@ class ExpressionClone < Test::Unit::TestCase
|
|
119
120
|
copy_subset = copy_set.members[1]
|
120
121
|
|
121
122
|
# Sanity checks
|
122
|
-
assert
|
123
|
-
assert
|
123
|
+
assert root_set.respond_to?(:members)
|
124
|
+
assert copy_set.respond_to?(:members)
|
124
125
|
|
125
|
-
assert
|
126
|
-
assert
|
126
|
+
assert root_subset.respond_to?(:members)
|
127
|
+
assert copy_subset.respond_to?(:members)
|
127
128
|
|
128
129
|
# The sets are not equal
|
129
|
-
|
130
|
+
refute_equal copy_set.object_id, root_set.object_id
|
130
131
|
|
131
132
|
# The subsets are not equal
|
132
|
-
|
133
|
+
refute_equal copy_subset.object_id, root_subset.object_id
|
133
134
|
|
134
135
|
# The subsets' members arrays are not equal.
|
135
|
-
|
136
|
-
|
136
|
+
refute_equal copy_subset.members.object_id,
|
137
|
+
root_subset.members.object_id
|
137
138
|
|
138
139
|
# The subsets' members are not equal
|
139
|
-
copy_subset.members.each_with_index do |
|
140
|
-
|
140
|
+
copy_subset.members.each_with_index do |member, member_index|
|
141
|
+
refute_equal member.object_id,
|
142
|
+
root_subset.members[member_index].object_id
|
141
143
|
end
|
142
144
|
end
|
143
145
|
|
@@ -20,13 +20,13 @@ class ExpressionConditionals < Test::Unit::TestCase
|
|
20
20
|
|
21
21
|
def test_expression_conditional_root_level
|
22
22
|
%w{^ a (b(?(1)c|(?(2)d|(?(3)e|f)))g) $}.each_with_index do |t, i|
|
23
|
-
assert_equal
|
24
|
-
assert_equal
|
23
|
+
assert_equal 0, @root[i].conditional_level
|
24
|
+
assert_equal t, @root[i].to_s
|
25
25
|
end
|
26
26
|
|
27
27
|
# First capture group
|
28
|
-
assert_equal
|
29
|
-
assert_equal
|
28
|
+
assert_equal 'b', @root[2][0].text
|
29
|
+
assert_equal 0, @root[2][0].conditional_level
|
30
30
|
end
|
31
31
|
|
32
32
|
def test_expression_conditional_level_one
|
@@ -35,18 +35,18 @@ class ExpressionConditionals < Test::Unit::TestCase
|
|
35
35
|
branch_2 = @cond_1.branches.last
|
36
36
|
|
37
37
|
# Condition
|
38
|
-
assert_equal
|
39
|
-
assert_equal
|
40
|
-
assert_equal
|
38
|
+
assert_equal true, is_conditional_condition?(condition)
|
39
|
+
assert_equal '(1)', condition.text
|
40
|
+
assert_equal 1, condition.conditional_level
|
41
41
|
|
42
42
|
# Branch 1
|
43
|
-
assert_equal
|
44
|
-
assert_equal
|
45
|
-
assert_equal
|
43
|
+
assert_equal true, is_conditional_branch?(branch_1)
|
44
|
+
assert_equal 'c', branch_1.text
|
45
|
+
assert_equal 1, branch_1.conditional_level
|
46
46
|
|
47
47
|
# Literal
|
48
|
-
assert_equal
|
49
|
-
assert_equal
|
48
|
+
assert_equal 'c', branch_1.first.text
|
49
|
+
assert_equal 1, branch_1.first.conditional_level
|
50
50
|
|
51
51
|
end
|
52
52
|
|
@@ -55,26 +55,26 @@ class ExpressionConditionals < Test::Unit::TestCase
|
|
55
55
|
branch_1 = @cond_2.branches.first
|
56
56
|
branch_2 = @cond_2.branches.last
|
57
57
|
|
58
|
-
assert_equal
|
59
|
-
assert_equal
|
58
|
+
assert_equal '(?', @cond_2.text
|
59
|
+
assert_equal 1, @cond_2.conditional_level
|
60
60
|
|
61
61
|
# Condition
|
62
|
-
assert_equal
|
63
|
-
assert_equal
|
64
|
-
assert_equal
|
62
|
+
assert_equal true, is_conditional_condition?(condition)
|
63
|
+
assert_equal '(2)', condition.text
|
64
|
+
assert_equal 2, condition.conditional_level
|
65
65
|
|
66
66
|
# Branch 1
|
67
|
-
assert_equal
|
68
|
-
assert_equal
|
69
|
-
assert_equal
|
67
|
+
assert_equal true, is_conditional_branch?(branch_1)
|
68
|
+
assert_equal 'd', branch_1.text
|
69
|
+
assert_equal 2, branch_1.conditional_level
|
70
70
|
|
71
71
|
# Literal
|
72
|
-
assert_equal
|
73
|
-
assert_equal
|
72
|
+
assert_equal 'd', branch_1.first.text
|
73
|
+
assert_equal 2, branch_1.first.conditional_level
|
74
74
|
|
75
75
|
# Branch 2
|
76
|
-
assert_equal
|
77
|
-
assert_equal
|
76
|
+
assert_equal '(?', branch_2.first.text
|
77
|
+
assert_equal 2, branch_2.first.conditional_level
|
78
78
|
end
|
79
79
|
|
80
80
|
def test_expression_conditional_level_three
|
@@ -83,32 +83,32 @@ class ExpressionConditionals < Test::Unit::TestCase
|
|
83
83
|
branch_2 = @cond_3.branches.last
|
84
84
|
|
85
85
|
# Condition
|
86
|
-
assert_equal
|
87
|
-
assert_equal
|
88
|
-
assert_equal
|
86
|
+
assert_equal true, is_conditional_condition?(condition)
|
87
|
+
assert_equal '(3)', condition.text
|
88
|
+
assert_equal 3, condition.conditional_level
|
89
89
|
|
90
90
|
# Same as branch 2 in level two
|
91
|
-
assert_equal
|
92
|
-
assert_equal
|
93
|
-
assert_equal
|
91
|
+
assert_equal '(?', @cond_3.text
|
92
|
+
assert_equal '(?(3)e|f)', @cond_3.to_s
|
93
|
+
assert_equal 2, @cond_3.conditional_level
|
94
94
|
|
95
95
|
# Branch 1
|
96
|
-
assert_equal
|
97
|
-
assert_equal
|
98
|
-
assert_equal
|
96
|
+
assert_equal true, is_conditional_branch?(branch_1)
|
97
|
+
assert_equal 'e', branch_1.text
|
98
|
+
assert_equal 3, branch_1.conditional_level
|
99
99
|
|
100
100
|
# Literal
|
101
|
-
assert_equal
|
102
|
-
assert_equal
|
101
|
+
assert_equal 'e', branch_1.first.text
|
102
|
+
assert_equal 3, branch_1.first.conditional_level
|
103
103
|
|
104
104
|
# Branch 2
|
105
|
-
assert_equal
|
106
|
-
assert_equal
|
107
|
-
assert_equal
|
105
|
+
assert_equal true, is_conditional_branch?(branch_2)
|
106
|
+
assert_equal 'f', branch_2.text
|
107
|
+
assert_equal 3, branch_2.conditional_level
|
108
108
|
|
109
109
|
# Literal
|
110
|
-
assert_equal
|
111
|
-
assert_equal
|
110
|
+
assert_equal 'f', branch_2.first.text
|
111
|
+
assert_equal 3, branch_2.first.conditional_level
|
112
112
|
end
|
113
113
|
|
114
114
|
end
|