浏览代码

Modify parser/__init__.py so that it communicates with the Java parsing process and reads a result back from a unique file. Add template files for Java parsers.

tags/v1.0^2
Benjamin Attal 10 年前
父节点
当前提交
a1066dd093
共有 6 个文件被更改,包括 23 次插入3 次删除
  1. +23
    -3
      bitshift/parser/__init__.py
  2. +0
    -0
     
  3. +0
    -0
     
  4. +0
    -0
     
  5. +0
    -0
     
  6. +0
    -0
     

+ 23
- 3
bitshift/parser/__init__.py 查看文件

@@ -1,15 +1,19 @@
import os
import os, ast


_all__ = ["parse"] _all__ = ["parse"]


def parse(codelet):
WRITE_F = "../../tmp/parser.proc"

def parse(codelet, pid):
""" """
Sends codelet code to the Java parsing process via a named pipe. Reads the Sends codelet code to the Java parsing process via a named pipe. Reads the
resulting symbols from the pipe and updates the codelet. resulting symbols from the pipe and updates the codelet.


:param codelet: The codelet object to parsed. :param codelet: The codelet object to parsed.
:param pid: The id of the current python process.


:type code: Codelet :type code: Codelet
:param pid: str.


.. todo:: .. todo::
Create a named pipe for python process to communicate with Java Create a named pipe for python process to communicate with Java
@@ -19,5 +23,21 @@ def parse(codelet):


Read the result from the named pipe and turn it into a dict. Read the result from the named pipe and turn it into a dict.
""" """
pass

with open(WRITE_F, 'a') as wf:
wf.write('pid:' + str(pid) + '\n')
wf.write('body:\n' + codelet.code)

read_f = '../../tmp/%s_py.data' % str(pid)
data = ''

while data == '':
with open(read_f) as rf:
data = rf.read()

os.remove(read_f)

results = data.split('\n')
codelet.language = results[0].split(',')[1]
codelet.symbols = ast.literal_eval(results[1].split(',')[1])



+ 0
- 0
查看文件


+ 0
- 0
查看文件


+ 0
- 0
查看文件


+ 0
- 0
查看文件


+ 0
- 0
查看文件


正在加载...
取消
保存