From 4cc0626a710f54917875362d064a8e9d21de293f Mon Sep 17 00:00:00 2001 From: Benjamin Attal Date: Mon, 28 Apr 2014 17:17:22 -0400 Subject: [PATCH] Catch ClassNotFound error in parser __init__.py --- bitshift/parser/__init__.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/bitshift/parser/__init__.py b/bitshift/parser/__init__.py index 571e25d..5522ae6 100644 --- a/bitshift/parser/__init__.py +++ b/bitshift/parser/__init__.py @@ -4,6 +4,9 @@ from .python import parse_py _all__ = ["parse"] +class UnsupportedFileError(Exception): + pass + def _lang(codelet): """ Private function to identify the language of a codelet. @@ -16,10 +19,13 @@ def _lang(codelet): Modify function to incorporate tags from stackoverflow. """ - if codelet.filename is not None: - return pgl.guess_lexer_for_filename(codelet.filename).name + try: + if codelet.filename is not None: + return pgl.guess_lexer_for_filename(codelet.filename, '').name - return LANGS.index(pgl.guess_lexer(codelet.code)) + return LANGS.index(pgl.guess_lexer(codelet.code)) + except: + raise UnsupportedFileError('Could not find a lexer for the codelet\'s filename') def _recv_data(server_socket): """ @@ -61,6 +67,9 @@ def _recv_data(server_socket): def parse(codelet): """ Dispatches the codelet to the correct parser based on its language. + It is the job of the respective parsers to accumulate data about the + code and to convert it into a string representing a python dict. + The codelet is then given dict as its 'symbols' field. :param codelet: The codelet object to parsed. @@ -68,6 +77,7 @@ def parse(codelet): """ lang = _lang(codelet); source = codelet.code + codelet.language = lang server_socket_number = 5000 + lang if lang == LANGS.index('Python'):