Class: Code::Parser::Number

Inherits:
Language
  • Object
show all
Defined in:
lib/code/parser/number.rb

Instance Method Summary collapse

Instance Method Details

#aObject



54
55
56
# File 'lib/code/parser/number.rb', line 54

def a
  str("a") | str("A")
end

#bObject



58
59
60
# File 'lib/code/parser/number.rb', line 58

def b
  str("b") | str("B")
end

#base_10_digitObject



95
96
97
# File 'lib/code/parser/number.rb', line 95

def base_10_digit
  zero | one | two | three | four | five | six | seven | eight | nine
end

#base_10_numberObject



135
136
137
# File 'lib/code/parser/number.rb', line 135

def base_10_number
  base_10_whole.aka(:whole) << exponent.maybe
end

#base_10_wholeObject



111
112
113
# File 'lib/code/parser/number.rb', line 111

def base_10_whole
  base_10_digit << (underscore.ignore | base_10_digit).repeat
end

#base_16_digitObject



90
91
92
93
# File 'lib/code/parser/number.rb', line 90

def base_16_digit
  zero | one | two | three | four | five | six | seven | eight | nine |
    a | b | c | d | e | f
end

#base_16_numberObject



131
132
133
# File 'lib/code/parser/number.rb', line 131

def base_16_number
  zero.ignore << x.ignore << base_16_whole
end

#base_16_wholeObject



107
108
109
# File 'lib/code/parser/number.rb', line 107

def base_16_whole
  base_16_digit << (underscore.ignore | base_16_digit).repeat
end

#base_2_digitObject



103
104
105
# File 'lib/code/parser/number.rb', line 103

def base_2_digit
  zero | one
end

#base_2_numberObject



143
144
145
# File 'lib/code/parser/number.rb', line 143

def base_2_number
  zero.ignore << b.ignore << base_2_whole
end

#base_2_wholeObject



119
120
121
# File 'lib/code/parser/number.rb', line 119

def base_2_whole
  base_2_digit << (underscore.ignore | base_2_digit).repeat
end

#base_8_digitObject



99
100
101
# File 'lib/code/parser/number.rb', line 99

def base_8_digit
  zero | one | two | three | four | five | six | seven
end

#base_8_numberObject



139
140
141
# File 'lib/code/parser/number.rb', line 139

def base_8_number
  zero.ignore << o.ignore << base_8_whole
end

#base_8_wholeObject



115
116
117
# File 'lib/code/parser/number.rb', line 115

def base_8_whole
  base_8_digit << (underscore.ignore | base_8_digit).repeat
end

#cObject



62
63
64
# File 'lib/code/parser/number.rb', line 62

def c
  str("c") | str("C")
end

#dObject



66
67
68
# File 'lib/code/parser/number.rb', line 66

def d
  str("d") | str("D")
end

#decimalObject



127
128
129
# File 'lib/code/parser/number.rb', line 127

def decimal
  (base_10_whole << dot << base_10_whole).aka(:decimal) << exponent.maybe
end

#dotObject



50
51
52
# File 'lib/code/parser/number.rb', line 50

def dot
  str(".")
end

#eObject



70
71
72
# File 'lib/code/parser/number.rb', line 70

def e
  str("e") | str("E")
end

#eightObject



42
43
44
# File 'lib/code/parser/number.rb', line 42

def eight
  str("8")
end

#exponentObject



123
124
125
# File 'lib/code/parser/number.rb', line 123

def exponent
  (e << number).aka(:exponent)
end

#fObject



74
75
76
# File 'lib/code/parser/number.rb', line 74

def f
  str("f") | str("F")
end

#fiveObject



30
31
32
# File 'lib/code/parser/number.rb', line 30

def five
  str("5")
end

#fourObject



26
27
28
# File 'lib/code/parser/number.rb', line 26

def four
  str("4")
end

#nineObject



46
47
48
# File 'lib/code/parser/number.rb', line 46

def nine
  str("9")
end

#numberObject



6
7
8
# File 'lib/code/parser/number.rb', line 6

def number
  Number
end

#oObject



78
79
80
# File 'lib/code/parser/number.rb', line 78

def o
  str("o") | str("O")
end

#oneObject



14
15
16
# File 'lib/code/parser/number.rb', line 14

def one
  str("1")
end

#rootObject



147
148
149
150
151
152
153
# File 'lib/code/parser/number.rb', line 147

def root
  (
    decimal.aka(:decimal) | base_16_number.aka(:base_16) |
      base_8_number.aka(:base_8) | base_2_number.aka(:base_2) |
      base_10_number.aka(:base_10)
  ).aka(:number) | Boolean
end

#sevenObject



38
39
40
# File 'lib/code/parser/number.rb', line 38

def seven
  str("7")
end

#sixObject



34
35
36
# File 'lib/code/parser/number.rb', line 34

def six
  str("6")
end

#threeObject



22
23
24
# File 'lib/code/parser/number.rb', line 22

def three
  str("3")
end

#twoObject



18
19
20
# File 'lib/code/parser/number.rb', line 18

def two
  str("2")
end

#underscoreObject



86
87
88
# File 'lib/code/parser/number.rb', line 86

def underscore
  str("_")
end

#xObject



82
83
84
# File 'lib/code/parser/number.rb', line 82

def x
  str("x") | str("X")
end

#zeroObject



10
11
12
# File 'lib/code/parser/number.rb', line 10

def zero
  str("0")
end