regexp_parser 0.4.6 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +13 -0
- data/README.md +4 -3
- data/lib/regexp_parser/expression.rb +8 -8
- data/lib/regexp_parser/expression/classes/backref.rb +7 -7
- data/lib/regexp_parser/expression/classes/conditional.rb +2 -2
- data/lib/regexp_parser/expression/classes/group.rb +2 -2
- data/lib/regexp_parser/expression/classes/root.rb +4 -18
- data/lib/regexp_parser/expression/classes/set.rb +1 -1
- data/lib/regexp_parser/expression/subexpression.rb +2 -2
- data/lib/regexp_parser/lexer.rb +10 -6
- data/lib/regexp_parser/parser.rb +202 -172
- data/lib/regexp_parser/scanner.rb +151 -148
- data/lib/regexp_parser/scanner/scanner.rl +44 -41
- data/lib/regexp_parser/syntax/tokens/backref.rb +1 -1
- data/lib/regexp_parser/version.rb +2 -2
- data/test/expression/test_to_h.rb +2 -2
- data/test/lexer/test_refcalls.rb +3 -0
- data/test/parser/test_errors.rb +13 -9
- data/test/parser/test_groups.rb +140 -14
- data/test/parser/test_refcalls.rb +13 -0
- data/test/scanner/test_free_space.rb +43 -0
- data/test/scanner/test_refcalls.rb +3 -0
- data/test/syntax/ruby/test_1.8.rb +1 -1
- metadata +3 -3
@@ -1,12 +1,20 @@
|
|
1
1
|
require File.expand_path("../../helpers", __FILE__)
|
2
2
|
|
3
3
|
class TestParserRefcalls < Test::Unit::TestCase
|
4
|
+
def test_parse_traditional_number_backref
|
5
|
+
root = RP.parse('(abc)\1', 'ruby/1.9')
|
6
|
+
exp = root.expressions.at(1)
|
7
|
+
|
8
|
+
assert_equal true, exp.is_a?(Backreference::Number)
|
9
|
+
assert_equal '1', exp.number
|
10
|
+
end
|
4
11
|
|
5
12
|
def test_parse_backref_named_ab
|
6
13
|
root = RP.parse('(?<X>abc)\k<X>', 'ruby/1.9')
|
7
14
|
exp = root.expressions.at(1)
|
8
15
|
|
9
16
|
assert_equal true, exp.is_a?(Backreference::Name)
|
17
|
+
assert_equal 'X', exp.name
|
10
18
|
end
|
11
19
|
|
12
20
|
def test_parse_backref_named_sq
|
@@ -14,6 +22,7 @@ class TestParserRefcalls < Test::Unit::TestCase
|
|
14
22
|
exp = root.expressions.at(1)
|
15
23
|
|
16
24
|
assert_equal true, exp.is_a?(Backreference::Name)
|
25
|
+
assert_equal 'X', exp.name
|
17
26
|
end
|
18
27
|
|
19
28
|
def test_parse_backref_number_ab
|
@@ -21,6 +30,7 @@ class TestParserRefcalls < Test::Unit::TestCase
|
|
21
30
|
exp = root.expressions.at(1)
|
22
31
|
|
23
32
|
assert_equal true, exp.is_a?(Backreference::Number)
|
33
|
+
assert_equal '1', exp.number
|
24
34
|
end
|
25
35
|
|
26
36
|
def test_parse_backref_number_sq
|
@@ -28,6 +38,7 @@ class TestParserRefcalls < Test::Unit::TestCase
|
|
28
38
|
exp = root.expressions.at(1)
|
29
39
|
|
30
40
|
assert_equal true, exp.is_a?(Backreference::Number)
|
41
|
+
assert_equal '1', exp.number
|
31
42
|
end
|
32
43
|
|
33
44
|
def test_parse_backref_number_relative_ab
|
@@ -35,6 +46,7 @@ class TestParserRefcalls < Test::Unit::TestCase
|
|
35
46
|
exp = root.expressions.at(1)
|
36
47
|
|
37
48
|
assert_equal true, exp.is_a?(Backreference::NumberRelative)
|
49
|
+
assert_equal '-1', exp.number
|
38
50
|
end
|
39
51
|
|
40
52
|
def test_parse_backref_number_relative_sq
|
@@ -42,6 +54,7 @@ class TestParserRefcalls < Test::Unit::TestCase
|
|
42
54
|
exp = root.expressions.at(1)
|
43
55
|
|
44
56
|
assert_equal true, exp.is_a?(Backreference::NumberRelative)
|
57
|
+
assert_equal '-1', exp.number
|
45
58
|
end
|
46
59
|
|
47
60
|
def test_parse_backref_name_call_ab
|
@@ -154,4 +154,47 @@ class ScannerFreeSpace < Test::Unit::TestCase
|
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
157
|
+
def test_scan_free_space_switch_groups
|
158
|
+
# Matches 'a bcde f g hi j'
|
159
|
+
regexp = /(a (b((?x) (c d) ((?-x)(e f) )g) h)i j)/
|
160
|
+
tokens = RS.scan(regexp)
|
161
|
+
[
|
162
|
+
[ 0, :group, :capture, '(', 0, 1],
|
163
|
+
[ 1, :literal, :literal, 'a ', 1, 3],
|
164
|
+
[ 2, :group, :capture, '(', 3, 4],
|
165
|
+
[ 3, :literal, :literal, 'b', 4, 5],
|
166
|
+
[ 4, :group, :capture, '(', 5, 6],
|
167
|
+
[ 5, :group, :options, '(?x', 6, 9],
|
168
|
+
[ 6, :group, :close, ')', 9, 10],
|
169
|
+
[ 7, :free_space, :whitespace, ' ', 10, 11],
|
170
|
+
[ 8, :group, :capture, '(', 11, 12],
|
171
|
+
[ 9, :literal, :literal, 'c', 12, 13],
|
172
|
+
[10, :free_space, :whitespace, ' ', 13, 14],
|
173
|
+
[11, :literal, :literal, 'd', 14, 15],
|
174
|
+
[12, :group, :close, ')', 15, 16],
|
175
|
+
[13, :free_space, :whitespace, ' ', 16, 17],
|
176
|
+
[14, :group, :capture, '(', 17, 18],
|
177
|
+
[15, :group, :options, '(?-x', 18, 22],
|
178
|
+
[16, :group, :close, ')', 22, 23],
|
179
|
+
[17, :group, :capture, '(', 23, 24],
|
180
|
+
[18, :literal, :literal, 'e f', 24, 27],
|
181
|
+
[19, :group, :close, ')', 27, 28],
|
182
|
+
[20, :literal, :literal, ' ', 28, 29],
|
183
|
+
[21, :group, :close, ')', 29, 30],
|
184
|
+
[22, :literal, :literal, 'g', 30, 31],
|
185
|
+
[23, :group, :close, ')', 31, 32],
|
186
|
+
[24, :literal, :literal, ' h', 32, 34],
|
187
|
+
[25, :group, :close, ')', 34, 35],
|
188
|
+
[26, :literal, :literal, 'i j', 35, 38],
|
189
|
+
[27, :group, :close, ')', 38, 39]
|
190
|
+
].each do |index, type, token, text, ts, te|
|
191
|
+
result = tokens[index]
|
192
|
+
|
193
|
+
assert_equal type, result[0]
|
194
|
+
assert_equal token, result[1]
|
195
|
+
assert_equal text, result[2]
|
196
|
+
assert_equal ts, result[3]
|
197
|
+
assert_equal te, result[4]
|
198
|
+
end
|
199
|
+
end
|
157
200
|
end
|
@@ -3,6 +3,9 @@ require File.expand_path("../../helpers", __FILE__)
|
|
3
3
|
class ScannerRefCalls < Test::Unit::TestCase
|
4
4
|
|
5
5
|
tests = {
|
6
|
+
# Traditional numerical group back-reference
|
7
|
+
'(abc)\1' => [3, :backref, :number, '\1', 5, 7],
|
8
|
+
|
6
9
|
# Group back-references, named, numbered, and relative
|
7
10
|
'(?<X>abc)\k<X>' => [3, :backref, :name_ref_ab, '\k<X>', 9, 14],
|
8
11
|
"(?<X>abc)\\k'X'" => [3, :backref, :name_ref_sq, "\\k'X'", 9, 14],
|
@@ -23,7 +23,7 @@ class TestSyntaxRuby_V18 < Test::Unit::TestCase
|
|
23
23
|
:assertion => [Assertion::Lookbehind].flatten,
|
24
24
|
|
25
25
|
:backref => [
|
26
|
-
Backreference::All + SubexpressionCall::All
|
26
|
+
Backreference::All - [:number] + SubexpressionCall::All
|
27
27
|
].flatten,
|
28
28
|
|
29
29
|
:quantifier => [
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: regexp_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ammar Ali
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A library for tokenizing, lexing, and parsing Ruby regular expressions.
|
14
14
|
email:
|
@@ -197,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
197
197
|
version: '0'
|
198
198
|
requirements: []
|
199
199
|
rubyforge_project:
|
200
|
-
rubygems_version: 2.6.
|
200
|
+
rubygems_version: 2.6.13
|
201
201
|
signing_key:
|
202
202
|
specification_version: 4
|
203
203
|
summary: Scanner, lexer, parser for ruby's regular expressions
|