277 self.__dict["@@Globals@@"]._addglobal( |
277 self.__dict["@@Globals@@"]._addglobal( |
278 Attribute(self.__module, "const " + var.name, |
278 Attribute(self.__module, "const " + var.name, |
279 self.__file, var.line)) |
279 self.__file, var.line)) |
280 |
280 |
281 |
281 |
282 # TODO: extract scan function (see pyclbr) |
|
283 def readmodule_ex(module, path=None): |
282 def readmodule_ex(module, path=None): |
284 """ |
283 """ |
285 Read a JavaScript file and return a dictionary of functions and variables. |
284 Read a JavaScript file and return a dictionary of functions and variables. |
286 |
285 |
287 @param module name of the JavaScript file (string) |
286 @param module name of the JavaScript file (string) |
288 @param path path the file should be searched in (list of strings) |
287 @param path path the file should be searched in (list of strings) |
289 @return the resulting dictionary |
288 @return the resulting dictionary |
290 """ |
289 """ |
291 global _modules |
290 global _modules |
292 |
291 |
293 dictionary = {} |
|
294 |
|
295 if module in _modules: |
292 if module in _modules: |
296 # we've seen this file before... |
293 # we've seen this file before... |
297 return _modules[module] |
294 return _modules[module] |
298 |
295 |
299 # search the path for the file |
296 # search the path for the file |
302 f, file, (suff, mode, type) = ClassBrowsers.find_module(module, fullpath) |
299 f, file, (suff, mode, type) = ClassBrowsers.find_module(module, fullpath) |
303 if f: |
300 if f: |
304 f.close() |
301 f.close() |
305 if type not in SUPPORTED_TYPES: |
302 if type not in SUPPORTED_TYPES: |
306 # not CORBA IDL source, can't do anything with this module |
303 # not CORBA IDL source, can't do anything with this module |
307 _modules[module] = dictionary |
304 _modules[module] = {} |
308 return dictionary |
305 return {} |
309 |
306 |
310 _modules[module] = dictionary |
|
311 try: |
307 try: |
312 src = Utilities.readEncodedFile(file)[0] |
308 src = Utilities.readEncodedFile(file)[0] |
313 except (UnicodeError, IOError): |
309 except (UnicodeError, IOError): |
314 # can't do anything with this module |
310 # can't do anything with this module |
315 _modules[module] = dictionary |
311 _modules[module] = {} |
316 return dictionary |
312 return {} |
|
313 |
|
314 _modules[module] = scan(src, file, module) |
|
315 return _modules[module] |
|
316 |
|
317 |
|
318 def scan(src, file, module): |
|
319 """ |
|
320 Public method to scan the given source text. |
|
321 |
|
322 @param src source text to be scanned |
|
323 @type str |
|
324 @param file file name associated with the source text |
|
325 @type str |
|
326 @param module module name associated with the source text |
|
327 @type str |
|
328 @return dictionary containing the extracted data |
|
329 @rtype dict |
|
330 """ |
317 # convert eol markers the Python style |
331 # convert eol markers the Python style |
318 src = src.replace("\r\n", "\n").replace("\r", "\n") |
332 src = src.replace("\r\n", "\n").replace("\r", "\n") |
319 |
333 |
|
334 dictionary = {} |
|
335 |
320 visitor = Visitor(src, module, file) |
336 visitor = Visitor(src, module, file) |
321 dictionary = visitor.parse() |
337 dictionary = visitor.parse() |
322 _modules[module] = dictionary |
338 _modules[module] = dictionary |
323 return dictionary |
339 return dictionary |