class RubyLexer

Public Instance Methods

parse_number() click to toggle source
Parse a number from the input stream.

@param c The first character of the number. @return A int constant wich represents a token.

# File lib/dzintars/ruby_parser_patches.rb, line 8
def parse_number
  self.lex_state = :expr_end

  case
  when src.scan(/[+-]?0[xXbBdD]\b/) then
    rb_compile_error "Invalid numeric format"
  # when src.scan(/[+-]?(?:(?:[1-9][\d_]*|0)(?!\.\d)\b|0[Dd][0-9_]+)/) then
  when src.scan(/[+-]?(?:(?:[1-9][\d_]*|0)(?!\,\d)\b|0[Dd][0-9_]+)/) then
    int_with_base(10)
  when src.scan(/[+-]?0x[a-f0-9_]+/i) then
    int_with_base(16)
  when src.scan(/[+-]?0[Bb][01_]+/) then
    int_with_base(2)
  when src.scan(/[+-]?0[Oo]?[0-7_]*[89]/) then
    rb_compile_error "Illegal octal digit."
  when src.scan(/[+-]?0[Oo]?[0-7_]+|0[Oo]/) then
    int_with_base(8)
  when src.scan(/[+-]?[\d_]+_(e|\.)/) then
    rb_compile_error "Trailing '_' in number."
  # when src.scan(/[+-]?[\d_]+\.[\d_]+(e[+-]?[\d_]+)?\b|[+-]?[\d_]+e[+-]?[\d_]+\b/i) then
  when src.scan(/[+-]?[\d_]+\,[\d_]+(e[+-]?[\d_]+)?\b|[+-]?[\d_]+e[+-]?[\d_]+\b/i) then
    number = src.matched.sub(',', '.')
    if number =~ /__/ then
      rb_compile_error "Invalid numeric format"
    end
    self.yacc_value = number.to_f
    :tFLOAT
  when src.scan(/[+-]?[0-9_]+(?![e])/) then
    int_with_base(10)
  else
    rb_compile_error "Bad number format"
  end
end