regexp_parser 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -2
- data/LICENSE +1 -1
- data/README.md +2 -2
- data/Rakefile +5 -8
- data/lib/regexp_parser/expression/classes/escape_sequence.rb +12 -7
- data/lib/regexp_parser/expression/methods/strfregexp.rb +1 -1
- data/lib/regexp_parser/scanner/properties/long.csv +604 -0
- data/lib/regexp_parser/scanner/properties/short.csv +242 -0
- data/lib/regexp_parser/scanner/scanner.rl +6 -4
- data/lib/regexp_parser/scanner.rb +126 -124
- data/lib/regexp_parser/syntax/base.rb +3 -5
- data/lib/regexp_parser/syntax/token/backreference.rb +7 -2
- data/lib/regexp_parser/syntax/versions/1.8.6.rb +2 -2
- data/lib/regexp_parser/syntax/versions/1.9.1.rb +1 -1
- data/lib/regexp_parser/version.rb +1 -1
- data/regexp_parser.gemspec +20 -22
- metadata +11 -143
- data/lib/regexp_parser/scanner/properties/long.yml +0 -607
- data/lib/regexp_parser/scanner/properties/short.yml +0 -245
- data/spec/expression/base_spec.rb +0 -104
- data/spec/expression/clone_spec.rb +0 -152
- data/spec/expression/conditional_spec.rb +0 -89
- data/spec/expression/free_space_spec.rb +0 -27
- data/spec/expression/methods/match_length_spec.rb +0 -161
- data/spec/expression/methods/match_spec.rb +0 -25
- data/spec/expression/methods/strfregexp_spec.rb +0 -224
- data/spec/expression/methods/tests_spec.rb +0 -99
- data/spec/expression/methods/traverse_spec.rb +0 -161
- data/spec/expression/options_spec.rb +0 -128
- data/spec/expression/subexpression_spec.rb +0 -50
- data/spec/expression/to_h_spec.rb +0 -26
- data/spec/expression/to_s_spec.rb +0 -108
- data/spec/lexer/all_spec.rb +0 -22
- data/spec/lexer/conditionals_spec.rb +0 -53
- data/spec/lexer/delimiters_spec.rb +0 -68
- data/spec/lexer/escapes_spec.rb +0 -14
- data/spec/lexer/keep_spec.rb +0 -10
- data/spec/lexer/literals_spec.rb +0 -64
- data/spec/lexer/nesting_spec.rb +0 -99
- data/spec/lexer/refcalls_spec.rb +0 -60
- data/spec/parser/all_spec.rb +0 -43
- data/spec/parser/alternation_spec.rb +0 -88
- data/spec/parser/anchors_spec.rb +0 -17
- data/spec/parser/conditionals_spec.rb +0 -179
- data/spec/parser/errors_spec.rb +0 -30
- data/spec/parser/escapes_spec.rb +0 -133
- data/spec/parser/free_space_spec.rb +0 -130
- data/spec/parser/groups_spec.rb +0 -108
- data/spec/parser/keep_spec.rb +0 -6
- data/spec/parser/options_spec.rb +0 -28
- data/spec/parser/posix_classes_spec.rb +0 -8
- data/spec/parser/properties_spec.rb +0 -117
- data/spec/parser/quantifiers_spec.rb +0 -68
- data/spec/parser/refcalls_spec.rb +0 -117
- data/spec/parser/set/intersections_spec.rb +0 -127
- data/spec/parser/set/ranges_spec.rb +0 -121
- data/spec/parser/sets_spec.rb +0 -178
- data/spec/parser/types_spec.rb +0 -18
- data/spec/scanner/all_spec.rb +0 -18
- data/spec/scanner/anchors_spec.rb +0 -21
- data/spec/scanner/conditionals_spec.rb +0 -128
- data/spec/scanner/delimiters_spec.rb +0 -52
- data/spec/scanner/errors_spec.rb +0 -67
- data/spec/scanner/escapes_spec.rb +0 -73
- data/spec/scanner/free_space_spec.rb +0 -165
- data/spec/scanner/groups_spec.rb +0 -61
- data/spec/scanner/keep_spec.rb +0 -10
- data/spec/scanner/literals_spec.rb +0 -39
- data/spec/scanner/meta_spec.rb +0 -18
- data/spec/scanner/options_spec.rb +0 -36
- data/spec/scanner/properties_spec.rb +0 -64
- data/spec/scanner/quantifiers_spec.rb +0 -25
- data/spec/scanner/refcalls_spec.rb +0 -55
- data/spec/scanner/sets_spec.rb +0 -151
- data/spec/scanner/types_spec.rb +0 -14
- data/spec/spec_helper.rb +0 -28
- data/spec/support/capturing_stderr.rb +0 -9
- data/spec/support/shared_examples.rb +0 -77
- data/spec/syntax/syntax_spec.rb +0 -48
- data/spec/syntax/syntax_token_map_spec.rb +0 -23
- data/spec/syntax/versions/1.8.6_spec.rb +0 -17
- data/spec/syntax/versions/1.9.1_spec.rb +0 -10
- data/spec/syntax/versions/1.9.3_spec.rb +0 -9
- data/spec/syntax/versions/2.0.0_spec.rb +0 -13
- data/spec/syntax/versions/2.2.0_spec.rb +0 -9
- data/spec/syntax/versions/aliases_spec.rb +0 -38
- data/spec/token/token_spec.rb +0 -85
data/spec/scanner/sets_spec.rb
DELETED
@@ -1,151 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe('Set scanning') do
|
4
|
-
include_examples 'scan', /[a]/, 0 => [:set, :open, '[', 0, 1]
|
5
|
-
include_examples 'scan', /[b]/, 2 => [:set, :close, ']', 2, 3]
|
6
|
-
include_examples 'scan', /[^n]/, 1 => [:set, :negate, '^', 1, 2]
|
7
|
-
|
8
|
-
include_examples 'scan', /[c]/, 1 => [:literal, :literal, 'c', 1, 2]
|
9
|
-
include_examples 'scan', /[^d]/, 2 => [:literal, :literal, 'd', 2, 3]
|
10
|
-
|
11
|
-
include_examples 'scan', /[\b]/, 1 => [:escape, :backspace, '\b', 1, 3]
|
12
|
-
include_examples 'scan', /[A\bX]/, 2 => [:escape, :backspace, '\b', 2, 4]
|
13
|
-
|
14
|
-
include_examples 'scan', /[\a]/, 1 => [:escape, :bell, '\a', 1, 3]
|
15
|
-
include_examples 'scan', /[\e]/, 1 => [:escape, :escape, '\e', 1, 3]
|
16
|
-
include_examples 'scan', /[\f]/, 1 => [:escape, :form_feed, '\f', 1, 3]
|
17
|
-
include_examples 'scan', /[\n]/, 1 => [:escape, :newline, '\n', 1, 3]
|
18
|
-
include_examples 'scan', /[\r]/, 1 => [:escape, :carriage, '\r', 1, 3]
|
19
|
-
include_examples 'scan', /[\t]/, 1 => [:escape, :tab, '\t', 1, 3]
|
20
|
-
include_examples 'scan', /[\v]/, 1 => [:escape, :vertical_tab, '\v', 1, 3]
|
21
|
-
|
22
|
-
include_examples 'scan', /[.]/, 1 => [:literal, :literal, '.', 1, 2]
|
23
|
-
include_examples 'scan', /[?]/, 1 => [:literal, :literal, '?', 1, 2]
|
24
|
-
include_examples 'scan', /[*]/, 1 => [:literal, :literal, '*', 1, 2]
|
25
|
-
include_examples 'scan', /[+]/, 1 => [:literal, :literal, '+', 1, 2]
|
26
|
-
include_examples 'scan', /[{]/, 1 => [:literal, :literal, '{', 1, 2]
|
27
|
-
include_examples 'scan', /[}]/, 1 => [:literal, :literal, '}', 1, 2]
|
28
|
-
include_examples 'scan', /[<]/, 1 => [:literal, :literal, '<', 1, 2]
|
29
|
-
include_examples 'scan', /[>]/, 1 => [:literal, :literal, '>', 1, 2]
|
30
|
-
|
31
|
-
include_examples 'scan', '[\\\\]', 1 => [:escape, :backslash, '\\\\', 1, 3]
|
32
|
-
include_examples 'scan', '[\u0040]', 1 => [:escape, :codepoint, '\u0040', 1, 7]
|
33
|
-
include_examples 'scan', '[\u{40}]', 1 => [:escape, :codepoint_list, '\u{40}', 1, 7]
|
34
|
-
include_examples 'scan', '[\c2]', 1 => [:escape, :control, '\c2', 1, 4]
|
35
|
-
include_examples 'scan', '[\C-C]', 1 => [:escape, :control, '\C-C', 1, 5]
|
36
|
-
include_examples 'scan', '[\x20]', 1 => [:escape, :hex, '\x20', 1, 5]
|
37
|
-
include_examples 'scan', '[\M-Z]', 1 => [:escape, :meta_sequence, '\M-Z', 1, 5]
|
38
|
-
include_examples 'scan', '[\M-\C-X]', 1 => [:escape, :meta_sequence, '\M-\C-X', 1, 8]
|
39
|
-
include_examples 'scan', '[\\[]', 1 => [:escape, :set_open, '\[', 1, 3]
|
40
|
-
include_examples 'scan', '[\\]]', 1 => [:escape, :set_close, '\]', 1, 3]
|
41
|
-
include_examples 'scan', '[a\-]', 2 => [:escape, :literal, '\-', 2, 4]
|
42
|
-
include_examples 'scan', '[\-c]', 1 => [:escape, :literal, '\-', 1, 3]
|
43
|
-
include_examples 'scan', '[\.]', 1 => [:escape, :literal, '\.', 1, 3]
|
44
|
-
include_examples 'scan', '[\?]', 1 => [:escape, :literal, '\?', 1, 3]
|
45
|
-
include_examples 'scan', '[\*]', 1 => [:escape, :literal, '\*', 1, 3]
|
46
|
-
include_examples 'scan', '[\+]', 1 => [:escape, :literal, '\+', 1, 3]
|
47
|
-
include_examples 'scan', '[\|]', 1 => [:escape, :literal, '\|', 1, 3]
|
48
|
-
include_examples 'scan', '[\{]', 1 => [:escape, :literal, '\{', 1, 3]
|
49
|
-
include_examples 'scan', '[\}]', 1 => [:escape, :literal, '\}', 1, 3]
|
50
|
-
include_examples 'scan', '[\(]', 1 => [:escape, :literal, '\(', 1, 3]
|
51
|
-
include_examples 'scan', '[\)]', 1 => [:escape, :literal, '\)', 1, 3]
|
52
|
-
include_examples 'scan', '[\!]', 1 => [:escape, :literal, '\!', 1, 3]
|
53
|
-
include_examples 'scan', '[\#]', 1 => [:escape, :literal, '\#', 1, 3]
|
54
|
-
include_examples 'scan', '[\A]', 1 => [:escape, :literal, '\A', 1, 3]
|
55
|
-
include_examples 'scan', '[\z]', 1 => [:escape, :literal, '\z', 1, 3]
|
56
|
-
include_examples 'scan', '[\g]', 1 => [:escape, :literal, '\g', 1, 3]
|
57
|
-
include_examples 'scan', '[\K]', 1 => [:escape, :literal, '\K', 1, 3]
|
58
|
-
include_examples 'scan', '[\R]', 1 => [:escape, :literal, '\R', 1, 3]
|
59
|
-
include_examples 'scan', '[\X]', 1 => [:escape, :literal, '\X', 1, 3]
|
60
|
-
include_examples 'scan', '[\B]', 1 => [:escape, :literal, '\B', 1, 3]
|
61
|
-
|
62
|
-
include_examples 'scan', /[\d]/, 1 => [:type, :digit, '\d', 1, 3]
|
63
|
-
include_examples 'scan', /[\da-z]/, 1 => [:type, :digit, '\d', 1, 3]
|
64
|
-
include_examples 'scan', /[\D]/, 1 => [:type, :nondigit, '\D', 1, 3]
|
65
|
-
|
66
|
-
include_examples 'scan', /[\h]/, 1 => [:type, :hex, '\h', 1, 3]
|
67
|
-
include_examples 'scan', /[\H]/, 1 => [:type, :nonhex, '\H', 1, 3]
|
68
|
-
|
69
|
-
include_examples 'scan', /[\s]/, 1 => [:type, :space, '\s', 1, 3]
|
70
|
-
include_examples 'scan', /[\S]/, 1 => [:type, :nonspace, '\S', 1, 3]
|
71
|
-
|
72
|
-
include_examples 'scan', /[\w]/, 1 => [:type, :word, '\w', 1, 3]
|
73
|
-
include_examples 'scan', /[\W]/, 1 => [:type, :nonword, '\W', 1, 3]
|
74
|
-
|
75
|
-
include_examples 'scan', /[a-b]/, 1 => [:literal, :literal, 'a', 1, 2]
|
76
|
-
include_examples 'scan', /[a-c]/, 2 => [:set, :range, '-', 2, 3]
|
77
|
-
include_examples 'scan', /[a-d]/, 3 => [:literal, :literal, 'd', 3, 4]
|
78
|
-
include_examples 'scan', /[a-b-]/, 4 => [:literal, :literal, '-', 4, 5]
|
79
|
-
include_examples 'scan', /[-a]/, 1 => [:literal, :literal, '-', 1, 2]
|
80
|
-
include_examples 'scan', /[a-c^]/, 4 => [:literal, :literal, '^', 4, 5]
|
81
|
-
include_examples 'scan', /[a-bd-f]/, 2 => [:set, :range, '-', 2, 3]
|
82
|
-
include_examples 'scan', /[a-cd-f]/, 5 => [:set, :range, '-', 5, 6]
|
83
|
-
# this is a buggy range, it matches only `c`, but not `a`, `b` or `-`
|
84
|
-
include_examples 'scan', /[a-[c]]/, 2 => [:set, :range, '-', 2, 3]
|
85
|
-
# these are not ranges, they match `a`, `c` and `-` (or non-`-` if negated)
|
86
|
-
include_examples 'scan', /[[a]-[c]]/, 4 => [:literal, :literal, '-', 4, 5]
|
87
|
-
include_examples 'scan', /[[a]-c]/, 4 => [:literal, :literal, '-', 4, 5]
|
88
|
-
include_examples 'scan', /[^-c]/, 2 => [:literal, :literal, '-', 2, 3]
|
89
|
-
|
90
|
-
include_examples 'scan', /[a[:digit:]c]/, 2 => [:posixclass, :digit, '[:digit:]', 2, 11]
|
91
|
-
include_examples 'scan', /[[:digit:][:space:]]/, 2 => [:posixclass, :space, '[:space:]', 10, 19]
|
92
|
-
include_examples 'scan', /[[:^digit:]]/, 1 => [:nonposixclass, :digit, '[:^digit:]', 1, 11]
|
93
|
-
|
94
|
-
include_examples 'scan', /[a-d&&g-h]/, 4 => [:set, :intersection, '&&', 4, 6]
|
95
|
-
include_examples 'scan', /[a&&]/, 2 => [:set, :intersection, '&&', 2, 4]
|
96
|
-
include_examples 'scan', /[&&z]/, 1 => [:set, :intersection, '&&', 1, 3]
|
97
|
-
include_examples 'scan', /[&&]/, 1 => [:set, :intersection, '&&', 1, 3]
|
98
|
-
|
99
|
-
include_examples 'scan', '[a\p{digit}c]', 2 => [:property, :digit, '\p{digit}', 2, 11]
|
100
|
-
include_examples 'scan', '[a\P{digit}c]', 2 => [:nonproperty, :digit, '\P{digit}', 2, 11]
|
101
|
-
include_examples 'scan', '[a\p{^digit}c]', 2 => [:nonproperty, :digit, '\p{^digit}', 2, 12]
|
102
|
-
include_examples 'scan', '[a\P{^digit}c]', 2 => [:property, :digit, '\P{^digit}', 2, 12]
|
103
|
-
|
104
|
-
include_examples 'scan', '[a\p{ALPHA}c]', 2 => [:property, :alpha, '\p{ALPHA}', 2, 11]
|
105
|
-
include_examples 'scan', '[a\p{P}c]', 2 => [:property, :punctuation,'\p{P}', 2, 7]
|
106
|
-
include_examples 'scan', '[a\p{P}\P{P}c]', 3 => [:nonproperty, :punctuation,'\P{P}', 7, 12]
|
107
|
-
|
108
|
-
include_examples 'scan', '[\x20-\x27]',
|
109
|
-
1 => [:escape, :hex, '\x20', 1, 5],
|
110
|
-
2 => [:set, :range, '-', 5, 6],
|
111
|
-
3 => [:escape, :hex, '\x27', 6, 10]
|
112
|
-
|
113
|
-
include_examples 'scan', '[a-w&&[^c-g]z]',
|
114
|
-
5 => [:set, :open, '[', 6, 7],
|
115
|
-
6 => [:set, :negate, '^', 7, 8],
|
116
|
-
8 => [:set, :range, '-', 9, 10],
|
117
|
-
10=> [:set, :close, ']', 11, 12]
|
118
|
-
|
119
|
-
# Collations/collating sequences and character equivalents are not enabled
|
120
|
-
# in Ruby at the moment. If they ever are, enable them in the scanner,
|
121
|
-
# add them to a new syntax version, and handle them in the parser. Until then,
|
122
|
-
# expect them to be scanned as regular subsets containing literals.
|
123
|
-
# include_examples 'scan', /[a[.a-b.]c]/, 2 => [:set, :collation, '[.a-b.]', 2, 9]
|
124
|
-
# include_examples 'scan', /[a[=e=]c]/, 2 => [:set, :equivalent, '[=e=]', 2, 7]
|
125
|
-
include_examples 'scan', '[a[.a-b.]c]',
|
126
|
-
2 => [:set, :open, '[', 2, 3],
|
127
|
-
3 => [:literal, :literal, '.', 3, 4],
|
128
|
-
4 => [:literal, :literal, 'a', 4, 5]
|
129
|
-
include_examples 'scan', '[a[=e=]c]',
|
130
|
-
2 => [:set, :open, '[', 2, 3],
|
131
|
-
3 => [:literal, :literal, '=', 3, 4],
|
132
|
-
4 => [:literal, :literal, 'e', 4, 5]
|
133
|
-
|
134
|
-
# multi-byte characters should not affect indices
|
135
|
-
include_examples 'scan', /[れます]/,
|
136
|
-
0 => [:set, :open, '[', 0, 1],
|
137
|
-
1 => [:literal, :literal, 'れ', 1, 2],
|
138
|
-
2 => [:literal, :literal, 'ま', 2, 3],
|
139
|
-
3 => [:literal, :literal, 'す', 3, 4],
|
140
|
-
4 => [:set, :close, ']', 4, 5]
|
141
|
-
|
142
|
-
specify('set literal encoding') do
|
143
|
-
text = RS.scan('[a]')[1][2].to_s
|
144
|
-
expect(text).to eq 'a'
|
145
|
-
expect(text.encoding.to_s).to eq 'UTF-8'
|
146
|
-
|
147
|
-
text = RS.scan("[\u{1F632}]")[1][2].to_s
|
148
|
-
expect(text).to eq "\u{1F632}"
|
149
|
-
expect(text.encoding.to_s).to eq 'UTF-8'
|
150
|
-
end
|
151
|
-
end
|
data/spec/scanner/types_spec.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe('Type scanning') do
|
4
|
-
include_examples 'scan', 'a\\dc', 1 => [:type, :digit, '\\d', 1, 3]
|
5
|
-
include_examples 'scan', 'a\\Dc', 1 => [:type, :nondigit, '\\D', 1, 3]
|
6
|
-
include_examples 'scan', 'a\\hc', 1 => [:type, :hex, '\\h', 1, 3]
|
7
|
-
include_examples 'scan', 'a\\Hc', 1 => [:type, :nonhex, '\\H', 1, 3]
|
8
|
-
include_examples 'scan', 'a\\sc', 1 => [:type, :space, '\\s', 1, 3]
|
9
|
-
include_examples 'scan', 'a\\Sc', 1 => [:type, :nonspace, '\\S', 1, 3]
|
10
|
-
include_examples 'scan', 'a\\wc', 1 => [:type, :word, '\\w', 1, 3]
|
11
|
-
include_examples 'scan', 'a\\Wc', 1 => [:type, :nonword, '\\W', 1, 3]
|
12
|
-
include_examples 'scan', 'a\\Rc', 1 => [:type, :linebreak, '\\R', 1, 3]
|
13
|
-
include_examples 'scan', 'a\\Xc', 1 => [:type, :xgrapheme, '\\X', 1, 3]
|
14
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
$VERBOSE = true
|
2
|
-
|
3
|
-
require 'ice_nine'
|
4
|
-
require 'regexp_property_values'
|
5
|
-
require_relative 'support/capturing_stderr'
|
6
|
-
require_relative 'support/shared_examples'
|
7
|
-
|
8
|
-
req_warn = capturing_stderr { require('regexp_parser') || fail('pre-required') }
|
9
|
-
req_warn.empty? || fail("requiring parser generated warnings:\n#{req_warn}")
|
10
|
-
|
11
|
-
RS = Regexp::Scanner
|
12
|
-
RL = Regexp::Lexer
|
13
|
-
RP = Regexp::Parser
|
14
|
-
RE = Regexp::Expression
|
15
|
-
T = Regexp::Syntax::Token
|
16
|
-
|
17
|
-
include Regexp::Expression
|
18
|
-
|
19
|
-
def ruby_version_at_least(version)
|
20
|
-
Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new(version)
|
21
|
-
end
|
22
|
-
|
23
|
-
RSpec.configure do |config|
|
24
|
-
config.around(:example) do |example|
|
25
|
-
# treat unexpected warnings as failures
|
26
|
-
expect { example.run }.not_to output.to_stderr
|
27
|
-
end
|
28
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
RSpec.shared_examples 'syntax' do |klass, opts|
|
2
|
-
opts[:implements].each do |type, tokens|
|
3
|
-
tokens.each do |token|
|
4
|
-
it("implements #{token} #{type}") do
|
5
|
-
expect(klass.implements?(type, token)).to be true
|
6
|
-
end
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
opts[:excludes] && opts[:excludes].each do |type, tokens|
|
11
|
-
tokens.each do |token|
|
12
|
-
it("does not implement #{token} #{type}") do
|
13
|
-
expect(klass.implements?(type, token)).to be false
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
RSpec.shared_examples 'scan' do |pattern, checks|
|
20
|
-
context "given the pattern #{pattern}" do
|
21
|
-
before(:all) { @tokens = Regexp::Scanner.scan(pattern) }
|
22
|
-
|
23
|
-
checks.each do |index, (type, token, text, ts, te)|
|
24
|
-
it "scans token #{index} as #{token} #{type} at #{ts}..#{te}" do
|
25
|
-
result = @tokens.at(index)
|
26
|
-
|
27
|
-
expect(result[0]).to eq type
|
28
|
-
expect(result[1]).to eq token
|
29
|
-
expect(result[2]).to eq text
|
30
|
-
expect(result[3]).to eq ts
|
31
|
-
expect(result[4]).to eq te
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
RSpec.shared_examples 'lex' do |pattern, checks|
|
38
|
-
context "given the pattern #{pattern}" do
|
39
|
-
before(:all) { @tokens = Regexp::Lexer.lex(pattern) }
|
40
|
-
|
41
|
-
checks.each do |index, (type, token, text, ts, te, lvl, set_lvl, cond_lvl)|
|
42
|
-
it "lexes token #{index} as #{token} #{type} at #{lvl}, #{set_lvl}, #{cond_lvl}" do
|
43
|
-
struct = @tokens.at(index)
|
44
|
-
|
45
|
-
expect(struct.type).to eq type
|
46
|
-
expect(struct.token).to eq token
|
47
|
-
expect(struct.text).to eq text
|
48
|
-
expect(struct.ts).to eq ts
|
49
|
-
expect(struct.te).to eq te
|
50
|
-
expect(struct.level).to eq lvl
|
51
|
-
expect(struct.set_level).to eq set_lvl
|
52
|
-
expect(struct.conditional_level).to eq cond_lvl
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
RSpec.shared_examples 'parse' do |pattern, checks|
|
59
|
-
context "given the pattern #{pattern}" do
|
60
|
-
before(:all) { @root = Regexp::Parser.parse(pattern, '*') }
|
61
|
-
|
62
|
-
checks.each do |path, (type, token, klass, attributes)|
|
63
|
-
it "parses expression at #{path} as #{klass}" do
|
64
|
-
exp = @root.dig(*path)
|
65
|
-
|
66
|
-
expect(exp).to be_instance_of(klass)
|
67
|
-
expect(exp.type).to eq type
|
68
|
-
expect(exp.token).to eq token
|
69
|
-
|
70
|
-
attributes && attributes.each do |method, value|
|
71
|
-
expect(exp.send(method)).to eq(value),
|
72
|
-
"expected expression at #{path} to have #{method} #{value}"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
data/spec/syntax/syntax_spec.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe(Regexp::Syntax) do
|
4
|
-
specify('unknown name') do
|
5
|
-
expect { Regexp::Syntax.new('ruby/1.0') }.to raise_error(Regexp::Syntax::UnknownSyntaxNameError)
|
6
|
-
end
|
7
|
-
|
8
|
-
specify('new') do
|
9
|
-
expect(Regexp::Syntax.new('ruby/1.9.3')).to be_instance_of(Regexp::Syntax::V1_9_3)
|
10
|
-
end
|
11
|
-
|
12
|
-
specify('new any') do
|
13
|
-
expect(Regexp::Syntax.new('any')).to be_instance_of(Regexp::Syntax::Any)
|
14
|
-
expect(Regexp::Syntax.new('*')).to be_instance_of(Regexp::Syntax::Any)
|
15
|
-
end
|
16
|
-
|
17
|
-
specify('not implemented') do
|
18
|
-
expect { RP.parse('\\p{alpha}', 'ruby/1.8') }.to raise_error(Regexp::Syntax::NotImplementedError)
|
19
|
-
end
|
20
|
-
|
21
|
-
specify('supported?') do
|
22
|
-
expect(Regexp::Syntax.supported?('ruby/1.1.1')).to be false
|
23
|
-
expect(Regexp::Syntax.supported?('ruby/2.4.3')).to be true
|
24
|
-
expect(Regexp::Syntax.supported?('ruby/2.5')).to be true
|
25
|
-
end
|
26
|
-
|
27
|
-
specify('invalid version') do
|
28
|
-
expect { Regexp::Syntax.version_class('2.0.0') }.to raise_error(Regexp::Syntax::InvalidVersionNameError)
|
29
|
-
|
30
|
-
expect { Regexp::Syntax.version_class('ruby/20') }.to raise_error(Regexp::Syntax::InvalidVersionNameError)
|
31
|
-
end
|
32
|
-
|
33
|
-
specify('version class tiny version') do
|
34
|
-
expect(Regexp::Syntax.version_class('ruby/1.9.3')).to eq Regexp::Syntax::V1_9_3
|
35
|
-
|
36
|
-
expect(Regexp::Syntax.version_class('ruby/2.3.1')).to eq Regexp::Syntax::V2_3_1
|
37
|
-
end
|
38
|
-
|
39
|
-
specify('version class minor version') do
|
40
|
-
expect(Regexp::Syntax.version_class('ruby/1.9')).to eq Regexp::Syntax::V1_9
|
41
|
-
|
42
|
-
expect(Regexp::Syntax.version_class('ruby/2.3')).to eq Regexp::Syntax::V2_3
|
43
|
-
end
|
44
|
-
|
45
|
-
specify('raises for unknown constant lookups') do
|
46
|
-
expect { Regexp::Syntax::V1 }.to raise_error(/V1/)
|
47
|
-
end
|
48
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe(Regexp::Syntax::Token::Map) do
|
4
|
-
let(:map) { Regexp::Syntax::Token::Map }
|
5
|
-
|
6
|
-
specify('is complete') do
|
7
|
-
latest_syntax = Regexp::Syntax.new('ruby/2.9')
|
8
|
-
|
9
|
-
latest_syntax.features.each do |type, tokens|
|
10
|
-
tokens.each { |token| expect(map[type]).to include(token) }
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
specify('contains no duplicate type/token combinations') do
|
15
|
-
combinations = map.flat_map do |type, tokens|
|
16
|
-
tokens.map { |token| "#{type} #{token}" }
|
17
|
-
end
|
18
|
-
|
19
|
-
non_uniq = combinations.group_by { |str| str }.select { |_, v| v.count > 1 }
|
20
|
-
|
21
|
-
expect(non_uniq.keys).to be_empty
|
22
|
-
end
|
23
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe(Regexp::Syntax::V1_8_6) do
|
4
|
-
include_examples 'syntax', Regexp::Syntax.new('ruby/1.8.6'),
|
5
|
-
implements: {
|
6
|
-
assertion: T::Assertion::Lookahead,
|
7
|
-
backref: T::Backreference::Plain,
|
8
|
-
escape: T::Escape::Basic + T::Escape::ASCII + T::Escape::Meta + T::Escape::Control,
|
9
|
-
group: T::Group::V1_8_6,
|
10
|
-
quantifier: T::Quantifier::Greedy + T::Quantifier::Reluctant + T::Quantifier::Interval + T::Quantifier::IntervalReluctant
|
11
|
-
},
|
12
|
-
excludes: {
|
13
|
-
assertion: T::Assertion::Lookbehind,
|
14
|
-
backref: T::Backreference::All - T::Backreference::Plain + T::SubexpressionCall::All,
|
15
|
-
quantifier: T::Quantifier::Possessive
|
16
|
-
}
|
17
|
-
end
|
@@ -1,10 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe(Regexp::Syntax::V1_9_1) do
|
4
|
-
include_examples 'syntax', Regexp::Syntax.new('ruby/1.9.1'),
|
5
|
-
implements: {
|
6
|
-
escape: T::Escape::Hex + T::Escape::Octal + T::Escape::Unicode,
|
7
|
-
type: T::CharacterType::Hex,
|
8
|
-
quantifier: T::Quantifier::Greedy + T::Quantifier::Reluctant + T::Quantifier::Possessive
|
9
|
-
}
|
10
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe(Regexp::Syntax::V1_9_3) do
|
4
|
-
include_examples 'syntax', Regexp::Syntax.new('ruby/1.9.3'),
|
5
|
-
implements: {
|
6
|
-
property: T::UnicodeProperty::Script_V1_9_3 + T::UnicodeProperty::Age_V1_9_3,
|
7
|
-
nonproperty: T::UnicodeProperty::Script_V1_9_3 + T::UnicodeProperty::Age_V1_9_3
|
8
|
-
}
|
9
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe(Regexp::Syntax::V2_0_0) do
|
4
|
-
include_examples 'syntax', Regexp::Syntax.new('ruby/2.0.0'),
|
5
|
-
implements: {
|
6
|
-
property: T::UnicodeProperty::Age_V2_0_0,
|
7
|
-
nonproperty: T::UnicodeProperty::Age_V2_0_0
|
8
|
-
},
|
9
|
-
excludes: {
|
10
|
-
property: %i[newline],
|
11
|
-
nonproperty: %i[newline]
|
12
|
-
}
|
13
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe(Regexp::Syntax::V2_2_0) do
|
4
|
-
include_examples 'syntax', Regexp::Syntax.new('ruby/2.2.0'),
|
5
|
-
implements: {
|
6
|
-
property: T::UnicodeProperty::Script_V2_2_0 + T::UnicodeProperty::Age_V2_2_0,
|
7
|
-
nonproperty: T::UnicodeProperty::Script_V2_2_0 + T::UnicodeProperty::Age_V2_2_0
|
8
|
-
}
|
9
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe(Regexp::Syntax) do
|
4
|
-
RSpec.shared_examples 'syntax alias' do |string, klass|
|
5
|
-
it "aliases #{string} to #{klass}" do
|
6
|
-
syntax = Regexp::Syntax.new(string)
|
7
|
-
expect(syntax).to be_a klass
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
include_examples 'syntax alias', 'ruby/1.8.6', Regexp::Syntax::V1_8_6
|
12
|
-
include_examples 'syntax alias', 'ruby/1.8', Regexp::Syntax::V1_8_6
|
13
|
-
include_examples 'syntax alias', 'ruby/1.9.1', Regexp::Syntax::V1_9_1
|
14
|
-
include_examples 'syntax alias', 'ruby/1.9', Regexp::Syntax::V1_9_3
|
15
|
-
include_examples 'syntax alias', 'ruby/2.0.0', Regexp::Syntax::V1_9
|
16
|
-
include_examples 'syntax alias', 'ruby/2.0', Regexp::Syntax::V2_0_0
|
17
|
-
include_examples 'syntax alias', 'ruby/2.1', Regexp::Syntax::V2_0_0
|
18
|
-
include_examples 'syntax alias', 'ruby/2.2.0', Regexp::Syntax::V2_0_0
|
19
|
-
include_examples 'syntax alias', 'ruby/2.2.10', Regexp::Syntax::V2_0_0
|
20
|
-
include_examples 'syntax alias', 'ruby/2.2', Regexp::Syntax::V2_0_0
|
21
|
-
include_examples 'syntax alias', 'ruby/2.3.0', Regexp::Syntax::V2_3_0
|
22
|
-
include_examples 'syntax alias', 'ruby/2.3', Regexp::Syntax::V2_3_0
|
23
|
-
include_examples 'syntax alias', 'ruby/2.4.0', Regexp::Syntax::V2_4_0
|
24
|
-
include_examples 'syntax alias', 'ruby/2.4.1', Regexp::Syntax::V2_4_1
|
25
|
-
include_examples 'syntax alias', 'ruby/2.5.0', Regexp::Syntax::V2_4_1
|
26
|
-
include_examples 'syntax alias', 'ruby/2.5', Regexp::Syntax::V2_5_0
|
27
|
-
include_examples 'syntax alias', 'ruby/2.6.0', Regexp::Syntax::V2_5_0
|
28
|
-
include_examples 'syntax alias', 'ruby/2.6.2', Regexp::Syntax::V2_6_2
|
29
|
-
include_examples 'syntax alias', 'ruby/2.6.3', Regexp::Syntax::V2_6_3
|
30
|
-
include_examples 'syntax alias', 'ruby/2.6', Regexp::Syntax::V2_6_3
|
31
|
-
include_examples 'syntax alias', 'ruby/3.1', Regexp::Syntax::V3_1_0
|
32
|
-
|
33
|
-
specify('future alias warning') do
|
34
|
-
expect { Regexp::Syntax.new('ruby/5.0') }
|
35
|
-
.to output(/This library .* but you are running .* \(feature set of .*\)/)
|
36
|
-
.to_stderr
|
37
|
-
end
|
38
|
-
end
|
data/spec/token/token_spec.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
RSpec.describe(Regexp::Token) do
|
4
|
-
specify('#offset') do
|
5
|
-
regexp = /ab?cd/
|
6
|
-
tokens = RL.lex(regexp)
|
7
|
-
|
8
|
-
expect(tokens[1].text).to eq 'b'
|
9
|
-
expect(tokens[1].offset).to eq [1, 2]
|
10
|
-
|
11
|
-
expect(tokens[2].text).to eq '?'
|
12
|
-
expect(tokens[2].offset).to eq [2, 3]
|
13
|
-
|
14
|
-
expect(tokens[3].text).to eq 'cd'
|
15
|
-
expect(tokens[3].offset).to eq [3, 5]
|
16
|
-
end
|
17
|
-
|
18
|
-
specify('#length') do
|
19
|
-
regexp = /abc?def/
|
20
|
-
tokens = RL.lex(regexp)
|
21
|
-
|
22
|
-
expect(tokens[0].text).to eq 'ab'
|
23
|
-
expect(tokens[0].length).to eq 2
|
24
|
-
|
25
|
-
expect(tokens[1].text).to eq 'c'
|
26
|
-
expect(tokens[1].length).to eq 1
|
27
|
-
|
28
|
-
expect(tokens[2].text).to eq '?'
|
29
|
-
expect(tokens[2].length).to eq 1
|
30
|
-
|
31
|
-
expect(tokens[3].text).to eq 'def'
|
32
|
-
expect(tokens[3].length).to eq 3
|
33
|
-
end
|
34
|
-
|
35
|
-
specify('#to_h') do
|
36
|
-
regexp = /abc?def/
|
37
|
-
tokens = RL.lex(regexp)
|
38
|
-
|
39
|
-
expect(tokens[0].text).to eq 'ab'
|
40
|
-
expect(tokens[0].to_h).to eq type: :literal, token: :literal, text: 'ab', ts: 0, te: 2, level: 0, set_level: 0, conditional_level: 0
|
41
|
-
|
42
|
-
expect(tokens[2].text).to eq '?'
|
43
|
-
expect(tokens[2].to_h).to eq type: :quantifier, token: :zero_or_one, text: '?', ts: 3, te: 4, level: 0, set_level: 0, conditional_level: 0
|
44
|
-
end
|
45
|
-
|
46
|
-
specify('#next') do
|
47
|
-
regexp = /a+b?c*d{2,3}/
|
48
|
-
tokens = RL.lex(regexp)
|
49
|
-
|
50
|
-
a = tokens.first
|
51
|
-
expect(a.text).to eq 'a'
|
52
|
-
|
53
|
-
plus = a.next
|
54
|
-
expect(plus.text).to eq '+'
|
55
|
-
|
56
|
-
b = plus.next
|
57
|
-
expect(b.text).to eq 'b'
|
58
|
-
|
59
|
-
interval = tokens.last
|
60
|
-
expect(interval.text).to eq '{2,3}'
|
61
|
-
|
62
|
-
expect(interval.next).to be_nil
|
63
|
-
end
|
64
|
-
|
65
|
-
specify('#previous') do
|
66
|
-
regexp = /a+b?c*d{2,3}/
|
67
|
-
tokens = RL.lex(regexp)
|
68
|
-
|
69
|
-
interval = tokens.last
|
70
|
-
expect(interval.text).to eq '{2,3}'
|
71
|
-
|
72
|
-
d = interval.previous
|
73
|
-
expect(d.text).to eq 'd'
|
74
|
-
|
75
|
-
star = d.previous
|
76
|
-
expect(star.text).to eq '*'
|
77
|
-
|
78
|
-
c = star.previous
|
79
|
-
expect(c.text).to eq 'c'
|
80
|
-
|
81
|
-
a = tokens.first
|
82
|
-
expect(a.text).to eq 'a'
|
83
|
-
expect(a.previous).to be_nil
|
84
|
-
end
|
85
|
-
end
|