Class: ParseDef

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



3
4
5
6
7
8
# File 'lib/saikuro/parse_def.rb', line 3

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



55
56
57
58
# File 'lib/saikuro/parse_def.rb', line 55

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.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/saikuro/parse_def.rb', line 12

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



48
49
50
51
52
53
# File 'lib/saikuro/parse_def.rb', line 48

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