From a1066dd0936dd8b67fbebdad2fac8babb1f1c4e5 Mon Sep 17 00:00:00 2001 From: Benjamin Attal Date: Fri, 18 Apr 2014 16:31:43 -0400 Subject: [PATCH] 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. --- bitshift/parser/__init__.py | 26 +++++++++++++++++++--- parsers/src/org/bitshift/parsers/Parse.java | 0 .../src/org/bitshift/parsers/langs/CParser.java | 0 .../src/org/bitshift/parsers/langs/JavaParser.java | 0 .../org/bitshift/parsers/langs/PythonParser.java | 0 .../src/org/bitshift/parsers/langs/RubyParser.java | 0 6 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 parsers/src/org/bitshift/parsers/Parse.java create mode 100644 parsers/src/org/bitshift/parsers/langs/CParser.java create mode 100644 parsers/src/org/bitshift/parsers/langs/JavaParser.java create mode 100644 parsers/src/org/bitshift/parsers/langs/PythonParser.java create mode 100644 parsers/src/org/bitshift/parsers/langs/RubyParser.java diff --git a/bitshift/parser/__init__.py b/bitshift/parser/__init__.py index 28d3e98..0fe4602 100644 --- a/bitshift/parser/__init__.py +++ b/bitshift/parser/__init__.py @@ -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]) diff --git a/parsers/src/org/bitshift/parsers/Parse.java b/parsers/src/org/bitshift/parsers/Parse.java new file mode 100644 index 0000000..e69de29 diff --git a/parsers/src/org/bitshift/parsers/langs/CParser.java b/parsers/src/org/bitshift/parsers/langs/CParser.java new file mode 100644 index 0000000..e69de29 diff --git a/parsers/src/org/bitshift/parsers/langs/JavaParser.java b/parsers/src/org/bitshift/parsers/langs/JavaParser.java new file mode 100644 index 0000000..e69de29 diff --git a/parsers/src/org/bitshift/parsers/langs/PythonParser.java b/parsers/src/org/bitshift/parsers/langs/PythonParser.java new file mode 100644 index 0000000..e69de29 diff --git a/parsers/src/org/bitshift/parsers/langs/RubyParser.java b/parsers/src/org/bitshift/parsers/langs/RubyParser.java new file mode 100644 index 0000000..e69de29