diff --git a/bitshift/config.py b/bitshift/config.py index 6c7be42..e69e367 100644 --- a/bitshift/config.py +++ b/bitshift/config.py @@ -4,3 +4,13 @@ Module to contain definitions of all Flask variables required by the app module. DEBUG = True SECRET_KEY = "\x89\x87\x9a9\xab{\xda\xfe.28\xb4\x18\x01\x95]]\xd2\xeaen\xe0Ot" + +LANG_PYTHON = 0 +LANG_C = 1 +LANG_JAVA = 2 + +PYG_IDS = { + "Python": LANG_PYTHON, + "C": LANG_C, + "JAVA": LANG_JAVA +} diff --git a/bitshift/parser/__init__.py b/bitshift/parser/__init__.py index 03d812c..3220a73 100644 --- a/bitshift/parser/__init__.py +++ b/bitshift/parser/__init__.py @@ -1,6 +1,7 @@ from .python import parse_py from .c import parse_c from .java import parse_java +from bitshift.config import LANG_PYTHON, LANG_C, LANG_JAVA, PYG_IDS import pygments.lexers as pgl _all__ = ["parse"] @@ -17,7 +18,7 @@ def _lang(codelet): if codelet.filename is not None: return pgl.guess_lexer_for_filename(codelet.filename).name - return pgl.guess_lexer(codelet.code) + return PYG_IDS[pgl.guess_lexer(codelet.code)] def parser(codelet): """ @@ -29,10 +30,10 @@ def parser(codelet): """ lang = _lang(codelet) - if lang == "Python": + if lang == LANG_PYTHON: parse_py(codelet) - elif lang == "C": + elif lang == LANG_C: parse_c(codelet) - elif lang == "Java": + elif lang == LANG_JAVA: parse_java(codelet)