class RDoc::TomDoc
基于 TomDoc
1.0.0-rc1 (02adef9b5a) 的 TomDoc
解析器
TomDoc
规范可以在 tomdoc.org 找到。
要选择 TomDoc
作为您唯一的默认格式,请参阅 RDoc::Options
的已保存选项,了解如何设置 .rdoc_options
文件以存储您的项目默认设置。
此解析器与规范之间存在一些差异。我们尽最大努力尽可能遵循规范,但做出了一些偏离的选择。
当违反 MUST 或 MUST NOT 时,未来版本的 RDoc
将发出警告,并且在违反 SHOULD 或 SHOULD NOT 时可能会发出警告。RDoc
始终会尝试发出文档,即使给定无效的 TomDoc
。
以下是此解析器当前做出的一些实现选择
此解析器允许 rdoc 风格的内联标记,但您不应依赖它。
此解析器允许在注释和方法主体之间存在空格。
此解析器不要求为可选参数描述默认值。
此解析器不检查各章节的顺序。“示例”章节可能位于“参数”章节之前。
公共
↑ 顶部公共类方法
源码
# File lib/rdoc/tom_doc.rb, line 124 def initialize super @section = nil @seen_returns = false end
创建一个新的 TomDoc
解析器。另请参阅 RDoc::Markup::parse
调用超类方法
源码
# File lib/rdoc/tom_doc.rb, line 78 def self.parse text parser = new parser.tokenize text doc = RDoc::Markup::Document.new parser.parse doc doc end
从文本中解析 TomDoc
- text
-
一个包含 TomDoc 格式文本的
String
。
示例¶ ↑
RDoc::TomDoc.parse <<-TOMDOC This method does some things Returns nothing. TOMDOC # => #<RDoc::Markup::Document:0xXXX @parts=[...], @file=nil>
返回值¶ ↑
返回一个 RDoc::Markup::Document,表示 TomDoc
格式。
内部
↑ 顶部属性
令牌访问器
公共类方法
源码
# File lib/rdoc/tom_doc.rb, line 94 def self.signature comment return unless comment.tomdoc? document = comment.parse signature = nil found_heading = false found_signature = false document.parts.delete_if do |part| next false if found_signature found_heading ||= RDoc::Markup::Heading === part && part.text == 'Signature' next false unless found_heading next true if RDoc::Markup::BlankLine === part if RDoc::Markup::Verbatim === part then signature = part found_signature = true end end signature and signature.text end
提取“签名”部分的 方法签名
- comment
-
一个
RDoc::Comment
,将被解析并提取签名
返回值¶ ↑
返回一个包含签名的 String
,如果不存在则返回 nil
公共实例方法
源码
源码
# File lib/rdoc/tom_doc.rb, line 167 def build_paragraph margin p :paragraph_start => margin if @debug paragraph = RDoc::Markup::Paragraph.new until @tokens.empty? do type, data, = get case type when :TEXT then @section = 'Returns' if data =~ /\A(Returns|Raises)/ paragraph << data when :NEWLINE then if :TEXT == peek_token[0] then # Lines beginning with 'Raises' in the Returns section should not be # treated as multiline text if 'Returns' == @section and peek_token[1].start_with?('Raises') then break else paragraph << ' ' end else break end else unget break end end p :paragraph_end => margin if @debug paragraph end
从令牌流构建段落
- margin
-
未使用
返回值¶ ↑
返回一个 RDoc::Markup::Paragraph。
源码
源码
# File lib/rdoc/tom_doc.rb, line 225 def tokenize text text = text.sub(/\A(Public|Internal|Deprecated):\s+/, '') setup_scanner text until @s.eos? do pos = @s.pos # leading spaces will be reflected by the column of the next token # the only thing we loose are trailing spaces at the end of the file next if @s.scan(/ +/) @tokens << case when @s.scan(/\r?\n/) then token = [:NEWLINE, @s.matched, *pos] @s.newline! token when @s.scan(/(Examples|Signature)$/) then @tokens << [:HEADER, 3, *pos] [:TEXT, @s[1], *pos] when @s.scan(/([:\w][\w\[\]]*)[ ]+- /) then [:NOTE, @s[1], *pos] else @s.scan(/.*/) [:TEXT, @s.matched.sub(/\r$/, ''), *pos] end end self end
将文本转换为令牌的 Array
- text
-
一个包含 TomDoc 格式文本的
String
。
返回值¶ ↑
返回 self。