Class | RDoc::Fortran95parser
In: | rdoc/parsers/parse_f95.rb
Parent: | Object

### Methods

find_comments new progress scan

### Public Class methods

new(top_level, file_name, body, options, stats)

prepare to parse a Fortran 95 file

[Source]

    # File rdoc/parsers/parse_f95.rb, line 35
        def initialize(top_level, file_name, body, options, stats)
          @body = body
          @stats = stats
          @options = options
          @top_level = top_level
          @progress = $stderr unless options.quiet
        end

### Public Instance methods

find_comments(text)

[Source]

    # File rdoc/parsers/parse_f95.rb, line 97
        def find_comments text
          lines = text.split("\n").reverse
          comment_block = Array.new
          lines.each do |line|
            break if line =~ /^\s*\w/
            comment_block.unshift line.sub(/^!\s?/,"")
          end
          nice_lines = comment_block.join("\n").split "\n\s*\n"
          nice_lines.shift
          nice_lines.shift
          nice_lines.shift
        end

progress(char)

[Source]

    # File rdoc/parsers/parse_f95.rb, line 110
        def progress(char)
          unless @options.quiet
            @progress.print(char)
            @progress.flush
          end
        end

scan()

devine code constructs

[Source]

    # File rdoc/parsers/parse_f95.rb, line 44
        def scan

          # modules and programs
          if @body =~ /^(module|program)\s+(\w+)/i
            progress "m"
            f9x_module = @top_level.add_module NormalClass, $2
            f9x_module.record_location @top_level
            first_comment, second_comment = $`.gsub(/^!\s?/,"").split "\n\s*\n"
            if second_comment
              @top_level.comment = first_comment if first_comment
              f9x_module.comment = second_comment
            else
              f9x_module.comment = first_comment if first_comment
            end
          end

          # use modules
          remaining_code = @body
          while remaining_code =~ /^\s*use\s+(\w+)/i
            remaining_code = $~.post_match
            progress "."
            f9x_module.add_include Include.new($1, "") if f9x_module
          end

          # subroutines
          remaining_code = @body
          while remaining_code =~ /^\s*subroutine\s+(\w+)\s*\((.*?)\)/im
            remaining_code = $~.post_match
            subroutine = AnyMethod.new("Text", $1)
            subroutine.singleton = false

            prematchText = $~.pre_match
            params = $2
            params.gsub!(/&/,'')
            subroutine.params = params
            comment = find_comments prematchText
            subroutine.comment = comment if comment

            subroutine.start_collecting_tokens
            remaining_code =~ /^\s*end\s+subroutine/i
            code = "subroutine #{subroutine.name} (#{subroutine.params})\n"
            code += $~.pre_match
            code += "\nend subroutine\n"
            subroutine.add_token Token.new(1,1).set_text(code)

            progress "s"
            f9x_module.add_method subroutine if f9x_module
          end

          @top_level

        end

[Validate]