regextest 0.1.6 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/Rakefile +13 -1
- data/lib/regextest.rb +1 -1
- data/lib/regextest/back/main.rb +10 -8
- data/lib/regextest/back/result.rb +48 -14
- data/lib/regextest/front/char-class.rb +28 -10
- data/lib/regextest/version.rb +1 -1
- data/lib/tst-reg-test.rb +2 -1
- data/regextest.gemspec +8 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 865e62c608efb9bb2cf95f3de6e426eef8a00a2a
|
4
|
+
data.tar.gz: ca284223e0405480e8361f00fdbb59f71129ee21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29c2cb6d4bb6a678bb978fb760341f4bf4eee750ff5deaea9f631df6df0270f7d18914d920ec155c6403ca78816f009eed7f98518511290abf83fca9d466e46b
|
7
|
+
data.tar.gz: 467200d8e3ba06a936ac58b7a746f6d4cdd3cc0e0c4fc8826c4e4b51c2e1b5a2a23213a89c83e4ada76366151f265579b7ed5eeef49193f5e0cf0a0f42554a6d
|
data/.gitignore
CHANGED
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ RSpec::Core::RakeTask.new(:spec)
|
|
5
5
|
|
6
6
|
# task :default => :spec
|
7
7
|
|
8
|
-
task :default => [:make, :spec]
|
8
|
+
task :default => [:make, :doc, :spec]
|
9
9
|
|
10
10
|
# Generating parser
|
11
11
|
file 'lib/regextest/front/parser.rb' => 'lib/regextest/front/parser.y' do
|
@@ -59,4 +59,16 @@ task :test => :make do
|
|
59
59
|
sh 'ruby test.rb'
|
60
60
|
end
|
61
61
|
|
62
|
+
# Generating documents
|
63
|
+
file 'doc/index.html' => [ 'lib/regextest/regexp.rb', 'README.md' ] do
|
64
|
+
puts "making document for regextest"
|
65
|
+
sh 'yardoc lib/regextest/regexp.rb'
|
66
|
+
end
|
67
|
+
|
68
|
+
task :doc =>
|
69
|
+
[
|
70
|
+
'doc/index.html',
|
71
|
+
] do
|
72
|
+
puts "Generate documents"
|
73
|
+
end
|
62
74
|
|
data/lib/regextest.rb
CHANGED
data/lib/regextest/back/main.rb
CHANGED
@@ -280,7 +280,7 @@ class Regextest::Back::Main
|
|
280
280
|
end
|
281
281
|
|
282
282
|
# puts "repeat=#{repeat} quit=#{@quit_mode} nest=#{@nest}"
|
283
|
-
repeat.times do
|
283
|
+
repeat.times do | current_repeat |
|
284
284
|
if( elem = generate_candidates(target["value"], param))
|
285
285
|
result.push elem
|
286
286
|
else
|
@@ -288,9 +288,13 @@ class Regextest::Back::Main
|
|
288
288
|
break
|
289
289
|
end
|
290
290
|
|
291
|
-
# quit to repeat if the first element is begin anchor
|
292
291
|
elem.flatten! if Array === elem # flatten considering duplicated repeat
|
293
|
-
|
292
|
+
|
293
|
+
# quit to repeat if the first element is begin anchor
|
294
|
+
if current_repeat >= min_repeat &&
|
295
|
+
elem.size > 0 &&
|
296
|
+
elem[0].respond_to?(:command) &&
|
297
|
+
elem[-1].respond_to?(:command)
|
294
298
|
break if elem[0].command == :CMD_ANC_LINE_BEGIN && !elem[-1].new_line?
|
295
299
|
break if elem[0].command == :CMD_ANC_STRING_BEGIN
|
296
300
|
end
|
@@ -327,11 +331,9 @@ class Regextest::Back::Main
|
|
327
331
|
# puts "relative: #{relative_num}, nest=#{@nest}, :#{target}"
|
328
332
|
result = @parens_hash[target["refer_name"]][:generated][relative_num]
|
329
333
|
|
330
|
-
# Somehow /(^a)\1/ must match with "aa"
|
331
|
-
if result.size > 0
|
332
|
-
|
333
|
-
result[0].command == :CMD_ANC_STRING_BEGIN)
|
334
|
-
result = result[1..-1] # ignore first anchor
|
334
|
+
# Somehow /(^a)\1/ or /(\ba)\1/ must match with "aa"
|
335
|
+
if result.size > 0
|
336
|
+
result = result.select{|elem| elem.command == :CMD_SELECT}
|
335
337
|
end
|
336
338
|
else
|
337
339
|
result = nil
|
@@ -382,16 +382,24 @@ class Regextest::Back::Result
|
|
382
382
|
@results.push (Regextest::Back::Element.any_char)
|
383
383
|
bound_process(@results[0], @results[1])
|
384
384
|
elsif offset == @results.size
|
385
|
-
|
386
|
-
|
385
|
+
if !is_end_anchor?
|
386
|
+
@results.push (Regextest::Back::Element.any_char)
|
387
|
+
if !bound_process(@results[-2], @results[-1])
|
388
|
+
return false
|
389
|
+
end
|
390
|
+
elsif !@results[-1].word_elements?
|
387
391
|
return false
|
388
392
|
end
|
389
393
|
elsif offset == 0
|
390
|
-
if !
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
394
|
+
if !is_begin_anchor?
|
395
|
+
if !unshift_params(1)
|
396
|
+
return false
|
397
|
+
end
|
398
|
+
@results.unshift (Regextest::Back::Element.any_char)
|
399
|
+
if !bound_process(@results[0], @results[1])
|
400
|
+
return false
|
401
|
+
end
|
402
|
+
elsif !@results[0].word_elements?
|
395
403
|
return false
|
396
404
|
end
|
397
405
|
end
|
@@ -409,16 +417,24 @@ class Regextest::Back::Result
|
|
409
417
|
@results.push (Regextest::Back::Element.any_char)
|
410
418
|
unbound_process(@results[0], @results[1])
|
411
419
|
elsif offset == @results.size
|
412
|
-
|
413
|
-
|
420
|
+
if !is_end_anchor?
|
421
|
+
@results.push (Regextest::Back::Element.any_char)
|
422
|
+
if !unbound_process(@results[-2], @results[-1])
|
423
|
+
return false
|
424
|
+
end
|
425
|
+
elsif @results[-1].word_elements?
|
414
426
|
return false
|
415
427
|
end
|
416
428
|
elsif offset == 0
|
417
|
-
if !
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
429
|
+
if !is_begin_anchor?
|
430
|
+
if !unshift_params(1)
|
431
|
+
return false
|
432
|
+
end
|
433
|
+
@results.unshift (Regextest::Back::Element.any_char)
|
434
|
+
if !unbound_process(@results[0], @results[1])
|
435
|
+
return false
|
436
|
+
end
|
437
|
+
elsif @results[0].word_elements?
|
422
438
|
return false
|
423
439
|
end
|
424
440
|
end
|
@@ -481,6 +497,24 @@ class Regextest::Back::Result
|
|
481
497
|
end
|
482
498
|
true
|
483
499
|
end
|
500
|
+
|
501
|
+
# return true if begin anchor exists
|
502
|
+
def is_begin_anchor?
|
503
|
+
(@positional_anchors[:CMD_ANC_STRING_BEGIN] &&
|
504
|
+
@positional_anchors[:CMD_ANC_STRING_BEGIN][0] == 0) ||
|
505
|
+
(@positional_anchors[:CMD_ANC_LINE_BEGIN] &&
|
506
|
+
@positional_anchors[:CMD_ANC_LINE_BEGIN][0] == 0)
|
507
|
+
end
|
508
|
+
|
509
|
+
# return true if end anchor exists
|
510
|
+
def is_end_anchor?
|
511
|
+
(@positional_anchors[:CMD_ANC_STRING_END] &&
|
512
|
+
@positional_anchors[:CMD_ANC_STRING_END][-1] == @results.size) ||
|
513
|
+
(@positional_anchors[:CMD_ANC_STRING_END2] &&
|
514
|
+
@positional_anchors[:CMD_ANC_STRING_END2][-1] == @results.size) ||
|
515
|
+
(@positional_anchors[:CMD_ANC_LINE_END] &&
|
516
|
+
@positional_anchors[:CMD_ANC_LINE_END][-1] == @results.size)
|
517
|
+
end
|
484
518
|
|
485
519
|
# Fixes results
|
486
520
|
def fix
|
@@ -16,6 +16,7 @@ module Regextest::Front::CharClass
|
|
16
16
|
@@id = 0 # a class variable for generating unique name of element
|
17
17
|
@@ascii_whole_set = nil
|
18
18
|
@@unicode_whole_set = nil
|
19
|
+
@@any_code_whole_set = nil
|
19
20
|
|
20
21
|
attr_reader :candidates, :offset, :length
|
21
22
|
|
@@ -80,20 +81,28 @@ module Regextest::Front::CharClass
|
|
80
81
|
@is_reverse = true
|
81
82
|
end
|
82
83
|
|
83
|
-
def set_reverse(options)
|
84
|
-
TstLog("CharClass set_reverse")
|
84
|
+
def set_reverse(options, default_whole_set = nil)
|
85
|
+
TstLog("CharClass set_reverse")
|
86
|
+
|
87
|
+
elems = @candidates.inject([]){|result, elem| result += elem.enumerate}
|
85
88
|
|
86
89
|
# Calc whole set of letters (depends on language environment)
|
87
|
-
@whole_set = get_whole_set(options)
|
90
|
+
@whole_set = default_whole_set || get_whole_set(options)
|
88
91
|
|
89
92
|
# delete characters from whole set
|
90
|
-
whole = @whole_set.
|
91
|
-
|
92
|
-
|
93
|
+
whole = @whole_set.sort
|
94
|
+
if !default_whole_set && elems.find{| elem | !whole.bsearch {|x| elem <=> x }}
|
95
|
+
if options[:reg_options].is_unicode?
|
96
|
+
set_reverse(options, get_any_whole_set)
|
97
|
+
else # ascii or default mode
|
98
|
+
set_reverse(options, @@unicode_whole_set)
|
99
|
+
end
|
100
|
+
else
|
101
|
+
whole -= elems
|
102
|
+
|
103
|
+
# reconstructing valid character set using TRange objects
|
104
|
+
@candidates = reconstruct_candidates(whole)
|
93
105
|
end
|
94
|
-
|
95
|
-
# reconstructing valid character set using TRange objects
|
96
|
-
@candidates = reconstruct_candidates(whole)
|
97
106
|
self
|
98
107
|
end
|
99
108
|
|
@@ -158,7 +167,7 @@ module Regextest::Front::CharClass
|
|
158
167
|
ascii_set & print_set
|
159
168
|
end
|
160
169
|
|
161
|
-
# Get
|
170
|
+
# Get code set of specified unicode classes( by environment variable)
|
162
171
|
def get_unicode_whole_set
|
163
172
|
char_set = []
|
164
173
|
TstConstUnicodeCharSet.split("|").each do | elem |
|
@@ -167,6 +176,15 @@ module Regextest::Front::CharClass
|
|
167
176
|
char_set
|
168
177
|
end
|
169
178
|
|
179
|
+
# Get whole (assigned) unicode set
|
180
|
+
def get_any_whole_set
|
181
|
+
if @@any_code_whole_set
|
182
|
+
@@any_code_whole_set
|
183
|
+
else
|
184
|
+
@@any_code_whole_set = Regextest::Unicode.enumerate("assigned")
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
170
188
|
# enumerate nomimated letters
|
171
189
|
def enumerate
|
172
190
|
TstLog("CharClass enumerate")
|
data/lib/regextest/version.rb
CHANGED
data/lib/tst-reg-test.rb
CHANGED
@@ -89,7 +89,7 @@ class Regextest::Test
|
|
89
89
|
reg = line.gsub(/^\s*(?:x1|x2|n)\(\"|\"\)\s*$/, "")
|
90
90
|
begin
|
91
91
|
rc = nil
|
92
|
-
timeout(timeout_seconds){
|
92
|
+
Timeout.timeout(timeout_seconds){
|
93
93
|
rc = eval(line)
|
94
94
|
}
|
95
95
|
if(rc[:result] == :ok)
|
@@ -144,6 +144,7 @@ class Regextest::Test
|
|
144
144
|
if !line.match(/ONIG_SYNTAX_PERL/)
|
145
145
|
if(md = line.match(/^\s*(?:x|x2|n)\s*\(.+?$/u) rescue nil)
|
146
146
|
line.sub!(/,\s*\".+?$/, ")") rescue nil
|
147
|
+
line.gsub!(/\\\\x\{(\h+)\}/) { "\\u{#{$1}}" }
|
147
148
|
lines.push line if line
|
148
149
|
end
|
149
150
|
else
|
data/regextest.gemspec
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'regextest/version'
|
5
|
+
additional_files = [
|
6
|
+
"lib/regextest/unicode.rb",
|
7
|
+
"lib/regextest/front/case-folding.rb",
|
8
|
+
"lib/regextest/front/parser.rb",
|
9
|
+
"lib/regextest/front/bracket-parser.rb"
|
10
|
+
]
|
5
11
|
|
6
12
|
Gem::Specification.new do |spec|
|
7
13
|
spec.name = "regextest"
|
@@ -14,7 +20,8 @@ Gem::Specification.new do |spec|
|
|
14
20
|
spec.homepage = "https://bitbucket.org/ikomamik/regextest"
|
15
21
|
spec.license = "2-clause BSD license (see the file LICENSE.txt)"
|
16
22
|
|
17
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } +
|
24
|
+
additional_files
|
18
25
|
spec.bindir = "exe"
|
19
26
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
27
|
spec.require_paths = ["lib"]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: regextest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- IKOMA, Mikio
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby
|
@@ -143,18 +143,15 @@ files:
|
|
143
143
|
- lib/regextest/front.rb
|
144
144
|
- lib/regextest/front/anchor.rb
|
145
145
|
- lib/regextest/front/back-refer.rb
|
146
|
-
- lib/regextest/front/bracket-parser.rb
|
147
146
|
- lib/regextest/front/bracket-parser.y
|
148
147
|
- lib/regextest/front/bracket-scanner.rb
|
149
148
|
- lib/regextest/front/bracket.rb
|
150
149
|
- lib/regextest/front/builtin-functions.rb
|
151
|
-
- lib/regextest/front/case-folding.rb
|
152
150
|
- lib/regextest/front/char-class.rb
|
153
151
|
- lib/regextest/front/empty.rb
|
154
152
|
- lib/regextest/front/letter.rb
|
155
153
|
- lib/regextest/front/manage-parentheses.rb
|
156
154
|
- lib/regextest/front/parenthesis.rb
|
157
|
-
- lib/regextest/front/parser.rb
|
158
155
|
- lib/regextest/front/parser.y
|
159
156
|
- lib/regextest/front/range.rb
|
160
157
|
- lib/regextest/front/repeat.rb
|
@@ -165,10 +162,13 @@ files:
|
|
165
162
|
- lib/regextest/front/special-letter.rb
|
166
163
|
- lib/regextest/regex-option.rb
|
167
164
|
- lib/regextest/regexp.rb
|
168
|
-
- lib/regextest/unicode.rb
|
169
165
|
- lib/regextest/version.rb
|
170
166
|
- lib/tst-reg-test.rb
|
171
167
|
- regextest.gemspec
|
168
|
+
- lib/regextest/unicode.rb
|
169
|
+
- lib/regextest/front/case-folding.rb
|
170
|
+
- lib/regextest/front/parser.rb
|
171
|
+
- lib/regextest/front/bracket-parser.rb
|
172
172
|
homepage: https://bitbucket.org/ikomamik/regextest
|
173
173
|
licenses:
|
174
174
|
- 2-clause BSD license (see the file LICENSE.txt)
|