method
parse_constant
v1_9_3_125 -
Show latest stable
- Class:
RDoc::Parser::Ruby
parse_constant(container, tk, comment)public
Parses a constant in context with comment
# File lib/rdoc/parser/ruby.rb, line 665
def parse_constant container, tk, comment
offset = tk.seek
line_no = tk.line_no
name = tk.name
skip_tkspace false
return unless name =~ /^\w+$/
eq_tk = get_tk
unless TkASSIGN === eq_tk then
unget_tk eq_tk
return false
end
nest = 0
get_tkread
tk = get_tk
if TkGT === tk then
unget_tk tk
unget_tk eq_tk
return false
end
rhs_name = ''
loop do
case tk
when TkSEMICOLON then
break if nest <= 0
when TkLPAREN, TkfLPAREN, TkLBRACE, TkfLBRACE, TkLBRACK, TkfLBRACK,
TkDO, TkIF, TkUNLESS, TkCASE, TkDEF, TkBEGIN then
nest += 1
when TkRPAREN, TkRBRACE, TkRBRACK, TkEND then
nest -= 1
when TkCOMMENT then
if nest <= 0 &&
(@scanner.lex_state == EXPR_END || [email protected]) then
unget_tk tk
break
end
when TkCONSTANT then
rhs_name << tk.name
if nest <= 0 and TkNL === peek_tk then
mod = if rhs_name =~ /^::/ then
RDoc::TopLevel.find_class_or_module rhs_name
else
container.find_module_named rhs_name
end
container.add_module_alias mod, name, @top_level if mod
break
end
when TkNL then
if nest <= 0 &&
(@scanner.lex_state == EXPR_END || [email protected]) then
unget_tk tk
break
end
when TkCOLON2, TkCOLON3 then
rhs_name << '::'
when nil then
break
end
tk = get_tk
end
res = get_tkread.gsub(/^[ \t]+/, '').strip
res = "" if res == ";"
con = RDoc::Constant.new name, res, comment
con.record_location @top_level
con.offset = offset
con.line = line_no
read_documentation_modifiers con, RDoc::CONSTANT_MODIFIERS
@stats.add_constant con
container.add_constant con
true
end Related methods
- Instance methods
- collect_first_comment
- error
- extract_call_seq
- get_bool
- get_class_or_module
- get_class_specification
- get_constant
- get_constant_with_optional_parens
- get_symbol_or_name
- look_for_directives_in
- make_message
- parse_alias
- parse_attr
- parse_attr_accessor
- parse_call_parameters
- parse_class
- parse_comment
- parse_constant
- parse_include
- parse_meta_attr
- parse_meta_method
- parse_method
- parse_method_or_yield_parameters
- parse_method_parameters
- parse_module
- parse_require
- parse_statements
- parse_symbol_arg
- parse_symbol_in_arg
- parse_top_level_statements
- parse_visibility
- parse_yield
- read_directive
- read_documentation_modifiers
- remove_private_comments
- scan
- skip_for_variable
- skip_method
- skip_optional_do_after_expression
- skip_tkspace_comment
- warn
- Class methods
- new