Module: Saikuro

Defined in:
lib/saikuro.rb,
lib/saikuro.rb,
lib/saikuro/cli.rb,
lib/saikuro/version.rb,
lib/saikuro/base_formater.rb,
lib/saikuro/html_style_sheet.rb,
lib/saikuro/parse_state_formater.rb,
lib/saikuro/result_index_generator.rb,
lib/saikuro/token_counter_formater.rb,
lib/saikuro/html_token_counter_formater.rb,
lib/saikuro/state_html_complexity_formater.rb

Defined Under Namespace

Modules: HTMLStyleSheet, ResultIndexGenerator Classes: BaseFormater, CLI, HTMLTokenCounterFormater, ParseStateFormater, StateHTMLComplexityFormater, TokenCounterFormater

Constant Summary collapse

VERSION =
"1.2.1"

Class Method Summary collapse

Class Method Details

.analyze(files, state_formater, token_count_formater, output_dir) ⇒ Object



616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
# File 'lib/saikuro.rb', line 616

def Saikuro.analyze(files, state_formater, token_count_formater, output_dir)

  idx_states = Array.new
  idx_tokens = Array.new

  # parse each file
  files.each do |file|
    begin
      STDOUT.puts "Parsing #{file}"
      # create top state
      top = ParseState.make_top_state
      STDOUT.puts "TOP State made" if $VERBOSE
      token_counter = TokenCounter.new
      ParseState.set_token_counter(token_counter)
      token_counter.set_current_file(file)

      STDOUT.puts "Setting up Lexer" if $VERBOSE
      lexer = RubyLex.new
      # Turn of this, because it aborts when a syntax error is found...
      lexer.exception_on_syntax_error = false
      lexer.set_input(File.new(file,"r"))
      top.lexer = lexer
      STDOUT.puts "Parsing" if $VERBOSE
      top.parse


      fdir_path = seperate_file_from_path(file)
      FileUtils.makedirs("#{output_dir}/#{fdir_path}")

      if state_formater
        # output results
        state_io = StringIO.new
        state_formater.start(state_io)
        top.compute_state(state_formater)
        state_formater.end

        fname = "#{file}_cyclo.html"
        puts "writing cyclomatic #{file}" if $VERBOSE
        File.open("#{output_dir}/#{fname}","w") do |f|
          f.write state_io.string
        end
        idx_states<< [
          fname,
          state_formater.warnings.dup,
          state_formater.errors.dup,
        ]
      end

      if token_count_formater
        token_io = StringIO.new
        token_count_formater.start(token_io)
        token_counter.list_tokens_per_line(token_count_formater)
        token_count_formater.end

        fname = "#{file}_token.html"
        puts "writing token #{file}" if $VERBOSE
        File.open("#{output_dir}/#{fname}","w") do |f|
          f.write token_io.string
        end
        idx_tokens<< [
          fname,
          token_count_formater.warnings.dup,
          token_count_formater.errors.dup,
        ]
      end

    rescue RubyLex::SyntaxError => synerr
      STDOUT.puts "Lexer error for file #{file} on line #{lexer.line_no}"
      STDOUT.puts "#{synerr.class.name} : #{synerr.message}"
    rescue StandardError => err
      STDOUT.puts "Error while parsing file : #{file}"
      STDOUT.puts err.class,err.message,err.backtrace.join("\n")
    rescue Exception => ex
      STDOUT.puts "Error while parsing file : #{file}"
      STDOUT.puts ex.class,ex.message,ex.backtrace.join("\n")
    end
  end

  [idx_states, idx_tokens]
end