Browse Source

Update class names. Move language ids to languages.py

tags/v1.0^2
Benjamin Attal 10 years ago
parent
commit
a8f918f7c4
8 changed files with 17 additions and 27 deletions
  1. +3
    -0
      .gitmodules
  2. +0
    -10
      bitshift/config.py
  3. +2
    -0
      bitshift/languages.py
  4. +5
    -8
      bitshift/parser/__init__.py
  5. +3
    -3
      bitshift/parser/c.py
  6. +0
    -3
      bitshift/parser/java.py
  7. +1
    -0
      bitshift/parser/pylj
  8. +3
    -3
      bitshift/parser/python.py

+ 3
- 0
.gitmodules View File

@@ -0,0 +1,3 @@
[submodule "bitshift/parser/pylj"]
path = bitshift/parser/pylj
url = git@github.com:musiKk/plyj.git

+ 0
- 10
bitshift/config.py View File

@@ -4,13 +4,3 @@ Module to contain definitions of all Flask variables required by the app module.


DEBUG = True DEBUG = True
SECRET_KEY = "\x89\x87\x9a9\xab{\xda\xfe.28\xb4\x18\x01\x95]]\xd2\xeaen\xe0Ot" 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
}

+ 2
- 0
bitshift/languages.py View File

@@ -0,0 +1,2 @@

LANGS = ["Python", "C"]

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

@@ -1,7 +1,6 @@
from .python import parse_py from .python import parse_py
from .c import parse_c 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 import pygments.lexers as pgl


_all__ = ["parse"] _all__ = ["parse"]
@@ -21,9 +20,9 @@ def _lang(codelet):
if codelet.filename is not None: if codelet.filename is not None:
return pgl.guess_lexer_for_filename(codelet.filename).name 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. Dispatch codelet to correct parser by language of code.


@@ -34,10 +33,8 @@ def parser(codelet):


lang = _lang(codelet) lang = _lang(codelet)


if lang == LANG_PYTHON:
if lang == LANGS.index("Python"):
parse_py(codelet) parse_py(codelet)
elif lang == LANG_C:
elif lang == LANGS.index("C"):
parse_c(codelet) parse_c(codelet)
elif lang == LANG_JAVA:
parse_java(codelet)



+ 3
- 3
bitshift/parser/c.py View File

@@ -1,6 +1,6 @@
from pycparser import c_parser, c_ast 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. Local node visitor for c abstract syntax trees.


@@ -18,7 +18,7 @@ class CTreeCutter(c_ast.NodeVisitor):


def __init__(self): def __init__(self):
""" """
Create a CTreeCutter instance.
Create a _TreeCutter instance.
""" """


self.accum = {'vars': {}, 'functions': {}, 'structs': {}} self.accum = {'vars': {}, 'functions': {}, 'structs': {}}
@@ -101,6 +101,6 @@ def parse_c(codelet):
""" """


tree = c_parser.CParser().parse(codelet.code) tree = c_parser.CParser().parse(codelet.code)
cutter = CTreeCutter()
cutter = _TreeCutter()
cutter.visit(tree) cutter.visit(tree)
codelet.symbols = cutter.accum codelet.symbols = cutter.accum

+ 0
- 3
bitshift/parser/java.py View File

@@ -1,3 +0,0 @@

def parse_java():
pass

+ 1
- 0
bitshift/parser/pylj

@@ -0,0 +1 @@
Subproject commit 323dd4e266b47579aef2347e68214a6fbe083add

+ 3
- 3
bitshift/parser/python.py View File

@@ -1,6 +1,6 @@
import ast import ast


class PyTreeCutter(ast.NodeVisitor):
class _TreeCutter(ast.NodeVisitor):
""" """
Local node visitor for python abstract syntax trees. Local node visitor for python abstract syntax trees.


@@ -18,7 +18,7 @@ class PyTreeCutter(ast.NodeVisitor):


def __init__(self): def __init__(self):
""" """
Create a PyTreeCutter instance.
Create a _TreeCutter instance.
""" """


self.accum = {'vars': {}, 'functions': {}, 'classes': {}} self.accum = {'vars': {}, 'functions': {}, 'classes': {}}
@@ -121,6 +121,6 @@ def parse_py(codelet):
""" """


tree = ast.parse(codelet.code) tree = ast.parse(codelet.code)
cutter = PyTreeCutter()
cutter = _TreeCutter()
cutter.visit(tree) cutter.visit(tree)
codelet.symbols = cutter.accum codelet.symbols = cutter.accum

Loading…
Cancel
Save