A semantic search engine for source code https://bitshift.benkurtovic.com/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

44 regels
1.1 KiB

  1. import os, ast
  2. _all__ = ["parse"]
  3. WRITE_F = "../../tmp/parser.proc"
  4. def parse(codelet, pid):
  5. """
  6. Sends codelet code to the Java parsing process via a named pipe. Reads the
  7. resulting symbols from the pipe and updates the codelet.
  8. :param codelet: The codelet object to parsed.
  9. :param pid: The id of the current python process.
  10. :type code: Codelet
  11. :param pid: str.
  12. .. todo::
  13. Create a named pipe for python process to communicate with Java
  14. process.
  15. Send the process id and codelet code through the named pipe.
  16. Read the result from the named pipe and turn it into a dict.
  17. """
  18. with open(WRITE_F, 'a') as wf:
  19. wf.write('pid:' + str(pid) + '\n')
  20. wf.write('body:\n' + codelet.code)
  21. read_f = '../../tmp/%s_py.data' % str(pid)
  22. data = ''
  23. while data == '':
  24. with open(read_f) as rf:
  25. data = rf.read()
  26. os.remove(read_f)
  27. results = data.split('\n')
  28. codelet.language = results[0].split(',')[1]
  29. codelet.symbols = ast.literal_eval(results[1].split(',')[1])