re_expand 0.0.6 → 0.1.1
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 +7 -0
- data/.gitignore +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/Makefile +22 -0
- data/README.md +39 -0
- data/Rakefile +10 -27
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/expand_ruby.gemspec +27 -0
- data/lib/{Generator.rb → re_expand/Generator.rb} +41 -24
- data/lib/{Node.rb → re_expand/Node.rb} +3 -1
- data/lib/{Scanner.rb → re_expand/Scanner.rb} +3 -2
- data/lib/re_expand/version.rb +3 -0
- data/lib/re_expand.rb +20 -38
- metadata +92 -129
- data/.gemtest +0 -0
- data/History.txt +0 -4
- data/Manifest.txt +0 -18
- data/PostInstall.txt +0 -7
- data/README.rdoc +0 -43
- data/script/console +0 -10
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/test/test_generator.rb +0 -32
- data/test/test_helper.rb +0 -3
- data/test/test_re_expand.rb +0 -36
- data/test/test_scanner.rb +0 -42
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d25d779f31d39147633c61eb33b0d54b95611378
|
4
|
+
data.tar.gz: 5f3e20916238ea9bdcde3a1a925f9e2f440f21ad
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 63fe3ec761fe216b41aa1e1ad7698b99dfcc43fa154ad7cd7cdc0fec7cd067175add88157ba6e8f6b4908b58c0d03b127fb139e731ae92f36afc58a5c31f8844
|
7
|
+
data.tar.gz: 4ddde9430c4530088b80d577ecf4a0e2a1b02a6d3f52512c4b4e4eba4a628624641bdc7cc507bc2c1e941be8cd0d32e8a41e6671b0966d329fc3331e7ca05c83
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Toshiyuki Masui
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/Makefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
VERSION=0.1.1
|
2
|
+
.PHONY: test
|
3
|
+
|
4
|
+
test:
|
5
|
+
rake test
|
6
|
+
|
7
|
+
# Build re_expand-0.1.0.gem into the pkg directory
|
8
|
+
build:
|
9
|
+
rake build
|
10
|
+
|
11
|
+
# Build and install re_expand-0.1.0.gem into system gems
|
12
|
+
install:
|
13
|
+
rake install
|
14
|
+
|
15
|
+
# Create tag v0.1.0 and build and push re_expand-0.1.0.gem to Rubygems
|
16
|
+
release:
|
17
|
+
rake release
|
18
|
+
|
19
|
+
# Push to GitHub
|
20
|
+
push:
|
21
|
+
git push git@github.com:masui/expand_ruby.git
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# re_expand
|
2
|
+
|
3
|
+
* Generates all the text strings that match the
|
4
|
+
given regexp.
|
5
|
+
|
6
|
+
`"(a|b)(1|2)"` => `["a1", "a2", "b1", "b2"]`
|
7
|
+
|
8
|
+
* If a filter pattern is given,
|
9
|
+
the output is filtered by the pattern.
|
10
|
+
|
11
|
+
## Install
|
12
|
+
|
13
|
+
$ gem install re_expand
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
require 're_expand'
|
18
|
+
"test (a|b|c)".expand { |s,a|
|
19
|
+
puts s
|
20
|
+
}
|
21
|
+
# "test a", "test b", ...
|
22
|
+
"(a|b)(1|2)".expand
|
23
|
+
# => ['a1', 'a2', 'b1', 'b2']
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on [GitHub](https://github.com/masui/expand_ruby).
|
34
|
+
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
39
|
+
|
data/Rakefile
CHANGED
@@ -1,27 +1,10 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
# Generate all the Rake tasks
|
12
|
-
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
|
-
$hoe = Hoe.spec 're_expand' do
|
14
|
-
self.developer 'Toshiyuki Masui', 'masui@pitecan.com'
|
15
|
-
self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
16
|
-
self.rubyforge_name = self.name # TODO this is default value
|
17
|
-
self.extra_deps = [['asearch','>= 0.0.1']]
|
18
|
-
# self.extra_deps = [['activesupport','>= 2.0.2']]
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
require 'newgem/tasks'
|
23
|
-
Dir['tasks/**/*.rake'].each { |t| load t }
|
24
|
-
|
25
|
-
# TODO - want other tests/tasks run by default? Add them to the list
|
26
|
-
# remove_task :default
|
27
|
-
# task :default => [:spec, :features]
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rake/testtask"
|
3
|
+
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.libs << "test"
|
6
|
+
t.libs << "lib"
|
7
|
+
t.test_files = FileList['test/**/*_test.rb']
|
8
|
+
end
|
9
|
+
|
10
|
+
task :default => :test
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "re_expand"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/expand_ruby.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 're_expand/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "re_expand"
|
8
|
+
spec.version = ExpandRuby::VERSION
|
9
|
+
spec.authors = ["Toshiyuki Masui"]
|
10
|
+
spec.email = ["masui@pitecan.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Generates all the text strings that match the given regexp.Expand RegExp.}
|
13
|
+
spec.description = %q{Generates all the text strings that match the given regexp.Expand RegExp.}
|
14
|
+
spec.homepage = "https://github.com/masui/expand_ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "minitest"
|
25
|
+
|
26
|
+
spec.add_development_dependency "asearch",'>= 0.0.1'
|
27
|
+
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
#
|
2
3
|
# Generator.rb
|
3
|
-
# ExpandHelpApp
|
4
4
|
#
|
5
5
|
# Created by Toshiyuki Masui on 2011/02/26.
|
6
|
-
#
|
7
|
-
|
6
|
+
# Modified by Toshiyuki Masui on 2012/05/??
|
7
|
+
# Modified by Toshiyuki Masui on 2016/04/24
|
8
|
+
# Copyright 2011-2016 Pitecan Systems. All rights reserved.
|
8
9
|
#
|
9
10
|
# ( ( ) ) ( ( ) ( ( ) ) ( ) ) | ( ( ) )
|
10
11
|
# pars [1]
|
@@ -13,12 +14,12 @@
|
|
13
14
|
# [3,4]
|
14
15
|
# [3,5]
|
15
16
|
|
16
|
-
require 'Scanner'
|
17
|
-
require 'Node'
|
17
|
+
require 're_expand/Scanner'
|
18
|
+
require 're_expand/Node'
|
18
19
|
|
19
|
-
require 'asearch'
|
20
|
+
require 'asearch' # これはGem
|
20
21
|
|
21
|
-
module
|
22
|
+
module ExpandRuby
|
22
23
|
class GenNode
|
23
24
|
def initialize(id, state=[], s="", substrings=[], accept=false)
|
24
25
|
@id = id
|
@@ -51,7 +52,7 @@ module ReExpand
|
|
51
52
|
#
|
52
53
|
# ルールを解析して状態遷移機械を作成し、patにマッチするもののリストを返す
|
53
54
|
#
|
54
|
-
def generate(pat,
|
55
|
+
def generate(pat, blockambig=0)
|
55
56
|
res = [[],[],[]] # 曖昧度0,1,2のマッチ結果
|
56
57
|
patterns = pat.split.map { |p| p.downcase }
|
57
58
|
|
@@ -69,6 +70,7 @@ module ReExpand
|
|
69
70
|
#
|
70
71
|
lists = []
|
71
72
|
listed = [{},{},{}]
|
73
|
+
block_listed = {}
|
72
74
|
#
|
73
75
|
# 初期状態
|
74
76
|
#
|
@@ -76,8 +78,10 @@ module ReExpand
|
|
76
78
|
list[0] = GenNode.new(startnode.id, @asearch.initstate)
|
77
79
|
lists[0] = list
|
78
80
|
#
|
81
|
+
loopcount = 0
|
79
82
|
(0..1000).each { |length|
|
80
|
-
|
83
|
+
#loop do
|
84
|
+
# length = loopcount
|
81
85
|
list = lists[length]
|
82
86
|
newlist = []
|
83
87
|
# puts "#{length} - #{list.length}"
|
@@ -98,23 +102,34 @@ module ReExpand
|
|
98
102
|
# マッチしてたら出力リストに加える
|
99
103
|
#
|
100
104
|
if acceptno then
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
105
|
+
if block_given? then
|
106
|
+
(0..blockambig).each { |ambig|
|
107
|
+
if !block_listed[s] then
|
108
|
+
if (newstate[ambig] & @asearch.acceptpat) != 0 then # マッチ
|
109
|
+
block_listed[s] = true
|
110
|
+
yield [s] + ss
|
111
|
+
end
|
112
|
+
end
|
113
|
+
}
|
114
|
+
else
|
115
|
+
maxambig = 2
|
116
|
+
(0..maxambig).each { |ambig|
|
117
|
+
if !listed[ambig][s] then
|
118
|
+
if (newstate[ambig] & @asearch.acceptpat) != 0 then # マッチ
|
119
|
+
maxambig = ambig if ambig < maxambig # 曖昧度0でマッチすれば曖昧度1の検索は不要
|
120
|
+
listed[ambig][s] = true
|
121
|
+
sslen = ss.length
|
122
|
+
if sslen > 0 then
|
123
|
+
# patstr = "(.*)\t" * (sslen-1) + "(.*)"
|
124
|
+
patstr = (["(.*)"] * sslen).join("\t")
|
125
|
+
/#{patstr}/ =~ ss.join("\t")
|
126
|
+
end
|
127
|
+
# 'set date #{$2}' のような記述の$変数にsubstringの値を代入
|
128
|
+
res[ambig] << [s, eval('%('+@commands[acceptno]+')')]
|
112
129
|
end
|
113
|
-
# 'set date #{$2}' のような記述の$変数にsubstringの値を代入
|
114
|
-
res[ambig] << [s, eval('%('+@commands[acceptno]+')')]
|
115
130
|
end
|
116
|
-
|
117
|
-
|
131
|
+
}
|
132
|
+
end
|
118
133
|
end
|
119
134
|
}
|
120
135
|
end
|
@@ -122,6 +137,8 @@ module ReExpand
|
|
122
137
|
break if newlist.length == 0
|
123
138
|
lists << newlist
|
124
139
|
break if res[0].length > 100
|
140
|
+
# loopcount += 1
|
141
|
+
#end
|
125
142
|
}
|
126
143
|
[res[0], res[1], res[2]]
|
127
144
|
end
|
data/lib/re_expand.rb
CHANGED
@@ -1,51 +1,33 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
1
|
+
# coding: utf-8
|
2
|
+
require "re_expand/version"
|
4
3
|
|
5
|
-
module
|
6
|
-
|
4
|
+
module ExpandRuby
|
5
|
+
# Your code goes here...
|
7
6
|
end
|
8
7
|
|
9
|
-
require 'Generator'
|
10
|
-
require 'Node'
|
11
|
-
require 'Scanner'
|
12
|
-
|
13
|
-
# require 'asearch'
|
14
|
-
|
8
|
+
require 're_expand/Generator'
|
9
|
+
require 're_expand/Node'
|
10
|
+
require 're_expand/Scanner'
|
11
|
+
|
15
12
|
class String
|
16
|
-
#
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
#
|
14
|
+
# restr.expand { |a| ... }
|
15
|
+
# restr.expand(' abc '){ |a| ... } パタンを指定
|
16
|
+
# restr.expand(' abc ',1){ |a| ... } 許容曖昧度を指定
|
17
|
+
#
|
18
|
+
def expand(filterpat=' ',ambig=0,&block)
|
19
|
+
g = ExpandRuby::Generator.new
|
20
|
+
g.add(self,'')
|
20
21
|
strings = []
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
|
23
|
+
if block_given? then
|
24
|
+
g.generate(filterpat,ambig,&block)
|
25
|
+
else
|
25
26
|
m = g.generate(filterpat)
|
26
27
|
matched = m[0].length > 0 ? m[0] : m[1].length > 0 ? m[1] : m[2]
|
27
28
|
strings = matched.collect { |r|
|
28
29
|
r[0]
|
29
30
|
}
|
30
|
-
else
|
31
|
-
matched = g.generate(' ')[0]
|
32
|
-
if filterpat.class == Regexp then
|
33
|
-
matched = matched.find_all { |r|
|
34
|
-
filterpat.match(r[0])
|
35
|
-
}
|
36
|
-
end
|
37
|
-
strings = matched.collect { |r|
|
38
|
-
r[0]
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
if block_given? then
|
43
|
-
matched.each { |m|
|
44
|
-
yield m[0], m[1].split(/\t/)
|
45
|
-
}
|
46
|
-
else
|
47
|
-
strings
|
48
31
|
end
|
49
32
|
end
|
50
33
|
end
|
51
|
-
|
metadata
CHANGED
@@ -1,151 +1,114 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: re_expand
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 6
|
10
|
-
version: 0.0.6
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Toshiyuki Masui
|
14
8
|
autorequire:
|
15
|
-
bindir:
|
9
|
+
bindir: exe
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
hash: 29
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
- 0
|
32
|
-
- 1
|
33
|
-
version: 0.0.1
|
34
|
-
type: :runtime
|
35
|
-
version_requirements: *id001
|
36
|
-
- !ruby/object:Gem::Dependency
|
37
|
-
name: rdoc
|
11
|
+
date: 2016-04-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
38
21
|
prerelease: false
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
49
34
|
type: :development
|
50
|
-
version_requirements: *id002
|
51
|
-
- !ruby/object:Gem::Dependency
|
52
|
-
name: newgem
|
53
35
|
prerelease: false
|
54
|
-
|
55
|
-
|
56
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
57
45
|
- - ">="
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
|
60
|
-
segments:
|
61
|
-
- 1
|
62
|
-
- 5
|
63
|
-
- 3
|
64
|
-
version: 1.5.3
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
65
48
|
type: :development
|
66
|
-
version_requirements: *id003
|
67
|
-
- !ruby/object:Gem::Dependency
|
68
|
-
name: hoe
|
69
49
|
prerelease: false
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: asearch
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.0.1
|
80
62
|
type: :development
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.0.1
|
69
|
+
description: Generates all the text strings that match the given regexp.Expand RegExp.
|
70
|
+
email:
|
86
71
|
- masui@pitecan.com
|
87
72
|
executables: []
|
88
|
-
|
89
73
|
extensions: []
|
90
|
-
|
91
|
-
|
92
|
-
-
|
93
|
-
-
|
94
|
-
-
|
95
|
-
|
96
|
-
-
|
97
|
-
- Manifest.txt
|
98
|
-
- PostInstall.txt
|
99
|
-
- README.rdoc
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- Makefile
|
80
|
+
- README.md
|
100
81
|
- Rakefile
|
82
|
+
- bin/console
|
83
|
+
- bin/setup
|
84
|
+
- expand_ruby.gemspec
|
101
85
|
- lib/re_expand.rb
|
102
|
-
- lib/Generator.rb
|
103
|
-
- lib/Node.rb
|
104
|
-
- lib/Scanner.rb
|
105
|
-
-
|
106
|
-
|
107
|
-
|
108
|
-
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
homepage: http://github.com/masui/expand-ruby
|
114
|
-
licenses: []
|
115
|
-
|
116
|
-
post_install_message: PostInstall.txt
|
117
|
-
rdoc_options:
|
118
|
-
- --main
|
119
|
-
- README.rdoc
|
120
|
-
require_paths:
|
86
|
+
- lib/re_expand/Generator.rb
|
87
|
+
- lib/re_expand/Node.rb
|
88
|
+
- lib/re_expand/Scanner.rb
|
89
|
+
- lib/re_expand/version.rb
|
90
|
+
homepage: https://github.com/masui/expand_ruby
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
121
97
|
- lib
|
122
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
-
|
124
|
-
requirements:
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
125
100
|
- - ">="
|
126
|
-
- !ruby/object:Gem::Version
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
version: "0"
|
131
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
-
none: false
|
133
|
-
requirements:
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
134
105
|
- - ">="
|
135
|
-
- !ruby/object:Gem::Version
|
136
|
-
|
137
|
-
segments:
|
138
|
-
- 0
|
139
|
-
version: "0"
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
140
108
|
requirements: []
|
141
|
-
|
142
|
-
|
143
|
-
rubygems_version: 1.8.23
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.2.2
|
144
111
|
signing_key:
|
145
|
-
specification_version:
|
146
|
-
summary: Generates all the text strings
|
147
|
-
test_files:
|
148
|
-
- test/test_generator.rb
|
149
|
-
- test/test_helper.rb
|
150
|
-
- test/test_re_expand.rb
|
151
|
-
- test/test_scanner.rb
|
112
|
+
specification_version: 4
|
113
|
+
summary: Generates all the text strings that match the given regexp.Expand RegExp.
|
114
|
+
test_files: []
|
data/.gemtest
DELETED
File without changes
|
data/History.txt
DELETED
data/Manifest.txt
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
History.txt
|
2
|
-
Manifest.txt
|
3
|
-
PostInstall.txt
|
4
|
-
README.rdoc
|
5
|
-
Rakefile
|
6
|
-
lib/re_expand.rb
|
7
|
-
lib/Generator.rb
|
8
|
-
lib/Node.rb
|
9
|
-
lib/Scanner.rb
|
10
|
-
script/console
|
11
|
-
script/destroy
|
12
|
-
script/generate
|
13
|
-
test/test_helper.rb
|
14
|
-
test/test_re_expand.rb
|
15
|
-
test/test_generator.rb
|
16
|
-
test/test_re_expand.rb
|
17
|
-
test/test_scanner.rb
|
18
|
-
|
data/PostInstall.txt
DELETED
data/README.rdoc
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
= re_expand
|
2
|
-
|
3
|
-
* http://github.com/masui/expand-ruby
|
4
|
-
|
5
|
-
== DESCRIPTION:
|
6
|
-
|
7
|
-
Generates all the text strings which match the given regexp.
|
8
|
-
If a filter pattern is given, the output is filtered by the pattern.
|
9
|
-
|
10
|
-
== SYNOPSIS:
|
11
|
-
|
12
|
-
require 're_expand'
|
13
|
-
"test (a|b|c)".expand { |s,a|
|
14
|
-
puts s
|
15
|
-
}
|
16
|
-
# "test a", "test b", ...
|
17
|
-
"(a|b)(1|2)".expand
|
18
|
-
# => ['a1', 'a2', 'b1', 'b2']
|
19
|
-
|
20
|
-
== LICENSE:
|
21
|
-
|
22
|
-
(The MIT License)
|
23
|
-
|
24
|
-
Copyright (c) 2012 Toshiyuki Masui
|
25
|
-
|
26
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
27
|
-
a copy of this software and associated documentation files (the
|
28
|
-
'Software'), to deal in the Software without restriction, including
|
29
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
30
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
31
|
-
permit persons to whom the Software is furnished to do so, subject to
|
32
|
-
the following conditions:
|
33
|
-
|
34
|
-
The above copyright notice and this permission notice shall be
|
35
|
-
included in all copies or substantial portions of the Software.
|
36
|
-
|
37
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
38
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
39
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
40
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
41
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
42
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
43
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/script/console
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# File: script/console
|
3
|
-
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
-
|
5
|
-
libs = " -r irb/completion"
|
6
|
-
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
-
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
-
libs << " -r #{File.dirname(__FILE__) + '/../lib/re_expand.rb'}"
|
9
|
-
puts "Loading re_expand gem"
|
10
|
-
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubigen'
|
6
|
-
rescue LoadError
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubigen'
|
9
|
-
end
|
10
|
-
require 'rubigen/scripts/destroy'
|
11
|
-
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
-
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubigen'
|
6
|
-
rescue LoadError
|
7
|
-
require 'rubygems'
|
8
|
-
require 'rubigen'
|
9
|
-
end
|
10
|
-
require 'rubigen/scripts/generate'
|
11
|
-
|
12
|
-
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
-
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
-
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/test/test_generator.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
module ReExpand
|
4
|
-
class GeneratorTest < Test::Unit::TestCase
|
5
|
-
def setup
|
6
|
-
end
|
7
|
-
|
8
|
-
def teardown
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_clock
|
12
|
-
g = Generator.new
|
13
|
-
g.add '(時計|時間|時刻)を(0|1|2|3|4|5|6|7|8|9|10|11|12)時に(セットする|設定する|あわせる)', 'set time #{$2}:00'
|
14
|
-
res = g.generate(' 10 ')
|
15
|
-
assert res[0].member?(['時刻を10時に設定する','set time 10:00'])
|
16
|
-
assert res[0].member?(['時計を10時にセットする','set time 10:00'])
|
17
|
-
assert !res[0].member?(['時計を8時にセットする','set time 8:00'])
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_substring
|
21
|
-
g = Generator.new
|
22
|
-
g.add '(a)bcd(e(fg)h)i(jk)', '#{$1}/#{$2}/#{$3}/#{$4}'
|
23
|
-
res = g.generate(' b ')
|
24
|
-
assert res[0].member?(['abcdefghijk', 'a/efgh/fg/jk'])
|
25
|
-
assert !res[0].member?(['abcdefghijk', 'a/fgh/fg/jk'])
|
26
|
-
g.add '(ab|cd)efg(hij|klm)n', '#{$1}/#{$2}'
|
27
|
-
res = g.generate(' ef ')
|
28
|
-
assert res[0].member?(['abefghijn', 'ab/hij'])
|
29
|
-
assert res[0].member?(['cdefgklmn', 'cd/klm'])
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
data/test/test_helper.rb
DELETED
data/test/test_re_expand.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require File.dirname(__FILE__) + '/test_helper.rb'
|
3
|
-
|
4
|
-
module ReExpand
|
5
|
-
class TestReExpand < Test::Unit::TestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_truth
|
11
|
-
assert true
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_array
|
15
|
-
e = "(月|火|水|木|金)曜(1|2|3|4|5|6)限".expand
|
16
|
-
assert_equal e.class, Array
|
17
|
-
assert_equal e.length, 30
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_2
|
21
|
-
"(月|火|水|木|金)曜(1|2|3|4|5|6)限".expand { |s,a|
|
22
|
-
assert_equal a.length, 2
|
23
|
-
}
|
24
|
-
|
25
|
-
e = "(月|火|水|木|金)曜(1|2|3|4|5|6)限".expand(' 1 ')
|
26
|
-
assert_equal e.length, 5
|
27
|
-
|
28
|
-
'(ab|cd)*'.expand(/bc/){ |s,a|
|
29
|
-
assert_equal a.length, 1
|
30
|
-
assert s =~ /abcd/
|
31
|
-
}
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
end
|
data/test/test_scanner.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
module ReExpand
|
4
|
-
class ScannerTest < Test::Unit::TestCase
|
5
|
-
def setup
|
6
|
-
end
|
7
|
-
|
8
|
-
def teardown
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_1
|
12
|
-
s = Scanner.new('a*d')
|
13
|
-
assert_equal s.gettoken, 'a'
|
14
|
-
assert_equal s.gettoken, '*'
|
15
|
-
assert_equal s.gettoken, 'd'
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_2
|
19
|
-
s = Scanner.new('a+d')
|
20
|
-
assert_equal s.gettoken, 'a'
|
21
|
-
assert_equal s.gettoken, '+'
|
22
|
-
assert_equal s.gettoken, 'd'
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_3
|
26
|
-
s = Scanner.new('ab*cd')
|
27
|
-
assert_equal s.gettoken, 'ab'
|
28
|
-
assert_equal s.gettoken, '*'
|
29
|
-
assert_equal s.gettoken, 'cd'
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_4
|
33
|
-
s = Scanner.new("(a\tb|c\td)")
|
34
|
-
assert_equal s.gettoken, "("
|
35
|
-
assert_equal s.gettoken, "a\tb"
|
36
|
-
assert_equal s.gettoken, '|'
|
37
|
-
assert_equal s.gettoken, "c\td"
|
38
|
-
assert_equal s.gettoken, ')'
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|