Add tags

Add tags to the following comment

Ripperを使ってみました。Ruby 1.9.0以上じゃないと動かないと思います。

AlphaConverter.newの第2引数以降で置換する変数を指定します。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'ripper'

class AlphaConverter<Ripper::Filter
  def initialize(src, *vars)
    super(src)
    @alpha_dict = {}
    vars.each do |o, n|
      @alpha_dict[o] = n
    end
  end

  def var_common(token, data)
    if @alpha_dict[token] then
      data << @alpha_dict[token]
    else
      data << token
    end
  end

  def on_default(event, token, data)
    data << token
  end

  # クラス変数
  def on_cvar(token, data)
    var_common(token, data)
  end

  # 大域変数
  def on_gvar(token, data)
    var_common(token, data)
  end

  # インスタンス変数
  def on_ivar(token, data)
    var_common(token, data)
  end 
 
  # ローカル変数
  def on_ident(token, data)
    var_common(token, data)
  end
end

print AlphaConverter.new(ARGF, ['event', 'ee'], ['@alpha_dict', '@ad']).parse('')

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...