Browse Source

Add constants in bitshift/config.py for languages instead of just strings.

tags/v1.0^2
Benjamin Attal 10 years ago
parent
commit
903e4ccc05
2 changed files with 15 additions and 4 deletions
  1. +10
    -0
      bitshift/config.py
  2. +5
    -4
      bitshift/parser/__init__.py

+ 10
- 0
bitshift/config.py View File

@@ -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
}

+ 5
- 4
bitshift/parser/__init__.py View File

@@ -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)


Loading…
Cancel
Save