Class: RubySourceStructure
Instance Attribute Summary collapse
#root
Instance Method Summary
collapse
#class_node_by_line, #deep_node_by_line, #node_by_line
Constructor Details
Returns a new instance of RubySourceStructure.
117
118
119
120
|
# File 'ext/ae-editor/ae-editor.rb', line 117
def initialize(_source)
super()
parse_source(_source)
end
|
Instance Attribute Details
#injected_row ⇒ Object
Returns the value of attribute injected_row.
115
116
117
|
# File 'ext/ae-editor/ae-editor.rb', line 115
def injected_row
@injected_row
end
|
Instance Method Details
#class_methods(_class) ⇒ Object
258
259
|
# File 'ext/ae-editor/ae-editor.rb', line 258
def class_methods(_class)
end
|
#classies ⇒ Object
254
255
|
# File 'ext/ae-editor/ae-editor.rb', line 254
def classies
end
|
#modules ⇒ Object
256
257
|
# File 'ext/ae-editor/ae-editor.rb', line 256
def modules
end
|
#parse_source(_source) ⇒ Object
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
# File 'ext/ae-editor/ae-editor.rb', line 123
def parse_source(_source)
_row = 1
_liv = 0
_livs = Array.new
_livs[_liv]=@root
_source.each_line{|line|
line = "\s"+line.split("#")[0]+"\s"
m = /[\s\n\t\;]+(module|class|def|if|unless|begin|case|for|while|do)[\s\n\t\;]+/.match("\s#{line}")
if m
index = m.post_match.strip.length - 1
if m.post_match.strip[index,index]=='{'
_row = _row +1
next
end
_liv>=0? _liv = _liv + 1:_liv=1
_pliv = _liv
_parent = nil
while (_parent == nil && _pliv>=0)
_pliv = _pliv -1
_parent = _livs[_pliv]
end
if _parent
_helptext = m.post_match.strip
_label = _helptext.split('<')[0]
if _label == nil || _label.strip.length==0
_label = _helptext
end
if (m[0].strip[0..4] == "class" && m.pre_match.strip.length==0)
_kind = 'KClass'
if m.post_match.strip[0..1]=='<<'
hinner_class = true
else
hinner_class = false
end
elsif (m[0].strip[0..4] == "class" && m.pre_match.strip.length>0)
_row = _row +1
_liv = _liv - 1
next
elsif (m[0].strip[0..5] == "module" && m.pre_match.strip.length==0)
_kind = 'KModule'
elsif (m[0].strip[0..5] == "module" && m.pre_match.strip.length>0)
_row = _row +1
_liv = _liv - 1
next
elsif ((m[0].strip[0..4] == "begin")||(m[0].strip[0..3] == "case") ||(m[0].strip[0..4] == "while") || (m[0].strip[0..2] == "for") || (m[0].strip[0..1] == "do") || ((m[0].strip[0..1] == "if" || m[0].strip[0..5] == "unless") && m.pre_match.strip.length==0))
_row = _row +1
next
elsif ((m[0].strip[0..1] == "if" || m[0].strip[0..5] == "unless") && m.pre_match.strip.length>0)
_row = _row +1
_liv = _liv - 1
next
elsif (m[0].strip[0..2] == "def" && m.pre_match.strip.length==0)
_kind = 'KDef'
if _label.include?(_parent.label + '.')
_kind = 'KDefClass'
end
end
if _livs[_liv-1] && (_livs[_liv-1].kind != 'KDef' || (_livs[_liv-1].kind == 'KDef' && _kind == 'KClass' && hinner_class))
TreeNode.new(_parent, _kind){|_node|
_node.label = _label
_node.helptext = _helptext
_node.rif = _row.to_s
_livs[_pliv + 1]=_node
}
else
TreeNode.new(_livs[_liv-3], _kind){|_node|
_node.label = _label
_node.helptext = _helptext
_node.rif = _row.to_s
_livs[_pliv-1]=_node
}
_liv = _liv - 2
end
else
_row = _row +1
_liv = _liv - 1
next
end
end
m_end = /[\s\n\t\;]+end[\s\n\t\;]+/.match(line)
if m_end
if _livs[_liv]
_livs[_liv].rif_end = _row
end
_liv = _liv - 1
end
_row = _row +1
}
end
|
#scheletor_from_node(_node, _source = '', _injected_source = '', _injected_class = '') ⇒ Object
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
# File 'ext/ae-editor/ae-editor.rb', line 224
def scheletor_from_node(_node, _source='', _injected_source='', _injected_class='')
_hinner_source = ''
_sons = _node.sons
for inode in 0.._sons.length - 1
_son = _sons[inode]
if _son.kind == 'KClass'
_hinner_source = "#{_hinner_source}class #{_son.helptext}\n"
elsif _son.kind == 'KModule'
_hinner_source = "#{_hinner_source}module #{_son.helptext}\n"
elsif _son.kind == 'KDef' && _son.helptext != 'initialize'
_hinner_source = "#{_hinner_source} def #{_son.helptext}\n"
_hinner_source = "#{_hinner_source} end\n"
elsif _son.kind == 'KDefClass'
_hinner_source = "#{_hinner_source} def #{_son.helptext}\n"
_hinner_source = "#{_hinner_source} end\n"
end
_hinner_source= scheletor_from_node(_son, _hinner_source, _injected_source, _injected_class)
end
_source = "#{_source}#{_hinner_source}" if _hinner_source.strip.length>0
if _node.kind == 'KClass' && _node.label == _injected_class
_source = "#{_source} def initialize\n #{_injected_source} end\n"
@injected_row = _source.split("\n").length-2
end
_source = "#{_source}end\n" if _node.kind == 'KClass' || _node.kind == 'KModule'
_source
end
|