@@ -14,10 +14,6 @@ def scan
14
14
ast . each do |decl |
15
15
parse_member ( decl : decl , context : @top_level )
16
16
end
17
- klass = @top_level . add_class ( RDoc ::NormalClass , 'Hello' )
18
- comment = RDoc ::Comment . new ( 'Hello documentation' , @top_level )
19
- klass . add_comment ( comment , @top_level )
20
- @stats . add_class ( klass )
21
17
end
22
18
23
19
def parse_member ( decl :, context :, outer_name : nil )
@@ -32,12 +28,18 @@ def parse_member(decl:, context:, outer_name: nil)
32
28
when ::RBS ::AST ::Members ::MethodDefinition
33
29
context = @top_level . find_class_or_module outer_name . to_s if outer_name
34
30
parse_method_decl ( decl : decl , context : context , outer_name : outer_name )
31
+ when ::RBS ::AST ::Members ::Alias
32
+ context = @top_level . find_class_or_module outer_name . to_s if outer_name
33
+ parse_method_alias_decl ( decl : decl , context : context , outer_name : outer_name )
34
+ when ::RBS ::AST ::Members ::AttrReader , ::RBS ::AST ::Members ::AttrWriter , ::RBS ::AST ::Members ::AttrAccessor
35
+ context = @top_level . find_class_or_module outer_name . to_s if outer_name
36
+ parse_attr_decl ( decl : decl , context : context , outer_name : outer_name )
35
37
end
36
38
end
37
39
38
40
def parse_class_decl ( decl :, context :, outer_name : nil )
39
41
full_name = fully_qualified_name ( outer_name : outer_name , decl : decl )
40
- klass = context . add_class ( RDoc ::NormalClass , full_name . to_s )
42
+ klass = context . add_class ( RDoc ::NormalClass , full_name . to_s , decl . super_class &. name &. to_s || "::Object" )
41
43
klass . add_comment ( construct_comment ( context : context , comment : decl . comment . string ) , context ) if decl . comment
42
44
decl . members . each { |member | parse_member ( decl : member , context : context , outer_name : full_name ) }
43
45
end
@@ -60,10 +62,37 @@ def parse_method_decl(decl:, context:, outer_name: nil)
60
62
method . singleton = decl . singleton?
61
63
method . visibility = decl . visibility
62
64
method . call_seq = decl . types . map { |type | "#{ decl . name . to_s } #{ type . to_s } " } . join ( "\n " )
65
+ if decl . location
66
+ method . start_collecting_tokens
67
+ method . add_token ( { line_no : 1 , char_no : 1 , kind : :on_comment , text : "# File #{ @top_level . relative_name } , line(s) #{ decl . location . start_line } :#{ decl . location . end_line } \n " } )
68
+ method . add_token ( { line_no : 1 , char_no : 1 , text : decl . location . source } )
69
+ method . line = decl . location . start_line if decl . location
70
+ end
63
71
method . comment = construct_comment ( context : context , comment : decl . comment . string ) if decl . comment
64
72
context . add_method ( method )
65
73
end
66
74
75
+ def parse_method_alias_decl ( decl :, context :, outer_name : nil )
76
+ alias_def = RDoc ::Alias . new ( nil , decl . old_name . to_s , decl . new_name . to_s , nil , decl . kind == :singleton )
77
+ alias_def . comment = construct_comment ( context : context , comment : decl . comment . string ) if decl . comment
78
+ context . add_alias ( alias_def )
79
+ end
80
+
81
+ def parse_attr_decl ( decl :, context :, outer_name : nil )
82
+ rw = case decl
83
+ when ::RBS ::AST ::Members ::AttrReader
84
+ 'R'
85
+ when ::RBS ::AST ::Members ::AttrWriter
86
+ 'W'
87
+ when ::RBS ::AST ::Members ::AttrAccessor
88
+ 'RW'
89
+ end
90
+ attribute = RDoc ::Attr . new ( nil , decl . name . to_s , rw , nil , decl . kind == :singleton )
91
+ attribute . visibility = decl . visibility
92
+ attribute . comment = construct_comment ( context : context , comment : decl . comment . string ) if decl . comment
93
+ context . add_attribute ( attribute )
94
+ end
95
+
67
96
private
68
97
69
98
def construct_comment ( context :, comment :)
0 commit comments