From a8f918f7c4dc9810d5ecd06c14ef87b2f757ee32 Mon Sep 17 00:00:00 2001 From: Benjamin Attal Date: Fri, 18 Apr 2014 15:36:38 -0400 Subject: [PATCH] Update class names. Move language ids to languages.py --- .gitmodules | 3 +++ bitshift/config.py | 10 ---------- bitshift/languages.py | 2 ++ bitshift/parser/__init__.py | 13 +++++-------- bitshift/parser/c.py | 6 +++--- bitshift/parser/java.py | 3 --- bitshift/parser/pylj | 1 + bitshift/parser/python.py | 6 +++--- 8 files changed, 17 insertions(+), 27 deletions(-) create mode 100644 .gitmodules create mode 100644 bitshift/languages.py delete mode 100644 bitshift/parser/java.py create mode 160000 bitshift/parser/pylj diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..afd8277 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "bitshift/parser/pylj"] + path = bitshift/parser/pylj + url = git@github.com:musiKk/plyj.git diff --git a/bitshift/config.py b/bitshift/config.py index e69e367..6c7be42 100644 --- a/bitshift/config.py +++ b/bitshift/config.py @@ -4,13 +4,3 @@ 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/languages.py b/bitshift/languages.py new file mode 100644 index 0000000..6775711 --- /dev/null +++ b/bitshift/languages.py @@ -0,0 +1,2 @@ + +LANGS = ["Python", "C"] diff --git a/bitshift/parser/__init__.py b/bitshift/parser/__init__.py index 3476487..d3915fc 100644 --- a/bitshift/parser/__init__.py +++ b/bitshift/parser/__init__.py @@ -1,7 +1,6 @@ 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 +from ..languages import LANGS import pygments.lexers as pgl _all__ = ["parse"] @@ -21,9 +20,9 @@ def _lang(codelet): if codelet.filename is not None: return pgl.guess_lexer_for_filename(codelet.filename).name - return PYG_IDS[pgl.guess_lexer(codelet.code)] + return LANGS.index(pgl.guess_lexer(codelet.code)) -def parser(codelet): +def parse(codelet): """ Dispatch codelet to correct parser by language of code. @@ -34,10 +33,8 @@ def parser(codelet): lang = _lang(codelet) - if lang == LANG_PYTHON: + if lang == LANGS.index("Python"): parse_py(codelet) - elif lang == LANG_C: + elif lang == LANGS.index("C"): parse_c(codelet) - elif lang == LANG_JAVA: - parse_java(codelet) diff --git a/bitshift/parser/c.py b/bitshift/parser/c.py index 7754b81..50ee6eb 100644 --- a/bitshift/parser/c.py +++ b/bitshift/parser/c.py @@ -1,6 +1,6 @@ from pycparser import c_parser, c_ast -class CTreeCutter(c_ast.NodeVisitor): +class _TreeCutter(c_ast.NodeVisitor): """ Local node visitor for c abstract syntax trees. @@ -18,7 +18,7 @@ class CTreeCutter(c_ast.NodeVisitor): def __init__(self): """ - Create a CTreeCutter instance. + Create a _TreeCutter instance. """ self.accum = {'vars': {}, 'functions': {}, 'structs': {}} @@ -101,6 +101,6 @@ def parse_c(codelet): """ tree = c_parser.CParser().parse(codelet.code) - cutter = CTreeCutter() + cutter = _TreeCutter() cutter.visit(tree) codelet.symbols = cutter.accum diff --git a/bitshift/parser/java.py b/bitshift/parser/java.py deleted file mode 100644 index a495a10..0000000 --- a/bitshift/parser/java.py +++ /dev/null @@ -1,3 +0,0 @@ - -def parse_java(): - pass diff --git a/bitshift/parser/pylj b/bitshift/parser/pylj new file mode 160000 index 0000000..323dd4e --- /dev/null +++ b/bitshift/parser/pylj @@ -0,0 +1 @@ +Subproject commit 323dd4e266b47579aef2347e68214a6fbe083add diff --git a/bitshift/parser/python.py b/bitshift/parser/python.py index 8c59301..1e011fb 100644 --- a/bitshift/parser/python.py +++ b/bitshift/parser/python.py @@ -1,6 +1,6 @@ import ast -class PyTreeCutter(ast.NodeVisitor): +class _TreeCutter(ast.NodeVisitor): """ Local node visitor for python abstract syntax trees. @@ -18,7 +18,7 @@ class PyTreeCutter(ast.NodeVisitor): def __init__(self): """ - Create a PyTreeCutter instance. + Create a _TreeCutter instance. """ self.accum = {'vars': {}, 'functions': {}, 'classes': {}} @@ -121,6 +121,6 @@ def parse_py(codelet): """ tree = ast.parse(codelet.code) - cutter = PyTreeCutter() + cutter = _TreeCutter() cutter.visit(tree) codelet.symbols = cutter.accum