From 3bc748242d29dfec7120e0314061ffece28d2295 Mon Sep 17 00:00:00 2001 From: Benjamin Attal Date: Fri, 18 Apr 2014 15:45:12 -0400 Subject: [PATCH] Refactor parser/__init__.py for new parsing mechanism --- bitshift/parser/__init__.py | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/bitshift/parser/__init__.py b/bitshift/parser/__init__.py index d3915fc..28d3e98 100644 --- a/bitshift/parser/__init__.py +++ b/bitshift/parser/__init__.py @@ -1,40 +1,23 @@ -from .python import parse_py -from .c import parse_c -from ..languages import LANGS -import pygments.lexers as pgl +import os _all__ = ["parse"] -def _lang(codelet): +def parse(codelet): """ - Private function to identify the language of a codelet. + 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 identified. + :param codelet: The codelet object to parsed. :type code: Codelet .. todo:: - Modify function to incorporate tags from stackoverflow. - """ - - if codelet.filename is not None: - return pgl.guess_lexer_for_filename(codelet.filename).name - - return LANGS.index(pgl.guess_lexer(codelet.code)) - -def parse(codelet): - """ - Dispatch codelet to correct parser by language of code. + Create a named pipe for python process to communicate with Java + process. - :param codelet: The codelet object to parsed. + Send the process id and codelet code through the named pipe. - :type code: Codelet + Read the result from the named pipe and turn it into a dict. """ - - lang = _lang(codelet) - - if lang == LANGS.index("Python"): - parse_py(codelet) - elif lang == LANGS.index("C"): - parse_c(codelet) + pass