From d8b234f4629529e07b22b8779e8954c865671a0a Mon Sep 17 00:00:00 2001 From: Benjamin Attal Date: Sun, 27 Apr 2014 22:47:19 -0400 Subject: [PATCH] Update docstrings and parser dispatching in parser init file. --- bitshift/parser/__init__.py | 35 ++++++++++++----------------------- bitshift/parser/java.py | 0 bitshift/parser/ruby.py | 0 3 files changed, 12 insertions(+), 23 deletions(-) create mode 100644 bitshift/parser/java.py create mode 100644 bitshift/parser/ruby.py diff --git a/bitshift/parser/__init__.py b/bitshift/parser/__init__.py index 6f2f898..8d37d74 100644 --- a/bitshift/parser/__init__.py +++ b/bitshift/parser/__init__.py @@ -1,7 +1,9 @@ -import os, ast import pygments.lexers as pgl from ..languages import LANGS from .python import parse_py +from .c import parse_c +from .java import parse_java +from .ruby import parse_ruby _all__ = ["parse"] @@ -24,39 +26,26 @@ def _lang(codelet): 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. + Dispatches the codelet to the correct parser based on its language. :param codelet: The codelet object to parsed. :param pid: The id of the current python process. :type code: Codelet :param pid: str. - - .. todo:: - Identify languages using pygments and change the write file based on - that. """ - codelet.language = _lang(codelet) + lang = _lang(codelet) - if codelet.language == LANGS.index("Python"): + if lang == LANGS.index("Python"): parse_py(codelet) - else: - write_f = "../../tmp/%d_parser.proc" % codelet.language - - 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 = '' + elif lang == LANGS.index("C"): + parse_c(codelet) - while data == '': - with open(read_f) as rf: - data = rf.read() + elif lang == LANGS.index("Java"): + parse_java(codelet) - os.remove(read_f) - codelet.symbols = ast.literal_eval(data.split(',')[1]) + elif lang == LANGS.index("Ruby"): + parse_ruby(codelet) diff --git a/bitshift/parser/java.py b/bitshift/parser/java.py new file mode 100644 index 0000000..e69de29 diff --git a/bitshift/parser/ruby.py b/bitshift/parser/ruby.py new file mode 100644 index 0000000..e69de29