lib: Update libs to use correctly ascii and code_point
[nit.git] / contrib / pep8analysis / src / model / operands.nit
1 import ast
2
3 redef class AValue
4 fun to_i: Int is abstract
5 end
6
7 redef class ALabelValue
8 redef fun to_i do
9 if not n_id.labels_to_address.has_key(n_id.text) then
10 manager.fatal_error( self, "Label {n_id.text} used but not defined.")
11 return 0
12 else
13 return n_id.labels_to_address[n_id.text]
14 end
15 end
16 end
17 redef class TId
18 var labels_to_address: HashMap[String,Int] = (once new HashMap[String,Int])
19 #redef fun to_i: Int do return label_to_address[text]
20 end
21
22 redef class ANumberValue
23 redef fun to_i do return n_number.text.to_i
24 end
25
26 redef class ACharValue
27 redef fun to_i do return n_char.content.first.code_point
28 end
29
30 redef class AStringValue
31 # legal but no not recommended
32 redef fun to_i do return n_string.content.first.code_point
33 end
34
35 redef class AHexValue
36 #TODO
37 redef fun to_i do return n_hex.text.to_hex
38 end
39
40 redef class TString # TkBlock
41 fun content : String
42 do
43 return text.substring(1, text.length-2)
44 end
45 end
46 redef class TChar # TkAscii
47 fun content : String
48 do
49 return text.substring(1, text.length-2)
50 end
51 end