Class: RubyLexer
- Inherits:
-
Object
- Object
- RubyLexer
- Defined in:
- lib/bato/ruby_parser_patches.rb
Instance Method Summary collapse
-
#parse_number ⇒ Object
Parse a number from the input stream.
Instance Method Details
#parse_number ⇒ Object
Parse a number from the input stream.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/bato/ruby_parser_patches.rb', line 10 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 |