class RDoc::RubyLex
def identify_number
def identify_number @lex_state = EXPR_END num = '' if peek(0) == "0" && peek(1) !~ /[.eE]/ num << getc case peek(0) when /[xX]/ ch = getc match = /[0-9a-fA-F_]/ when /[bB]/ ch = getc match = /[01_]/ when /[oO]/ ch = getc match = /[0-7_]/ when /[dD]/ ch = getc match = /[0-9_]/ when /[0-7]/ match = /[0-7_]/ when /[89]/ raise RDoc::Error, "Illegal octal digit" else return Token(TkINTEGER, num) end num << ch if ch len0 = true non_digit = false while ch = getc num << ch if match =~ ch if ch == "_" if non_digit raise RDoc::Error, "trailing `#{ch}' in number" else non_digit = ch end else non_digit = false len0 = false end else ungetc num[-1, 1] = '' if len0 raise RDoc::Error, "numeric literal without digits" end if non_digit raise RDoc::Error, "trailing `#{non_digit}' in number" end break end end return Token(TkINTEGER, num) end type = TkINTEGER allow_point = true allow_e = true non_digit = false while ch = getc num << ch case ch when /[0-9]/ non_digit = false when "_" non_digit = ch when allow_point && "." if non_digit raise RDoc::Error, "trailing `#{non_digit}' in number" end type = TkFLOAT if peek(0) !~ /[0-9]/ type = TkINTEGER ungetc num[-1, 1] = '' break end allow_point = false when allow_e && "e", allow_e && "E" if non_digit raise RDoc::Error, "trailing `#{non_digit}' in number" end type = TkFLOAT if peek(0) =~ /[+-]/ num << getc end allow_e = false allow_point = false non_digit = ch else if non_digit raise RDoc::Error, "trailing `#{non_digit}' in number" end ungetc num[-1, 1] = '' break end end Token(type, num) end