Class: ParseDef

Inherits:
EndableParseState show all
Defined in:
lib/saikuro.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.



466
467
468
469
470
471
# File 'lib/saikuro.rb', line 466

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



518
519
520
521
# File 'lib/saikuro.rb', line 518

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.



475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
# File 'lib/saikuro.rb', line 475

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



511
512
513
514
515
516
# File 'lib/saikuro.rb', line 511

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