lib/ffi/clang/comment.rb in ffi-clang-0.2.0 vs lib/ffi/clang/comment.rb in ffi-clang-0.2.1

- old
+ new

@@ -30,27 +30,45 @@ include Enumerable def self.build_from(comment) kind = Lib.comment_get_kind(comment) case kind - when :comment_full - FullComment.new comment - when :comment_paragraph - ParagraphComment.new comment + when :comment_null + Comment.new comment when :comment_text TextComment.new comment + when :comment_inline_command + InlineCommandComment.new comment + when :comment_html_start_tag + HTMLStartTagComment.new comment + when :comment_html_end_tag + HTMLEndTagComment.new comment + when :comment_paragraph + ParagraphComment.new comment when :comment_block_command BlockCommandComment.new comment when :comment_param_command ParamCommandComment.new comment - when :comment_null - Comment.new comment + when :comment_tparam_command + TParamCommandComment.new comment + when :comment_verbatim_block_command + VerbatimBlockCommandComment.new comment + when :comment_verbatim_block_line + VerbatimBlockLineComment.new comment + when :comment_verbatim_line + VerbatimLine.new comment + when :comment_full + FullComment.new comment else raise NotImplementedError, kind end end + def text + return "" + end + def initialize(comment) @comment = comment end def kind @@ -63,18 +81,63 @@ def child(n = 0) Comment.build_from Lib.comment_get_child(@comment, n) end + def children + num_children.times.map { |i| child(i) } + end + + def whitespace? + Lib.comment_is_whitespace(@comment) != 0 + end + + def has_trailing_newline? + Lib.inline_content_comment_has_trailing_newline(@comment) != 0 + end + def each(&block) - (0..num_children-1).map do |i| + num_children.times.map do |i| block.call(child(i)) end end end + class HTMLTagComment < Comment + def name + Lib.extract_string Lib.html_tag_comment_get_tag_name(@comment) + end + alias_method :tag, :name + + def text + Lib.extract_string Lib.html_tag_comment_get_as_string(@comment) + end + end + + class HTMLStartTagComment < HTMLTagComment + def self_closing? + Lib.html_start_tag_comment_is_self_closing(@comment) != 0 + end + + def num_attrs + Lib.html_start_tag_comment_get_num_attrs(@comment) + end + + def attrs + num_attrs.times.map { |i| + { + name: Lib.extract_string(Lib.html_start_tag_comment_get_attr_name(@comment, i)), + value: Lib.extract_string(Lib.html_start_tag_comment_get_attr_value(@comment, i)), + } + } + end + end + + class HTMLEndTagComment < HTMLTagComment + end + class ParagraphComment < Comment def text self.map(&:text).join("\n") end end @@ -83,53 +146,133 @@ def text Lib.extract_string Lib.text_comment_get_text(@comment) end end + class InlineCommandComment < Comment + def name + Lib.extract_string Lib.inline_command_comment_get_command_name(@comment) + end + + def render_kind + Lib.inline_command_comment_get_render_kind(@comment) + end + + def num_args + Lib.inline_command_comment_get_num_args(@comment) + end + + def args + num_args.times.map { |i| + Lib.extract_string Lib.inline_command_comment_get_arg_text(@comment, i) + } + end + + def text + args.join + end + end + class BlockCommandComment < Comment def name Lib.extract_string Lib.block_command_comment_get_command_name(@comment) end def paragraph Comment.build_from Lib.block_command_comment_get_paragraph(@comment) end - def comment + def text self.paragraph.text end + alias_method :comment, :text def num_args Lib.block_command_comment_get_num_args(@comment) end + + def args + num_args.times.map { |i| + Lib.extract_string Lib.block_command_comment_get_arg_text(@comment, i) + } + end end class ParamCommandComment < Comment def name Lib.extract_string Lib.param_command_comment_get_param_name(@comment) end - def comment - self.child.text + def text + self.map(&:text).join("") end + alias_method :comment, :text def valid_index? Lib.param_command_comment_is_param_index_valid(@comment) != 0 end def index Lib.param_command_comment_get_param_index(@comment) end + + def direction_explicit? + Lib.param_command_comment_is_direction_explicit(@comment) != 0 + end + + def direction + Lib.param_command_comment_get_direction(@comment) + end end + class TParamCommandComment < Comment + def text + self.child.text + end + alias_method :comment, :text + + def name + Lib.extract_string Lib.tparam_command_comment_get_param_name(@comment) + end + + def valid_position? + Lib.tparam_command_comment_is_param_position_valid(@comment) != 0 + end + + def depth + Lib.tparam_command_comment_get_depth(@comment) + end + + def index(depth = 0) + Lib.tparam_command_comment_get_index(@comment, depth) + end + end + + class VerbatimBlockCommandComment < Comment + def text + children.map(&:text).join("\n") + end + end + + class VerbatimBlockLineComment < Comment + def text + Lib.extract_string Lib.verbatim_block_line_comment_get_text(@comment) + end + end + + class VerbatimLine < Comment + def text + Lib.extract_string Lib.verbatim_line_comment_get_text(@comment) + end + end + class FullComment < Comment def to_html Lib.extract_string Lib.full_comment_get_as_html(@comment) end def to_xml Lib.extract_string Lib.full_comment_get_as_xml(@comment) end end - end end