class RDoc::Parser::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 32
def initialize(code)
  @lex_state = EXPR_BEG
  @in_fname = false
  @continue = false
  reset
  super(code)
end

Public Instance Methods

on_CHAR(tok, data) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 148
def on_CHAR(tok, data)
  @lex_state = EXPR_END
  data << Token.new(lineno, column, __method__, tok, @lex_state)
end
on_float(tok, data) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 163
def on_float(tok, data)
  @lex_state = EXPR_END | EXPR_ENDARG
  data << Token.new(lineno, column, __method__, tok, @lex_state)
end
on_ignored_nl(tok, data) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 56
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
  data << Token.new(lineno, column, __method__, tok, @lex_state)
end
on_imaginary(tok, data) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 173
def on_imaginary(tok, data)
  @lex_state = EXPR_END | EXPR_ENDARG
  data << Token.new(lineno, column, __method__, tok, @lex_state)
end
on_int(tok, data) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 158
def on_int(tok, data)
  @lex_state = EXPR_END | EXPR_ENDARG
  data << Token.new(lineno, column, __method__, tok, @lex_state)
end
on_kw(tok, data) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 109
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_MID | 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
  data << Token.new(lineno, column, __method__, tok, @lex_state)
end
on_nl(tok, data) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 45
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
  data << Token.new(lineno, column, __method__, tok, @lex_state)
end
on_op(tok, data) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 67
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
  data << Token.new(lineno, column, __method__, tok, @lex_state)
end
on_period(tok, data) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 153
def on_period(tok, data)
  @lex_state = EXPR_DOT
  data << Token.new(lineno, column, __method__, tok, @lex_state)
end
on_rational(tok, data) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 168
def on_rational(tok, data)
  @lex_state = EXPR_END | EXPR_ENDARG
  data << Token.new(lineno, column, __method__, tok, @lex_state)
end
on_symbeg(tok, data) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 178
def on_symbeg(tok, data)
  @lex_state = EXPR_FNAME
  @continue = true
  @in_fname = true
  data << Token.new(lineno, column, __method__, tok, @lex_state)
end
on_tstring_beg(tok, data) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 138
def on_tstring_beg(tok, data)
  @lex_state = EXPR_BEG
  data << Token.new(lineno, column, __method__, tok, @lex_state)
end
on_tstring_end(tok, data) click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 143
def on_tstring_end(tok, data)
  @lex_state = EXPR_END | EXPR_ENDARG
  data << Token.new(lineno, column, __method__, tok, @lex_state)
end
reset() click to toggle source
# File lib/rdoc/parser/ripper_state_lex.rb, line 40
def reset
  @command_start = false
  @cmd_state = @command_start
end