Class: RDocF95::RubyParser

Inherits:
Object
  • Object
show all
Extended by:
ParserFactory
Includes:
TokenStream, RubyToken
Defined in:
lib/rdoc-f95/parsers/parse_rb.rb

Overview

Extract code elements from a source file, returning a TopLevel object containing the constituent file elements.

This file is based on rtags

Constant Summary

Constants included from RubyToken

RubyToken::EXPR_ARG, RubyToken::EXPR_BEG, RubyToken::EXPR_CLASS, RubyToken::EXPR_DOT, RubyToken::EXPR_END, RubyToken::EXPR_FNAME, RubyToken::EXPR_MID, RubyToken::NEWLINE_TOKEN, RubyToken::TkReading2Token, RubyToken::TkSymbol2Token, RubyToken::TokenDefinitions

Instance Method Summary collapse

Methods included from ParserFactory

alias_extension, can_parse, parse_files_matching, parser_for

Methods included from TokenStream

#add_token, #add_tokens, #pop_token, #start_collecting_tokens, #token_stream

Methods included from RubyToken

#Token, def_token, #set_token_position

Constructor Details

#initialize(top_level, file_name, content, options, stats) ⇒ RubyParser

Returns a new instance of RubyParser.



1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
# File 'lib/rdoc-f95/parsers/parse_rb.rb', line 1376

def initialize(top_level, file_name, content, options, stats)
  @options = options
  @stats   = stats
  @size = 0
  @token_listeners = nil
  @input_file_name = file_name
  @scanner = RubyLex.new content, @options
  @scanner.exception_on_syntax_error = false
  @top_level = top_level
  @progress = $stderr unless options.quiet
end

Instance Method Details

#scanObject



1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
# File 'lib/rdoc-f95/parsers/parse_rb.rb', line 1388

def scan
  @tokens = []
  @unget_read = []
  @read = []
  catch(:eof) do
    catch(:enddoc) do
      begin
        parse_toplevel_statements(@top_level)
      rescue Exception => e
        $stderr.puts "\n\n"
        $stderr.puts "RDoc failure in #@input_file_name at or around " +
                     "line #{@scanner.line_no} column #{@scanner.char_no}"
        $stderr.puts
        $stderr.puts "Before reporting this, could you check that the file"
        $stderr.puts "you're documenting compiles cleanly--RDoc is not a"
        $stderr.puts "full Ruby parser, and gets confused easily if fed"
        $stderr.puts "invalid programs."
        $stderr.puts
        $stderr.puts "The internal error was:\n\n"

        e.set_backtrace(e.backtrace[0,4])
        raise
      end
    end
  end
  @top_level
end