class RDoc::RipperStateLex::InnerStateLex

Attributes

lex_state[RW]

Public Class Methods

new(code) click to toggle source
Calls superclass method
# File lib/rdoc/parser/ripper_state_lex.rb, line 30
def initialize(code)
  @lex_state = EXPR_BEG
  @in_fname = false
  @continue = false
  reset
  super(code)
end

Public Instance Methods

each(&block) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 297
def each(&block)
  @callback = block
  parse
end
on_CHAR(tok, data) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 146
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_backref(tok, data) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 221
def on_backref(tok, data)
  @lex_state = EXPR_END
  on_variables(__method__, tok, data)
end
on_comma(tok, data) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 272
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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 277
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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 256
def on_const(tok, data)
  case @lex_state
  when EXPR_FNAME
    @lex_state = EXPR_ENDFN
  when EXPR_CLASS, EXPR_CMDARG, EXPR_MID
    @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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 211
def on_cvar(tok, data)
  @lex_state = EXPR_END
  on_variables(__method__, tok, data)
end
on_default(event, tok, data) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 292
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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 161
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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 216
def on_gvar(tok, data)
  @lex_state = EXPR_END
  on_variables(__method__, tok, data)
end
on_heredoc_end(tok, data) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 287
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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 202
def on_ident(tok, data)
  on_variables(__method__, tok, data)
end
on_ignored_nl(tok, data) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 54
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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 282
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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 171
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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 156
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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 206
def on_ivar(tok, data)
  @lex_state = EXPR_END
  on_variables(__method__, tok, data)
end
on_kw(tok, data) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 107
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', 'case', 'when'
    @lex_state = EXPR_BEG
  when 'return', 'break'
    @lex_state = EXPR_MID
  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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 236
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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 246
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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 226
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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 43
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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 65
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
  when '::'
    case @lex_state
    when EXPR_ARG, EXPR_CMDARG
      @lex_state = EXPR_DOT
    when EXPR_FNAME, EXPR_DOT
      @lex_state = EXPR_ARG
    else
      @lex_state = EXPR_BEG
    end
  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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 151
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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 166
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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 241
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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 251
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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 231
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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 268
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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 176
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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 136
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) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 141
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
reset() click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 38
def reset
  @command_start = false
  @cmd_state = @command_start
end