Module: ScanHeader
Instance Method Summary collapse
- #ctype_canonical_form(ctype) ⇒ Object
- #parse_prototype(s, argnames = true) ⇒ Object
- #scan_header(header, ppdefs = nil, &block) ⇒ Object
- #scan_header_io(io, ppdefs = nil) ⇒ Object
Instance Method Details
#ctype_canonical_form(ctype) ⇒ Object
63 64 65 |
# File 'ext/lapack/extconf.rb', line 63 def ctype_canonical_form(ctype) ctype.gsub(%r!\*!, " * ").gsub(%r!\s+!, " ").strip end |
#parse_prototype(s, argnames = true) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'ext/lapack/extconf.rb', line 67 def parse_prototype(s, argnames = true) func, args = s.strip.gsub(%r!\s+!, " ").split(%r![\(\)]!) ret, name = func. strip. match(%r!^(\w[*\s\w]*[*\s])(\w+)$!). captures desc = {} desc[:name] = name desc[:return] = ctype_canonical_form(ret) desc[:args] = [] unless args == "" or args.strip == "void" args.split(",").each { |arg| arg.sub!(%r!\w+\s*$!, "") if argnames desc[:args].push(ctype_canonical_form(arg)) } end desc end |
#scan_header(header, ppdefs = nil, &block) ⇒ Object
106 107 108 109 110 |
# File 'ext/lapack/extconf.rb', line 106 def scan_header(header, ppdefs = nil, &block) File.open(header) { |file| scan_header_io(file, ppdefs, &block) } end |
#scan_header_io(io, ppdefs = nil) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'ext/lapack/extconf.rb', line 87 def scan_header_io(io, ppdefs = nil) s = io.read s.gsub!(%r!^\s*\#.*$!, "") s.gsub!(%r!//.*$!, "") s.gsub!(%r!/\*.*?\*/!m, "") if ppdefs s.gsub!(%r!\w+!) { |word| if ppdefs[word] ppdefs[word] else word end } end s.scan(%r!\w[*\w\s]*?\w+\s*\(.*?\)\s*\;!m) { |func| yield parse_prototype(func) } end |