Created
November 14, 2011 22:02
-
-
Save benben/1365341 to your computer and use it in GitHub Desktop.
parsing c++ code tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'pp' | |
OF_DIR = '/home/ben/code/openFrameworks/libs/openFrameworks' | |
classes = {} | |
class_content = "" | |
Dir[OF_DIR + "/**/*.h"].each do |file| | |
in_class = false | |
in_comment = false | |
bracket_level = 0 | |
class_name = "" | |
File.readlines(file).each do |line| | |
in_comment = true if line.match(/\/\*/) | |
in_comment = false if line.match(/\*\//) | |
if in_class and bracket_level > 0 and !in_comment | |
bracket_level += 1 if line.match(/{/) | |
bracket_level -= 1 if line.match(/}/) | |
class_content += line.gsub(/\/\/.*\n/,"").gsub(/\t/," ") | |
end | |
if bracket_level == 0 and class_content != "" | |
in_class = false | |
classes[class_name] = class_content | |
class_content = "" | |
end | |
if line.match(/class\s(\w+)\s*[:|{]/) | |
class_name = $1 | |
bracket_level = 1 | |
in_class = true | |
end | |
end | |
end | |
key = "public" | |
# "ofVideoPlayer" => {"public" => "...", "private" => "...", protected => "..."} | |
classes.each do |k,v| | |
h = Hash.new("") | |
v.each_line do |line| | |
key = "protected" if line.match /protected\s*:/ | |
key = "private" if line.match /private\s*:/ | |
h[key] += line.gsub(/\n/,"") unless line.match /public\s*:|protected\s*:|private\s*:/ | |
end | |
h.each do |kk,vv| | |
h[kk] = vv.split(";").map!{|n| n.strip} | |
end | |
key = "public" | |
classes[k] = h | |
end | |
pp classes | |
pp classes.count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment