Browse Source

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 years ago
parent
commit
a1066dd093
6 changed files with 23 additions and 3 deletions
  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 View File

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

_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
resulting symbols from the pipe and updates the codelet.

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

:type code: Codelet
:param pid: str.

.. todo::
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.
"""
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
View File


+ 0
- 0
View File


+ 0
- 0
View File


+ 0
- 0
View File


+ 0
- 0
View File


Loading…
Cancel
Save