Class: Cyclomagic::ParseDef

Inherits:
EndableParseState show all
Defined in:
lib/cyclomagic.rb

Instance Attribute Summary

Attributes inherited from ParseState

#children, #complexity, #lines, #name, #parent

Instance Method Summary collapse

Methods inherited from EndableParseState

#do_end_token

Methods inherited from ParseState

#calc_complexity, #calc_lines, #compute_state_for_global, #count_tokens?, #do_begin_token, #do_block_token, #do_case_token, #do_class_token, #do_comment_token, #do_conditional_do_control_token, #do_conditional_token, #do_constant_token, #do_def_token, #do_else_token, #do_end_token, #do_identifier_token, #do_module_token, #do_one_line_conditional_token, #do_right_brace_token, #do_symbol_token, #end_debug, get_token_counter, #lexer=, #lexer_loop?, #make_state, make_top_state, #parse, set_token_counter, #top_state?

Constructor Details

#initialize(lexer, parent = nil) ⇒ ParseDef

Returns a new instance of ParseDef.



432
433
434
435
436
437
# File 'lib/cyclomagic.rb', line 432

def initialize(lexer,parent=nil)
  super(lexer,parent)
  @complexity = 1
  @looking_for_name = true
  @first_space = true
end

Instance Method Details

#compute_state(formater) ⇒ Object



484
485
486
487
# File 'lib/cyclomagic.rb', line 484

def compute_state(formater)
  formater.def_compute_state(@name, self.calc_complexity, self.calc_lines)
  super(formater)
end

#create_def_name(token) ⇒ Object

This way I don’t need to list all possible overload tokens.



441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'lib/cyclomagic.rb', line 441

def create_def_name(token)
  case token
  when TkSPACE
    # mark first space so we can stop at next space
    if @first_space
	@first_space = false
    else
	@looking_for_name = false
    end
  when TkNL,TkLPAREN,TkfLPAREN,TkSEMICOLON
    # we can also stop at a new line or left parenthesis
    @looking_for_name = false
  when TkDOT
    @name<< "."
  when TkCOLON2
    @name<< "::"
  when TkASSIGN
    @name<< "="
  when TkfLBRACK
    @name<< "["
  when TkRBRACK
    @name<< "]"
  else
    begin
	@name<< token.name.to_s
    rescue Exception => err
	#what is this?
	STDOUT.puts @@token_counter.current_file
	STDOUT.puts @name
	STDOUT.puts token.inspect
	STDOUT.puts err.message
	exit 1
    end
  end
end

#parse_token(token) ⇒ Object



477
478
479
480
481
482
# File 'lib/cyclomagic.rb', line 477

def parse_token(token)
  if @looking_for_name
    create_def_name(token)
  end
  super(token)
end