Class: Rsec::PDouble

Inherits:
Binary
  • Object
show all
Includes:
Prim
Defined in:
lib/rsec/parsers/prim.rb

Overview

double precision float parser

Instance Attribute Summary

Attributes inherited from Binary

#left, #right

Attributes included from Parser

#name

Instance Method Summary collapse

Methods included from Prim

#sign_strategy_to_pattern

Methods included from Parser

#&, #*, #<<, #>>, #^, #cached, #eof, #fail, #inspect, #join, #map, #maybe, #parse, #parse!, #star, #|

Constructor Details

#initialize(sign_strategy, is_hex) ⇒ PDouble

Returns a new instance of PDouble.



28
29
30
# File 'lib/rsec/parsers/prim.rb', line 28

def initialize sign_strategy, is_hex
  self.left = float_pattern sign_strategy, is_hex
end

Instance Method Details

#_parse(ctx) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/rsec/parsers/prim.rb', line 32

def _parse ctx
  if (d = ctx.scan left)
    d = Float(d)
    return d if d.finite?
  end
  INVALID
end

#float_pattern(sign_strategy, is_hex) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/rsec/parsers/prim.rb', line 19

def float_pattern sign_strategy, is_hex
  sign = sign_strategy_to_pattern sign_strategy
  if is_hex
    /#{sign}0x[\da-f]+(\.[\da-f]+)?/i
  else
    /#{sign}\d+(\.\d+)?(e[\+\-]?\d+)?/i
  end
end