VB.NETのソースを解析するためのプログラム
VB.NETのソースを解析するためのプログラム。
指定したフォルダに存在する.vbファイルのクラス名とプロパティ名、メソッド名を出力する。
- vbAnalyzer.rb
#VB情報クラス class VbClass attr_accessor :cls, :subs, :funcs, :props, :enum def initialize @subs = Array.new @funcs = Array.new @props = Array.new end end #VB情報メンバー class Member attr_accessor :scope, :name def initialize(name, scope) @name, @scope = name, scope end end #ディレクトリ内のvbファイル一覧 #Vbを分析するクラス class VbAnalizer def initialize(dir) @dir = dir end #読み込む def read @clsList = Array.new Dir.glob("#{@dir}/*.vb").each{|name| file = open(name) vb = VbClass.new vb.cls = File.basename(file.path, ".vb") file.each_line{ |l| #scope scope = "" if (l.match("(Private|Public|Protected)")) scope = $1 end #プロパティ if (l.match("\sProperty\s+([a-zA-Z]+)\(\)")) vb.props << Member.new($1, scope) end #Sub if (l.match("\sSub\s+([a-zA-Z]+)\(\)")) vb.subs << Member.new($1, scope) end #Function if (l.match("\sFunction\s+([a-zA-Z]+)\(\)")) vb.funcs << Member.new($1, scope) end } file.close() @clsList << vb } return @clsList end #書き出す def out @clsList.each{|c| print c.cls c.props.each{|e| puts " #{e.scope} property #{e.name}" } c.subs.each{|e| puts " #{e.scope} sub #{e.name}" } c.funcs.each{|e| puts " #{e.scope} function #{e.name}" } puts } end end path = ARGV[0] unless File.directory?(path) raise IOError.new("#{path} is not a directory.") end analizer = VbAnalizer.new(path) analizer.read analizer.out
使い方
ruby vbAnalyzer.rb c:\vbdir > vbText.txt