re_expand 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -1
- data/lib/Generator.rb +8 -7
- data/lib/Node.rb +1 -2
- data/lib/Scanner.rb +2 -2
- data/lib/re_expand.rb +2 -2
- data/test/test_scanner.rb +17 -3
- metadata +4 -4
data/README.rdoc
CHANGED
data/lib/Generator.rb
CHANGED
@@ -26,12 +26,7 @@ module ReExpand
|
|
26
26
|
@accept = accept
|
27
27
|
@state = state
|
28
28
|
end
|
29
|
-
|
30
|
-
attr :id, true
|
31
|
-
attr :s, true
|
32
|
-
attr :substrings, true
|
33
|
-
attr :accept, true
|
34
|
-
attr :state, true
|
29
|
+
attr_accessor :id,:s,:substrings,:accept,:state
|
35
30
|
end
|
36
31
|
|
37
32
|
class Generator
|
@@ -194,8 +189,14 @@ module ReExpand
|
|
194
189
|
elsif t =~ /^[\+]$/ then
|
195
190
|
endnode.addTrans('',startnode)
|
196
191
|
elsif t =~ /^[\*]$/ then
|
192
|
+
n = Node.new
|
197
193
|
startnode.addTrans('',endnode)
|
198
|
-
endnode.addTrans('',
|
194
|
+
endnode.addTrans('',n)
|
195
|
+
n.addTrans('',startnode)
|
196
|
+
|
197
|
+
# ループがあるとマズいのか? 上のように修正すると動くようなのだが
|
198
|
+
#startnode.addTrans('',endnode)
|
199
|
+
#endnode.addTrans('',startnode)
|
199
200
|
else
|
200
201
|
s.ungettoken
|
201
202
|
end
|
data/lib/Node.rb
CHANGED
data/lib/Scanner.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
#
|
3
3
|
# 文字列から1トークンずつ取得
|
4
4
|
#
|
5
|
+
$KCODE = 'utf8' if RUBY_VERSION < "1.9"
|
5
6
|
|
6
|
-
$KCODE = 'utf8'
|
7
7
|
|
8
8
|
module ReExpand
|
9
9
|
class Scanner
|
@@ -26,7 +26,7 @@ module ReExpand
|
|
26
26
|
return ''
|
27
27
|
end
|
28
28
|
@t = @a[@p]
|
29
|
-
if @t =~ /^[\(\|\)
|
29
|
+
if @t =~ /^[\(\|\)\*\+\?\[\]]$/ then
|
30
30
|
@p += 1
|
31
31
|
return @t
|
32
32
|
elsif @t == '\\' then
|
data/lib/re_expand.rb
CHANGED
@@ -3,7 +3,7 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
3
3
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
4
4
|
|
5
5
|
module ReExpand
|
6
|
-
VERSION = '0.0.
|
6
|
+
VERSION = '0.0.4'
|
7
7
|
end
|
8
8
|
|
9
9
|
require 'Generator'
|
@@ -39,7 +39,7 @@ class String
|
|
39
39
|
end
|
40
40
|
|
41
41
|
if block_given? then
|
42
|
-
matched.
|
42
|
+
matched.each { |m|
|
43
43
|
yield m[0], m[1].split(/\t/)
|
44
44
|
}
|
45
45
|
else
|
data/test/test_scanner.rb
CHANGED
@@ -9,13 +9,27 @@ module ReExpand
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_1
|
12
|
-
s = Scanner.new('
|
13
|
-
assert_equal s.gettoken, '
|
12
|
+
s = Scanner.new('a*d')
|
13
|
+
assert_equal s.gettoken, 'a'
|
14
14
|
assert_equal s.gettoken, '*'
|
15
|
-
assert_equal s.gettoken, '
|
15
|
+
assert_equal s.gettoken, 'd'
|
16
16
|
end
|
17
17
|
|
18
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
|
19
33
|
s = Scanner.new("(a\tb|c\td)")
|
20
34
|
assert_equal s.gettoken, "("
|
21
35
|
assert_equal s.gettoken, "a\tb"
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: re_expand
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Toshiyuki Masui
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-05-01 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rdoc
|