Class: Lexer
- Inherits:
-
Object
- Object
- Lexer
- Defined in:
- lib/filipinomemes/ruby_parser_patches.rb
Overview
Lexer The Parsing method is explicitly UTF-8 so the Lexer is also explicitly UTF-8 Inorder to use the functions of yacc, we need to use BNF Grammar
Instance Method Summary collapse
Instance Method Details
#parse_number ⇒ Object
5 6 7 8 9 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 |
# File 'lib/filipinomemes/ruby_parser_patches.rb', line 5 def parse_number self.lex_state = :expr_end if src.scan(/[+-]?0[xXbBdD]\b/) rb_compile_error 'Invalid numeric format' # elsif src.scan(/[+-]?(?:(?:[1-9][\d_]*|0)(?!\.\d)\b|0[Dd][0-9_]+)/) elsif src.scan(/[+-]?(?:(?:[1-9][\d_]*|0)(?!\,\d)\b|0[Dd][0-9_]+)/) int_with_base(10) elsif src.scan(/[+-]?0x[a-f0-9_]+/i) int_with_base(16) elsif src.scan(/[+-]?0[Bb][01_]+/) int_with_base(2) elsif src.scan(/[+-]?0[Oo]?[0-7_]*[89]/) rb_compile_error 'Illegal octal digit.' elsif src.scan(/[+-]?0[Oo]?[0-7_]+|0[Oo]/) int_with_base(8) elsif src.scan(/[+-]?[\d_]+_(e|\.)/) rb_compile_error "Trailing '_' in number." # elsif src.scan(/[+-]?[\d_]+\.[\d_]+(e[+-]?[\d_]+)?\b|[+-]?[\d_]+e[+-]?[\d_]+\b/i) elsif src.scan(/[+-]?[\d_]+\,[\d_]+(e[+-]?[\d_]+)?\b|[+-]?[\d_]+e[+-]?[\d_]+\b/i) number = src.matched.sub(',', '.') rb_compile_error 'Invalid numeric format' if number =~ /__/ self.yacc_value = number.to_f #values of token which had a value associated with it. :tFLOAT elsif src.scan(/[+-]?[0-9_]+(?![e])/) int_with_base(10) else rb_compile_error 'Bad number format' end end |