| Class | RDoc::Fortran95parser |
| In: |
rdoc/parsers/parse_f95.rb
|
| Parent: | Object |
Methods
Public Class methods
prepare to parse a Fortran 95 file
# File rdoc/parsers/parse_f95.rb, line 35
35: def initialize(top_level, file_name, body, options, stats)
36: @body = body
37: @stats = stats
38: @options = options
39: @top_level = top_level
40: @progress = $stderr unless options.quiet
41: end
Public Instance methods
# File rdoc/parsers/parse_f95.rb, line 97
97: def find_comments text
98: lines = text.split("\n").reverse
99: comment_block = Array.new
100: lines.each do |line|
101: break if line =~ /^\s*\w/
102: comment_block.unshift line.sub(/^!\s?/,"")
103: end
104: nice_lines = comment_block.join("\n").split "\n\s*\n"
105: nice_lines.shift
106: nice_lines.shift
107: nice_lines.shift
108: end
# File rdoc/parsers/parse_f95.rb, line 110
110: def progress(char)
111: unless @options.quiet
112: @progress.print(char)
113: @progress.flush
114: end
115: end
devine code constructs
# File rdoc/parsers/parse_f95.rb, line 44
44: def scan
45:
46: # modules and programs
47: if @body =~ /^(module|program)\s+(\w+)/i
48: progress "m"
49: f9x_module = @top_level.add_module NormalClass, $2
50: f9x_module.record_location @top_level
51: first_comment, second_comment = $`.gsub(/^!\s?/,"").split "\n\s*\n"
52: if second_comment
53: @top_level.comment = first_comment if first_comment
54: f9x_module.comment = second_comment
55: else
56: f9x_module.comment = first_comment if first_comment
57: end
58: end
59:
60: # use modules
61: remaining_code = @body
62: while remaining_code =~ /^\s*use\s+(\w+)/i
63: remaining_code = $~.post_match
64: progress "."
65: f9x_module.add_include Include.new($1, "") if f9x_module
66: end
67:
68: # subroutines
69: remaining_code = @body
70: while remaining_code =~ /^\s*subroutine\s+(\w+)\s*\((.*?)\)/im
71: remaining_code = $~.post_match
72: subroutine = AnyMethod.new("Text", $1)
73: subroutine.singleton = false
74:
75: prematchText = $~.pre_match
76: params = $2
77: params.gsub!(/&/,'')
78: subroutine.params = params
79: comment = find_comments prematchText
80: subroutine.comment = comment if comment
81:
82: subroutine.start_collecting_tokens
83: remaining_code =~ /^\s*end\s+subroutine/i
84: code = "subroutine #{subroutine.name} (#{subroutine.params})\n"
85: code += $~.pre_match
86: code += "\nend subroutine\n"
87: subroutine.add_token Token.new(1,1).set_text(code)
88:
89: progress "s"
90: f9x_module.add_method subroutine if f9x_module
91: end
92:
93: @top_level
94:
95: end