369c0a7919acaf900e4b0ebac6e26707ffe44209
[nit.git] / contrib / pep8analysis / src / backbone.nit
1 import opts
2
3 import parser
4
5 class AnalysisManager
6 super Noter
7 var opts = new OptionContext
8
9 init do end
10 end
11
12 abstract class Noter
13 var notes = new Array[Note]
14
15 var failed = false
16
17 fun print_notes
18 do
19 if not notes.is_empty then
20 print "# Notes:"
21 for n in notes do print n
22 end
23 end
24
25 fun fatal_error(n: ANode, msg: String)
26 do
27 notes.add( new Fatal(n.location, msg) )
28 failed = true
29 end
30
31 fun reset
32 do
33 failed = false
34 end
35 end
36
37 abstract class Note
38 var line: Location
39 var to: nullable Location = null
40 var msg: String
41
42 init (line: Location, msg: String)
43 do
44 self.line = line
45 self.msg = msg
46 end
47 init range(from, to: Location, msg: String)
48 do
49 self.line = from
50 self.to = to
51 self.msg = msg
52 end
53
54 fun prefix: String is abstract
55 redef fun to_s do
56 var s = ""
57 var to = to
58 if to != null then
59 s += " from {line} to {to}"
60 s = "{line.to_file_s}:{line.to_line_s}--{to.to_line_s}; "
61 else
62 s = "{line.to_file_s}:{line.to_line_s}; "
63 end
64 return "{prefix}{s}{msg}"
65 end
66 end
67
68 class Warn
69 super Note
70 init (line: Location, msg: String) do super
71 init range(from, to: Location, msg: String) do super
72 redef fun prefix do return "Warning: "
73 end
74
75 class Error
76 super Note
77 init (line: Location, msg: String) do super
78 init range(from, to: Location, msg: String) do super
79 redef fun prefix do return "Error: "
80 end
81
82 class Fatal
83 super Note
84 init (line: Location, msg: String) do super
85 init range(from, to: Location, msg: String) do super
86 redef fun prefix do return "Fatal: "
87 end
88
89 redef class Object
90 protected fun manager: AnalysisManager is abstract
91 end
92
93 redef class Location
94 # "line 5"
95 fun to_line_s: String
96 do
97 return line_start.to_s
98 end
99
100 fun to_file_s: String
101 do
102 return file.filename
103 end
104 end