本文简要介绍ruby语言中 RDoc::Parser类
的用法。
解析器是一个简单的类,它是 RDoc::Parser
的子类,并实现扫描以用解析的数据填充 RDoc::TopLevel
。
初始化方法接受一个 RDoc::TopLevel
来填充解析的内容、要解析的文件的名称、文件的内容、一个 RDoc::Options
对象和一个 RDoc::Stats
对象来通知用户已解析的项目。然后调用扫描方法来解析文件,并且必须返回 RDoc::TopLevel
对象。通过调用 super 这些项目将为您设置。
为了被 RDoc
使用,解析器需要注册它可以解析的文件扩展名。使用 ::parse_files_matching
注册扩展。
require 'rdoc'
class RDoc::Parser::Xyz < RDoc::Parser
parse_files_matching /\.xyz$/
def initialize top_level, file_name, content, options, stats
super
# extra initialization if needed
end
def scan
# parse file and fill in @top_level
end
end
相关用法
- Ruby Parser类用法及代码示例
- Ruby Parser.use_markup用法及代码示例
- Ruby Pathname.<=>用法及代码示例
- Ruby Pathname.children用法及代码示例
- Ruby Pathname.descend用法及代码示例
- Ruby Pathname.getwd用法及代码示例
- Ruby Pathname.ascend用法及代码示例
- Ruby Pathname.pwd用法及代码示例
- Ruby Pathname.+用法及代码示例
- Ruby Pathname.sub_ext用法及代码示例
- Ruby Pathname.glob用法及代码示例
- Ruby Pathname.entries用法及代码示例
- Ruby Pathname.join用法及代码示例
- Ruby Pathname.sub用法及代码示例
- Ruby Pathname类用法及代码示例
- Ruby Pathname.each_filename用法及代码示例
- Ruby Pathname.absolute?用法及代码示例
- Ruby Pathname.relative?用法及代码示例
- Ruby Pathname.each_child用法及代码示例
- Ruby PackageTask类用法及代码示例
- Ruby PrettyPrint.current_group用法及代码示例
- Ruby Process.groups用法及代码示例
- Ruby Process.wait2用法及代码示例
- Ruby Process.getpgrp用法及代码示例
- Ruby Proc.eql?用法及代码示例
注:本文由纯净天空筛选整理自ruby-lang.org大神的英文原创作品 Parser类。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。