cedlemo f53e91195c Update README | 9 jaren geleden | |
---|---|---|
app | 10 jaren geleden | |
ext | 9 jaren geleden | |
lib | 9 jaren geleden | |
swig | 9 jaren geleden | |
test | 9 jaren geleden | |
README.md | 9 jaren geleden | |
Rakefile | 9 jaren geleden | |
TODO | 9 jaren geleden | |
rtruckboris-1.0.1.gem | 9 jaren geleden | |
rtruckboris.gemspec | 9 jaren geleden |
With rtruckboris, you can easily parse C headers files in pure Ruby.
#!/usr/bin/env ruby
require 'rtruckboris'
parser = Rtruckboris::HeaderParser.new("a_file.h", ["/usr/include"])
parser.parse
functions = parser.functions
puts "Functions number : #{functions.size}"
functions.each do |f|
puts "Name : #{f.name}"
puts "Return : #{f.return.name}"
params = f.parameters
puts "\t #{params.size.to_s} parameters :"
params.each do |p|
puts "\t\t#{p.type.name} #{p.name}"
if(!p.type.is_canonical)
puts "\t\t\t#{p.type.canonical_type.name}"
end
end
end
functions.each do |f|
puts f.raw(parser.source_manager,parser.lang_opts)
end
rtruckboris is a ruby extension for the truckboris library so you need to install it (https://github.com/cedlemo/truckboris) and its dependencies (LLVM and Clang >= 3.4 to 3.8).
You will need to install :
When this is done, clone this repository with:
git clone https://github.com/cedlemo/rtruckboris
First (re)generate the extension source code via swig with:
rake swig
Then create the gem for your platform:
gem build rtruckboris.gemspec
You can now install the rtruckboris gem with:
gem install rtruckboris-x.x.x.gem
a lot of examples can be found in the test lib. I use those files when I test truckboris functionnalities you have two ways to try them:
rake swig
rake compile
Then you can use each files in the directory (be sure to be in this directory
in order to launch those files.
Just modify the require
line:
require File.dirname(FILE) + "/../lib/rtruckboris/rtruckboris"
with
require 'rtruckboris'
Cedlemo