eric6/Utilities/ClassBrowsers/rbclbr.py

changeset 7690
a59680062837
parent 7685
0b6e8c0d6403
child 7781
607a6098cb44
equal deleted inserted replaced
7689:147236d850a4 7690:a59680062837
248 ClbrBaseClasses.Attribute.__init__(self, module, name, file, lineno) 248 ClbrBaseClasses.Attribute.__init__(self, module, name, file, lineno)
249 VisibilityMixin.__init__(self) 249 VisibilityMixin.__init__(self)
250 self.setPrivate() 250 self.setPrivate()
251 251
252 252
253 # TODO: extract scan function (see pyclbr)
254 def readmodule_ex(module, path=None): 253 def readmodule_ex(module, path=None):
255 """ 254 """
256 Read a Ruby file and return a dictionary of classes, functions and modules. 255 Read a Ruby file and return a dictionary of classes, functions and modules.
257 256
258 @param module name of the Ruby file (string) 257 @param module name of the Ruby file (string)
259 @param path path the file should be searched in (list of strings) 258 @param path path the file should be searched in (list of strings)
260 @return the resulting dictionary 259 @return the resulting dictionary
261 """ 260 """
262 global _modules 261 global _modules
263 262
264 dictionary = {}
265 dict_counts = {}
266
267 if module in _modules: 263 if module in _modules:
268 # we've seen this file before... 264 # we've seen this file before...
269 return _modules[module] 265 return _modules[module]
270 266
271 # search the path for the file 267 # search the path for the file
274 f, file, (suff, mode, type) = ClassBrowsers.find_module(module, fullpath) 270 f, file, (suff, mode, type) = ClassBrowsers.find_module(module, fullpath)
275 if f: 271 if f:
276 f.close() 272 f.close()
277 if type not in SUPPORTED_TYPES: 273 if type not in SUPPORTED_TYPES:
278 # not Ruby source, can't do anything with this module 274 # not Ruby source, can't do anything with this module
279 _modules[module] = dictionary 275 _modules[module] = {}
280 return dictionary 276 return {}
281 277
282 _modules[module] = dictionary
283 classstack = [] # stack of (class, indent) pairs
284 acstack = [] # stack of (access control, indent) pairs
285 indent = 0
286 try: 278 try:
287 src = Utilities.readEncodedFile(file)[0] 279 src = Utilities.readEncodedFile(file)[0]
288 except (UnicodeError, IOError): 280 except (UnicodeError, IOError):
289 # can't do anything with this module 281 # can't do anything with this module
290 _modules[module] = dictionary 282 _modules[module] = {}
291 return dictionary 283 return {}
284
285 _modules[module] = scan(src, file, module)
286 return _modules[module]
287
288
289 def scan(src, file, module):
290 """
291 Public method to scan the given source text.
292
293 @param src source text to be scanned
294 @type str
295 @param file file name associated with the source text
296 @type str
297 @param module module name associated with the source text
298 @type str
299 @return dictionary containing the extracted data
300 @rtype dict
301 """
292 # convert eol markers the Python style 302 # convert eol markers the Python style
293 src = src.replace("\r\n", "\n").replace("\r", "\n") 303 src = src.replace("\r\n", "\n").replace("\r", "\n")
304
305 dictionary = {}
306 dict_counts = {}
307
308 classstack = [] # stack of (class, indent) pairs
309 acstack = [] # stack of (access control, indent) pairs
310 indent = 0
294 311
295 lineno, last_lineno_pos = 1, 0 312 lineno, last_lineno_pos = 1, 0
296 cur_obj = None 313 cur_obj = None
297 lastGlobalEntry = None 314 lastGlobalEntry = None
298 i = 0 315 i = 0

eric ide

mercurial