123456789_123456789_123456789_123456789_123456789_

Class: RDoc::RipperStateLex::InnerStateLex

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Ripper::Filter
Instance Chain:
self, Ripper::Filter
Inherits: Ripper::Filter
  • Object
Defined in: lib/rdoc/parser/ripper_state_lex.rb,
lib/rdoc/parser/ripper_state_lex.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(code) ⇒ InnerStateLex

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 29

def initialize(code)
  @lex_state = EXPR_BEG
  @in_fname = false
  @continue = false
  reset
  super(code)
end

#initialize(code) ⇒ InnerStateLex

See additional method definition at line 29.

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 292

def initialize(code)
  @lex_state = EXPR_BEG
  @in_fname = false
  @continue = false
  reset
  super(code)
end

Instance Attribute Details

#lex_state (rw)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 27

attr_accessor :lex_state

Instance Method Details

#each(&block)

See additional method definition at line 285.

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 300

def each(&block)
  @callback = block
  parse
end

#on_backref(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 209

def on_backref(tok, data)
  @lex_state = EXPR_END
  on_variables(__method__, tok, data)
end

#on_CHAR(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 134

def on_CHAR(tok, data)
  @lex_state = EXPR_END
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_comma(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 260

def on_comma(tok, data)
  @lex_state = EXPR_BEG | EXPR_LABEL if (EXPR_ARG_ANY & @lex_state) != 0
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_comment(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 265

def on_comment(tok, data)
  @lex_state = EXPR_BEG unless (EXPR_LABEL & @lex_state) != 0
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_const(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 244

def on_const(tok, data)
  case @lex_state
  when EXPR_FNAME
    @lex_state = EXPR_ENDFN
  when EXPR_CLASS
    @lex_state = EXPR_ARG
  else
    @lex_state = EXPR_CMDARG
  end
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_cvar(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 199

def on_cvar(tok, data)
  @lex_state = EXPR_END
  on_variables(__method__, tok, data)
end

#on_default(event, tok, data)

See additional method definition at line 280.

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 296

def on_default(event, tok, data)
  reset
  @callback.call({ :line_no => lineno, :char_no => column, :kind => event, :text => tok, :state => @lex_state})
end

#on_float(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 149

def on_float(tok, data)
  @lex_state = EXPR_END | EXPR_ENDARG
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_gvar(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 204

def on_gvar(tok, data)
  @lex_state = EXPR_END
  on_variables(__method__, tok, data)
end

#on_heredoc_end(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 275

def on_heredoc_end(tok, data)
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
  @lex_state = EXPR_BEG
end

#on_ident(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 190

def on_ident(tok, data)
  on_variables(__method__, tok, data)
end

#on_ignored_nl(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 53

def on_ignored_nl(tok, data)
  case @lex_state
  when EXPR_FNAME, EXPR_DOT
    @continue = true
  else
    @continue = false
    @lex_state = EXPR_BEG unless (EXPR_LABEL & @lex_state) != 0
  end
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_ignored_sp(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 270

def on_ignored_sp(tok, data)
  @lex_state = EXPR_BEG unless (EXPR_LABEL & @lex_state) != 0
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_imaginary(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 159

def on_imaginary(tok, data)
  @lex_state = EXPR_END | EXPR_ENDARG
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_int(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 144

def on_int(tok, data)
  @lex_state = EXPR_END | EXPR_ENDARG
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_ivar(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 194

def on_ivar(tok, data)
  @lex_state = EXPR_END
  on_variables(__method__, tok, data)
end

#on_kw(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 97

def on_kw(tok, data)
  case tok
  when 'class'
    @lex_state = EXPR_CLASS
    @in_fname = true
  when 'def'
    @lex_state = EXPR_FNAME
    @continue = true
    @in_fname = true
  when 'if', 'unless', 'while', 'until'
    if ((EXPR_END | EXPR_ENDARG | EXPR_ENDFN | EXPR_ARG | EXPR_CMDARG) & @lex_state) != 0 # postfix if
      @lex_state = EXPR_BEG | EXPR_LABEL
    else
      @lex_state = EXPR_BEG
    end
  when 'begin'
    @lex_state = EXPR_BEG
  else
    if @lex_state == EXPR_FNAME
      @lex_state = EXPR_END
    else
      @lex_state = EXPR_END
    end
  end
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_lbrace(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 224

def on_lbrace(tok, data)
  @lex_state = EXPR_LABEL | EXPR_BEG
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_lbracket(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 234

def on_lbracket(tok, data)
  @lex_state = EXPR_LABEL | EXPR_BEG
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_lparen(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 214

def on_lparen(tok, data)
  @lex_state = EXPR_LABEL | EXPR_BEG
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_nl(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 42

def on_nl(tok, data)
  case @lex_state
  when EXPR_FNAME, EXPR_DOT
    @continue = true
  else
    @continue = false
    @lex_state = EXPR_BEG unless (EXPR_LABEL & @lex_state) != 0
  end
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_op(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 64

def on_op(tok, data)
  case tok
  when '&', '|', '!', '!=', '!~'
    case @lex_state
    when EXPR_FNAME, EXPR_DOT
      @lex_state = EXPR_ARG
    else
      @lex_state = EXPR_BEG
    end
  when '<<'
    # TODO next token?
    case @lex_state
    when EXPR_FNAME, EXPR_DOT
      @lex_state = EXPR_ARG
    else
      @lex_state = EXPR_BEG
    end
  when '?'
    @lex_state = EXPR_BEG
  when '&&', '||', '+=', '-=', '*=', '**=',
       '&=', '|=', '^=', '<<=', '>>=', '||=', '&&='
    @lex_state = EXPR_BEG
  else
    case @lex_state
    when EXPR_FNAME, EXPR_DOT
      @lex_state = EXPR_ARG
    else
      @lex_state = EXPR_BEG
    end
  end
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_period(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 139

def on_period(tok, data)
  @lex_state = EXPR_DOT
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_rational(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 154

def on_rational(tok, data)
  @lex_state = EXPR_END | EXPR_ENDARG
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_rbrace(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 229

def on_rbrace(tok, data)
  @lex_state = EXPR_ENDARG
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_rbracket(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 239

def on_rbracket(tok, data)
  @lex_state = EXPR_ENDARG
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_rparen(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 219

def on_rparen(tok, data)
  @lex_state = EXPR_ENDFN
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_sp(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 256

def on_sp(tok, data)
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_symbeg(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 164

def on_symbeg(tok, data)
  @lex_state = EXPR_FNAME
  @continue = true
  @in_fname = true
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_tstring_beg(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 124

def on_tstring_beg(tok, data)
  @lex_state = EXPR_BEG
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_tstring_end(tok, data)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 129

def on_tstring_end(tok, data)
  @lex_state = EXPR_END | EXPR_ENDARG
  @callback.call({ :line_no => lineno, :char_no => column, :kind => __method__, :text => tok, :state => @lex_state})
end

#on_variables(event, tok, data) (private)

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 171

private def on_variables(event, tok, data)
  if @in_fname
    @lex_state = EXPR_ENDFN
    @in_fname = false
    @continue = false
  elsif @continue
    case @lex_state
    when EXPR_DOT
      @lex_state = EXPR_ARG
    else
      @lex_state = EXPR_ENDFN
      @continue = false
    end
  else
    @lex_state = EXPR_CMDARG
  end
  @callback.call({ :line_no => lineno, :char_no => column, :kind => event, :text => tok, :state => @lex_state})
end

#reset

[ GitHub ]

  
# File 'lib/rdoc/parser/ripper_state_lex.rb', line 37

def reset
  @command_start = false
  @cmd_state = @command_start
end