Class: Rsec::PInt

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

Overview

primitive int parser commons

Direct Known Subclasses

PInt32, PInt64, PUnsignedInt32, PUnsignedInt64

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, #|

Instance Method Details

#_parse(ctx) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/rsec/parsers/prim.rb', line 57

def _parse ctx
  if (d = ctx.scan left)
    d = d.to_i @base
    return d if right.include?(d)
  end
  INVALID
end

#int_pattern(sign_strategy, base) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rsec/parsers/prim.rb', line 45

def int_pattern sign_strategy, base
  sign = sign_strategy_to_pattern sign_strategy
  if base > 10
    d_hi = 9
    char_range = "a-#{('a'.ord + base - 11).chr}"
  else
    d_hi = base - 1
    char_range = ''
  end
  /#{sign}[0-#{d_hi}#{char_range}]+/i
end