Sha256: 5fc63cc0a183611fa33424420197be3820d71ff110d86bfc4475c4f19c4753bf

Contents?: true

Size: 1 KB

Versions: 16

Compression:

Stored size: 1 KB

Contents

class Code
  class Parser
    class Number < ::Code::Parser
      def parse
        if match(DIGITS)
          if match(X)
            parse_base(16)
          elsif match(O)
            parse_base(8)
          elsif match(B)
            parse_base(2)
          else
            consume while (next?(DIGITS) || next?(UNDERSCORE)) && !end_of_input?

            if next?(DOT) && next_next?(DIGITS)
              consume
              while (next?(DIGITS) || next?(UNDERSCORE)) && !end_of_input?
                consume
              end

              { decimal: buffer.gsub(UNDERSCORE, EMPTY_STRING) }
            else
              { integer: buffer.gsub(UNDERSCORE, EMPTY_STRING).to_i }
            end
          end
        else
          parse_subclass(::Code::Parser::Boolean)
        end
      end

      def parse_base(base)
        buffer!
        consume while (next?(DIGITS) || next?(UNDERSCORE)) && !end_of_input?

        { integer: buffer.gsub(UNDERSCORE, EMPTY_STRING).to_i(base) }
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
template-ruby-parser-0.1.7 lib/code/parser/number.rb
code-ruby-parser-0.1.7 lib/code/parser/number.rb
template-ruby-parser-0.1.6 lib/code/parser/number.rb
code-ruby-parser-0.1.6 lib/code/parser/number.rb
template-ruby-parser-0.1.5 lib/code/parser/number.rb
code-ruby-parser-0.1.5 lib/code/parser/number.rb
template-ruby-parser-0.1.4 lib/code/parser/number.rb
code-ruby-parser-0.1.4 lib/code/parser/number.rb
template-ruby-parser-0.1.3 lib/code/parser/number.rb
code-ruby-parser-0.1.3 lib/code/parser/number.rb
template-ruby-parser-0.1.2 lib/code/parser/number.rb
code-ruby-parser-0.1.2 lib/code/parser/number.rb
template-ruby-parser-0.1.1 lib/code/parser/number.rb
code-ruby-parser-0.1.1 lib/code/parser/number.rb
template-ruby-parser-0.1.0 lib/code/parser/number.rb
code-ruby-parser-0.1.0 lib/code/parser/number.rb