Module: Cyclomagic::Cyclomagic
- Defined in:
- lib/cyclomagic.rb
Class Method Summary collapse
- .analyze(files, state_formater, token_count_formater, output_dir) ⇒ Object
-
.seperate_file_from_path(path) ⇒ Object
Returns the path without the file.
Class Method Details
.analyze(files, state_formater, token_count_formater, output_dir) ⇒ Object
948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 |
# File 'lib/cyclomagic.rb', line 948 def Cyclomagic.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.}" rescue StandardError => err STDOUT.puts "Error while parsing file : #{file}" STDOUT.puts err.class,err.,err.backtrace.join("\n") rescue Exception => ex STDOUT.puts "Error while parsing file : #{file}" STDOUT.puts ex.class,ex.,ex.backtrace.join("\n") end end [idx_states, idx_tokens] end |
.seperate_file_from_path(path) ⇒ Object
Returns the path without the file
939 940 941 942 943 944 945 946 |
# File 'lib/cyclomagic.rb', line 939 def Cyclomagic.seperate_file_from_path(path) res = path.split("/") if res.size == 1 "" else res[0..res.size - 2].join("/") end end |