| @@ -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"] | _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 | :type code: Codelet | ||||
| .. todo:: | .. 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 | |||||