regexp_parser 1.8.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +62 -0
- data/Gemfile +1 -0
- data/README.md +1 -4
- data/Rakefile +2 -2
- data/lib/regexp_parser/expression.rb +4 -17
- data/lib/regexp_parser/expression/classes/free_space.rb +1 -1
- data/lib/regexp_parser/expression/classes/group.rb +22 -2
- data/lib/regexp_parser/expression/classes/root.rb +4 -16
- data/lib/regexp_parser/expression/methods/match_length.rb +2 -2
- data/lib/regexp_parser/expression/methods/traverse.rb +2 -2
- data/lib/regexp_parser/expression/quantifier.rb +9 -0
- data/lib/regexp_parser/expression/sequence.rb +0 -10
- data/lib/regexp_parser/lexer.rb +2 -2
- data/lib/regexp_parser/parser.rb +27 -2
- data/lib/regexp_parser/scanner.rb +1194 -1272
- data/lib/regexp_parser/scanner/char_type.rl +11 -11
- data/lib/regexp_parser/scanner/property.rl +2 -2
- data/lib/regexp_parser/scanner/scanner.rl +178 -186
- data/lib/regexp_parser/syntax.rb +4 -4
- data/lib/regexp_parser/syntax/any.rb +2 -2
- data/lib/regexp_parser/syntax/base.rb +1 -1
- data/lib/regexp_parser/syntax/version_lookup.rb +2 -2
- data/lib/regexp_parser/version.rb +1 -1
- data/spec/expression/base_spec.rb +10 -0
- data/spec/expression/subexpression_spec.rb +1 -1
- data/spec/expression/to_s_spec.rb +39 -31
- data/spec/lexer/literals_spec.rb +24 -49
- data/spec/parser/errors_spec.rb +1 -1
- data/spec/parser/escapes_spec.rb +1 -1
- data/spec/parser/quantifiers_spec.rb +16 -0
- data/spec/parser/set/ranges_spec.rb +3 -3
- data/spec/scanner/escapes_spec.rb +7 -0
- data/spec/scanner/groups_spec.rb +10 -1
- data/spec/scanner/literals_spec.rb +28 -38
- data/spec/scanner/quantifiers_spec.rb +18 -13
- data/spec/scanner/sets_spec.rb +23 -5
- data/spec/spec_helper.rb +1 -0
- metadata +3 -7
- data/spec/expression/root_spec.rb +0 -9
- data/spec/expression/sequence_spec.rb +0 -9
@@ -1,20 +1,25 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
RSpec.describe('Quantifier scanning') do
|
4
|
-
include_examples 'scan', 'a?',
|
5
|
-
include_examples 'scan', 'a??',
|
6
|
-
include_examples 'scan', 'a?+',
|
4
|
+
include_examples 'scan', 'a?', 1 => [:quantifier, :zero_or_one, '?', 1, 2]
|
5
|
+
include_examples 'scan', 'a??', 1 => [:quantifier, :zero_or_one_reluctant, '??', 1, 3]
|
6
|
+
include_examples 'scan', 'a?+', 1 => [:quantifier, :zero_or_one_possessive, '?+', 1, 3]
|
7
7
|
|
8
|
-
include_examples 'scan', 'a*',
|
9
|
-
include_examples 'scan', 'a*?',
|
10
|
-
include_examples 'scan', 'a*+',
|
8
|
+
include_examples 'scan', 'a*', 1 => [:quantifier, :zero_or_more, '*', 1, 2]
|
9
|
+
include_examples 'scan', 'a*?', 1 => [:quantifier, :zero_or_more_reluctant, '*?', 1, 3]
|
10
|
+
include_examples 'scan', 'a*+', 1 => [:quantifier, :zero_or_more_possessive, '*+', 1, 3]
|
11
11
|
|
12
|
-
include_examples 'scan', 'a+',
|
13
|
-
include_examples 'scan', 'a+?',
|
14
|
-
include_examples 'scan', 'a++',
|
12
|
+
include_examples 'scan', 'a+', 1 => [:quantifier, :one_or_more, '+', 1, 2]
|
13
|
+
include_examples 'scan', 'a+?', 1 => [:quantifier, :one_or_more_reluctant, '+?', 1, 3]
|
14
|
+
include_examples 'scan', 'a++', 1 => [:quantifier, :one_or_more_possessive, '++', 1, 3]
|
15
15
|
|
16
|
-
include_examples 'scan', 'a{2}',
|
17
|
-
include_examples 'scan', 'a{2,}',
|
18
|
-
include_examples 'scan', 'a{,2}',
|
19
|
-
include_examples 'scan', 'a{2,4}',
|
16
|
+
include_examples 'scan', 'a{2}', 1 => [:quantifier, :interval, '{2}', 1, 4]
|
17
|
+
include_examples 'scan', 'a{2,}', 1 => [:quantifier, :interval, '{2,}', 1, 5]
|
18
|
+
include_examples 'scan', 'a{,2}', 1 => [:quantifier, :interval, '{,2}', 1, 5]
|
19
|
+
include_examples 'scan', 'a{2,4}', 1 => [:quantifier, :interval, '{2,4}', 1, 6]
|
20
|
+
|
21
|
+
# special case: chained quantifiers
|
22
|
+
include_examples 'scan', 'a+{2}{3}', 1 => [:quantifier, :one_or_more, '+', 1, 2]
|
23
|
+
include_examples 'scan', 'a+{2}{3}', 2 => [:quantifier, :interval, '{2}', 2, 5]
|
24
|
+
include_examples 'scan', 'a+{2}{3}', 3 => [:quantifier, :interval, '{3}', 5, 8]
|
20
25
|
end
|
data/spec/scanner/sets_spec.rb
CHANGED
@@ -18,8 +18,6 @@ RSpec.describe('Set scanning') do
|
|
18
18
|
include_examples 'scan', /[<]/, 1 => [:literal, :literal, '<', 1, 2]
|
19
19
|
include_examples 'scan', /[>]/, 1 => [:literal, :literal, '>', 1, 2]
|
20
20
|
|
21
|
-
include_examples 'scan', /[äöü]/, 2 => [:literal, :literal, 'ö', 3, 5]
|
22
|
-
|
23
21
|
include_examples 'scan', /[\x20]/, 1 => [:escape, :hex, '\x20', 1, 5]
|
24
22
|
|
25
23
|
include_examples 'scan', '[\.]', 1 => [:escape, :dot, '\.', 1, 3]
|
@@ -63,9 +61,6 @@ RSpec.describe('Set scanning') do
|
|
63
61
|
include_examples 'scan', /[[:digit:][:space:]]/, 2 => [:posixclass, :space, '[:space:]', 10, 19]
|
64
62
|
include_examples 'scan', /[[:^digit:]]/, 1 => [:nonposixclass, :digit, '[:^digit:]', 1, 11]
|
65
63
|
|
66
|
-
include_examples 'scan', /[a[.a-b.]c]/, 2 => [:set, :collation, '[.a-b.]', 2, 9]
|
67
|
-
include_examples 'scan', /[a[=e=]c]/, 2 => [:set, :equivalent, '[=e=]', 2, 7]
|
68
|
-
|
69
64
|
include_examples 'scan', /[a-d&&g-h]/, 4 => [:set, :intersection, '&&', 4, 6]
|
70
65
|
include_examples 'scan', /[a&&]/, 2 => [:set, :intersection, '&&', 2, 4]
|
71
66
|
include_examples 'scan', /[&&z]/, 1 => [:set, :intersection, '&&', 1, 3]
|
@@ -90,6 +85,29 @@ RSpec.describe('Set scanning') do
|
|
90
85
|
8 => [:set, :range, '-', 9, 10],
|
91
86
|
10=> [:set, :close, ']', 11, 12]
|
92
87
|
|
88
|
+
# Collations/collating sequences and character equivalents are not enabled
|
89
|
+
# in Ruby at the moment. If they ever are, enable them in the scanner,
|
90
|
+
# add them to a new syntax version, and handle them in the parser. Until then,
|
91
|
+
# expect them to be scanned as regular subsets containing literals.
|
92
|
+
# include_examples 'scan', /[a[.a-b.]c]/, 2 => [:set, :collation, '[.a-b.]', 2, 9]
|
93
|
+
# include_examples 'scan', /[a[=e=]c]/, 2 => [:set, :equivalent, '[=e=]', 2, 7]
|
94
|
+
include_examples 'scan', '[a[.a-b.]c]',
|
95
|
+
2 => [:set, :open, '[', 2, 3],
|
96
|
+
3 => [:literal, :literal, '.', 3, 4],
|
97
|
+
4 => [:literal, :literal, 'a', 4, 5]
|
98
|
+
include_examples 'scan', '[a[=e=]c]',
|
99
|
+
2 => [:set, :open, '[', 2, 3],
|
100
|
+
3 => [:literal, :literal, '=', 3, 4],
|
101
|
+
4 => [:literal, :literal, 'e', 4, 5]
|
102
|
+
|
103
|
+
# multi-byte characters should not affect indices
|
104
|
+
include_examples 'scan', /[れます]/,
|
105
|
+
0 => [:set, :open, '[', 0, 1],
|
106
|
+
1 => [:literal, :literal, 'れ', 1, 2],
|
107
|
+
2 => [:literal, :literal, 'ま', 2, 3],
|
108
|
+
3 => [:literal, :literal, 'す', 3, 4],
|
109
|
+
4 => [:set, :close, ']', 4, 5]
|
110
|
+
|
93
111
|
specify('set literal encoding') do
|
94
112
|
text = RS.scan('[a]')[1][2].to_s
|
95
113
|
expect(text).to eq 'a'
|
data/spec/spec_helper.rb
CHANGED
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:
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ammar Ali
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A library for tokenizing, lexing, and parsing Ruby regular expressions.
|
14
14
|
email:
|
@@ -102,8 +102,6 @@ files:
|
|
102
102
|
- spec/expression/methods/tests_spec.rb
|
103
103
|
- spec/expression/methods/traverse_spec.rb
|
104
104
|
- spec/expression/options_spec.rb
|
105
|
-
- spec/expression/root_spec.rb
|
106
|
-
- spec/expression/sequence_spec.rb
|
107
105
|
- spec/expression/subexpression_spec.rb
|
108
106
|
- spec/expression/to_h_spec.rb
|
109
107
|
- spec/expression/to_s_spec.rb
|
@@ -185,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
183
|
- !ruby/object:Gem::Version
|
186
184
|
version: '0'
|
187
185
|
requirements: []
|
188
|
-
rubygems_version: 3.2.0
|
186
|
+
rubygems_version: 3.2.0
|
189
187
|
signing_key:
|
190
188
|
specification_version: 4
|
191
189
|
summary: Scanner, lexer, parser for ruby's regular expressions
|
@@ -200,8 +198,6 @@ test_files:
|
|
200
198
|
- spec/expression/methods/tests_spec.rb
|
201
199
|
- spec/expression/methods/traverse_spec.rb
|
202
200
|
- spec/expression/options_spec.rb
|
203
|
-
- spec/expression/root_spec.rb
|
204
|
-
- spec/expression/sequence_spec.rb
|
205
201
|
- spec/expression/subexpression_spec.rb
|
206
202
|
- spec/expression/to_h_spec.rb
|
207
203
|
- spec/expression/to_s_spec.rb
|