Class: RubyHeaderParser::Parser
- Inherits:
-
Object
- Object
- RubyHeaderParser::Parser
- Defined in:
- lib/ruby_header_parser/parser.rb
Overview
parse ruby.h
using ctags
Constant Summary collapse
- DEFAULT_HEADER_FILE =
"#{RbConfig::CONFIG["rubyhdrdir"]}/ruby.h".freeze
- DEFAULT_INCLUDE_PATHS =
[ RbConfig::CONFIG["rubyarchhdrdir"], RbConfig::CONFIG["rubyhdrdir"], ].freeze
Instance Attribute Summary collapse
- #config ⇒ RubyHeaderParser::Config readonly
- #dist_preprocessed_header_file ⇒ String readonly
- #header_file ⇒ String readonly
- #include_paths ⇒ Array<String> readonly
Instance Method Summary collapse
- #extract_enum_definitions ⇒ Array<RubyHeaderParser::EnumDefinition>
- #extract_function_definitions ⇒ Array<RubyHeaderParser::FunctionDefinition>
- #extract_static_inline_function_definitions ⇒ Array<RubyHeaderParser::FunctionDefinition>
- #extract_struct_definitions ⇒ Array<RubyHeaderParser::StructDefinition>
- #extract_type_definitions ⇒ Array<RubyHeaderParser::TyperefDefinition>
-
#initialize(dist_preprocessed_header_file: nil, header_file: DEFAULT_HEADER_FILE, include_paths: DEFAULT_INCLUDE_PATHS, config_file: nil) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(dist_preprocessed_header_file: nil, header_file: DEFAULT_HEADER_FILE, include_paths: DEFAULT_INCLUDE_PATHS, config_file: nil) ⇒ Parser
Note:
dist_preprocessed_header_file
is used as the output destination for temporary files when the parser is executed
Note:
See CONFIG.md for config file details
Returns a new instance of Parser.
39 40 41 42 43 44 45 46 47 |
# File 'lib/ruby_header_parser/parser.rb', line 39 def initialize(dist_preprocessed_header_file: nil, header_file: DEFAULT_HEADER_FILE, include_paths: DEFAULT_INCLUDE_PATHS, config_file: nil) @header_file = header_file @include_paths = include_paths @dist_preprocessed_header_file = dist_preprocessed_header_file || File.join(Dir.tmpdir, "ruby_preprocessed.h") config_file ||= File.("../../config/default.yml", __dir__.to_s) @config = Config.new(config_file) end |
Instance Attribute Details
#config ⇒ RubyHeaderParser::Config (readonly)
20 21 22 |
# File 'lib/ruby_header_parser/parser.rb', line 20 def config @config end |
#dist_preprocessed_header_file ⇒ String (readonly)
16 17 18 |
# File 'lib/ruby_header_parser/parser.rb', line 16 def dist_preprocessed_header_file @dist_preprocessed_header_file end |
#header_file ⇒ String (readonly)
8 9 10 |
# File 'lib/ruby_header_parser/parser.rb', line 8 def header_file @header_file end |
#include_paths ⇒ Array<String> (readonly)
12 13 14 |
# File 'lib/ruby_header_parser/parser.rb', line 12 def include_paths @include_paths end |
Instance Method Details
#extract_enum_definitions ⇒ Array<RubyHeaderParser::EnumDefinition>
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/ruby_header_parser/parser.rb', line 93 def extract_enum_definitions stdout = ("--c-kinds=e --fields=+n") name_to_definitions = stdout.each_line.with_object({}) do |line, hash| parts = line.split("\t") enum_name = Util.find_field(parts, "enum") next unless enum_name value = parts[0] next unless config.should_generate_enum?(enum_name) hash[enum_name] ||= EnumDefinition.new(name: enum_name) hash[enum_name].values << value end name_to_definitions.values end |
#extract_function_definitions ⇒ Array<RubyHeaderParser::FunctionDefinition>
50 51 52 |
# File 'lib/ruby_header_parser/parser.rb', line 50 def extract_function_definitions __extract_function_definitions(c_kinds: "p", kind: "p", is_parse_multiline_definition: true) end |
#extract_static_inline_function_definitions ⇒ Array<RubyHeaderParser::FunctionDefinition>
55 56 57 |
# File 'lib/ruby_header_parser/parser.rb', line 55 def extract_static_inline_function_definitions __extract_function_definitions(c_kinds: "+p-d", kind: "f", is_parse_multiline_definition: false) end |
#extract_struct_definitions ⇒ Array<RubyHeaderParser::StructDefinition>
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ruby_header_parser/parser.rb', line 60 def extract_struct_definitions stdout = ("--c-kinds=s --fields=+n") stdout.each_line.with_object([]) do |line, definitions| parts = line.split("\t") struct_name = parts[0] next unless config.should_generate_struct?(struct_name) definitions << StructDefinition.new( name: struct_name, ) end end |
#extract_type_definitions ⇒ Array<RubyHeaderParser::TyperefDefinition>
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ruby_header_parser/parser.rb', line 76 def extract_type_definitions stdout = ("--c-kinds=t --fields=+n") stdout.each_line.with_object([]) do |line, definitions| parts = line.split("\t") type_name = parts[0] next unless config.should_generate_type?(type_name) definitions << TypeDefinition.new( name: type_name, ) end.uniq(&:name) end |