diff options
Diffstat (limited to 'lib/rdoc/parser')
-rw-r--r-- | lib/rdoc/parser/c.rb | 55 | ||||
-rw-r--r-- | lib/rdoc/parser/changelog.rb | 15 | ||||
-rw-r--r-- | lib/rdoc/parser/ripper_state_lex.rb | 12 | ||||
-rw-r--r-- | lib/rdoc/parser/ruby.rb | 16 |
4 files changed, 73 insertions, 25 deletions
diff --git a/lib/rdoc/parser/c.rb b/lib/rdoc/parser/c.rb index 5695bf1acb..f8f238fd74 100644 --- a/lib/rdoc/parser/c.rb +++ b/lib/rdoc/parser/c.rb @@ -575,19 +575,18 @@ class RDoc::Parser::C < RDoc::Parser table = {} file_content.scan(%r{ ((?>/\*.*?\*/\s*)?) - ((?:(?:\w+)\s+)? - (?:intern\s+)?VALUE\s+(\w+) - \s*(?:\([^)]*\))(?:[^\);]|$)) + ((?:\w+\s+){0,2} VALUE\s+(\w+) + \s*(?:\([^\)]*\))(?:[^\);]|$)) | ((?>/\*.*?\*/\s*))^\s*(\#\s*define\s+(\w+)\s+(\w+)) | ^\s*\#\s*define\s+(\w+)\s+(\w+) }xm) do case - when $1 - table[$3] = [:func_def, $1, $2, $~.offset(2)] if !table[$3] || table[$3][0] != :func_def - when $4 - table[$6] = [:macro_def, $4, $5, $~.offset(5), $7] if !table[$6] || table[$6][0] == :macro_alias - when $8 - table[$8] ||= [:macro_alias, $9] + when name = $3 + table[name] = [:func_def, $1, $2, $~.offset(2)] if !(t = table[name]) || t[0] != :func_def + when name = $6 + table[name] = [:macro_def, $4, $5, $~.offset(5), $7] if !(t = table[name]) || t[0] == :macro_alias + when name = $8 + table[name] ||= [:macro_alias, $9] end end table @@ -757,17 +756,27 @@ class RDoc::Parser::C < RDoc::Parser def gen_const_table file_content table = {} @content.scan(%r{ - ((?>^\s*/\*.*?\*/\s+)) - rb_define_(\w+)\((?:\s*(?:\w+),)?\s* - "(\w+)"\s*, + (?<doc>(?>^\s*/\*.*?\*/\s+)) + rb_define_(?<type>\w+)\(\s*(?:\w+),\s* + "(?<name>\w+)"\s*, .*?\)\s*; + | (?<doc>(?>^\s*/\*.*?\*/\s+)) + rb_file_(?<type>const)\(\s* + "(?<name>\w+)"\s*, + .*?\)\s*; + | (?<doc>(?>^\s*/\*.*?\*/\s+)) + rb_curses_define_(?<type>const)\(\s* + (?<name>\w+) + \s*\)\s*; | Document-(?:const|global|variable):\s - ((?:\w+::)*\w+) - \s*?\n((?>.*?\*/)) + (?<name>(?:\w+::)*\w+) + \s*?\n(?<doc>(?>.*?\*/)) }mxi) do - case - when $1 then table[[$2, $3]] = $1 - when $4 then table[$4] = "/*\n" + $5 + name, doc, type = $~.values_at(:name, :doc, :type) + if type + table[[type, name]] = doc + else + table[name] = "/*\n" + doc end end table @@ -939,14 +948,13 @@ class RDoc::Parser::C < RDoc::Parser # "/* definition: comment */" form. The literal ':' and '\' characters # can be escaped with a backslash. if type.downcase == 'const' then - no_match, new_definition, new_comment = comment.text.split(/(\A.*):/) + if /\A(.+?)?:(?!\S)/ =~ comment.text + new_definition, new_comment = $1, $' - if no_match and no_match.empty? then - if new_definition.empty? then # Default to literal C definition + if !new_definition # Default to literal C definition new_definition = definition else - new_definition = new_definition.gsub("\:", ":") - new_definition = new_definition.gsub("\\", '\\') + new_definition = new_definition.gsub(/\\([\\:])/, '\1') end new_definition.sub!(/\A(\s+)/, '') @@ -1217,6 +1225,9 @@ class RDoc::Parser::C < RDoc::Parser @top_level end + ## + # Creates a RDoc::Comment instance. + def new_comment text = nil, location = nil, language = nil RDoc::Comment.new(text, location, language).tap do |comment| comment.format = @markup diff --git a/lib/rdoc/parser/changelog.rb b/lib/rdoc/parser/changelog.rb index 2a685d1d79..a046241870 100644 --- a/lib/rdoc/parser/changelog.rb +++ b/lib/rdoc/parser/changelog.rb @@ -216,12 +216,22 @@ class RDoc::Parser::ChangeLog < RDoc::Parser @top_level end + ## + # The extension for Git commit log + module Git + ## + # Parses auxiliary info. Currentry `base-url` to expand + # references is effective. + def parse_info(info) /^\s*base-url\s*=\s*(.*\S)/ =~ info @base_url = $1 end + ## + # Parses the entries in the Git commit logs + def parse_entries entries = [] @@ -244,6 +254,11 @@ class RDoc::Parser::ChangeLog < RDoc::Parser entries end + ## + # Returns a list of ChangeLog entries as + # RDoc::Parser::ChangeLog::Git::LogEntry list for the given + # +entries+. + def create_entries entries # git log entries have no strictly itemized style like the old # style, just assume Markdown. diff --git a/lib/rdoc/parser/ripper_state_lex.rb b/lib/rdoc/parser/ripper_state_lex.rb index 5492f08726..f6cefd0305 100644 --- a/lib/rdoc/parser/ripper_state_lex.rb +++ b/lib/rdoc/parser/ripper_state_lex.rb @@ -1,7 +1,12 @@ # frozen_string_literal: true require 'ripper' +## +# Wrapper for Ripper lex states + class RDoc::Parser::RipperStateLex + # :stopdoc: + # TODO: Remove this constants after Ruby 2.4 EOL RIPPER_HAS_LEX_STATE = Ripper::Filter.method_defined?(:state) @@ -368,7 +373,7 @@ class RDoc::Parser::RipperStateLex private def get_symbol_tk(tk) is_symbol = true symbol_tk = Token.new(tk.line_no, tk.char_no, :on_symbol) - if ":'" == tk[:text] or ':"' == tk[:text] + if ":'" == tk[:text] or ':"' == tk[:text] or tk[:text].start_with?('%s') tk1 = get_string_tk(tk) symbol_tk[:text] = tk1[:text] symbol_tk[:state] = tk1[:state] @@ -565,6 +570,9 @@ class RDoc::Parser::RipperStateLex tk end + # :startdoc: + + # New lexer for +code+. def initialize(code) @buf = [] @heredoc_queue = [] @@ -572,6 +580,7 @@ class RDoc::Parser::RipperStateLex @tokens = @inner_lex.parse([]) end + # Returns tokens parsed from +code+. def self.parse(code) lex = self.new(code) tokens = [] @@ -584,6 +593,7 @@ class RDoc::Parser::RipperStateLex tokens end + # Returns +true+ if lex state will be +END+ after +token+. def self.end?(token) (token[:state] & EXPR_END) end diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb index 2c8a19f608..85f1cd0391 100644 --- a/lib/rdoc/parser/ruby.rb +++ b/lib/rdoc/parser/ruby.rb @@ -180,6 +180,9 @@ class RDoc::Parser::Ruby < RDoc::Parser reset end + ## + # Return +true+ if +tk+ is a newline. + def tk_nl?(tk) :on_nl == tk[:kind] or :on_ignored_nl == tk[:kind] end @@ -786,8 +789,10 @@ class RDoc::Parser::Ruby < RDoc::Parser al.line = line_no read_documentation_modifiers al, RDoc::ATTR_MODIFIERS - context.add_alias al - @stats.add_alias al + if al.document_self or not @track_visibility + context.add_alias al + @stats.add_alias al + end al end @@ -1450,6 +1455,12 @@ class RDoc::Parser::Ruby < RDoc::Parser meth = RDoc::AnyMethod.new get_tkread, name look_for_directives_in meth, comment meth.singleton = single == SINGLE ? true : singleton + if singleton + # `current_line_visibility' is useless because it works against + # the normal method named as same as the singleton method, after + # the latter was defined. Of course these are different things. + container.current_line_visibility = :public + end record_location meth meth.line = line_no @@ -1773,6 +1784,7 @@ class RDoc::Parser::Ruby < RDoc::Parser nest = 1 save_visibility = container.visibility + container.visibility = :public unless current_method non_comment_seen = true |