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 CHANGED
@@ -10,7 +10,7 @@ If a filter pattern is given, the output is filtered by the pattern.
10
10
  == SYNOPSIS:
11
11
 
12
12
  require 're_expand'
13
- "test (a|b|c)".expand { |s|
13
+ "test (a|b|c)".expand { |s,a|
14
14
  puts s
15
15
  }
16
16
  # "test a", "test b", ...
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('',startnode)
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
@@ -46,8 +46,7 @@ module ReExpand
46
46
 
47
47
  attr_reader :id
48
48
  attr_reader :trans
49
- attr :accept, true
50
- attr :pars, true
49
+ attr_accessor :accept,:pars
51
50
 
52
51
  def addTrans(pat,dest)
53
52
  t = Trans.new(pat,dest)
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 =~ /^[\(\|\)\*\?\[\]]$/ then
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.3'
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.collect { |m|
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('abc*def')
13
- assert_equal s.gettoken, 'abc'
12
+ s = Scanner.new('a*d')
13
+ assert_equal s.gettoken, 'a'
14
14
  assert_equal s.gettoken, '*'
15
- assert_equal s.gettoken, 'def'
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: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
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-04-30 00:00:00 Z
18
+ date: 2012-05-01 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rdoc