Ver código fonte

Add dispatch 'parse' function to parser __init__.py. Basic code language identification as well. Included pycparser as a depedency.

tags/v1.0^2
Benjamin Attal 10 anos atrás
pai
commit
d88e68e16e
5 arquivos alterados com 26 adições e 0 exclusões
  1. +1
    -0
      .gitignore
  2. +25
    -0
      bitshift/parser/__init__.py
  3. +0
    -0
     
  4. +0
    -0
     
  5. +0
    -0
     

+ 1
- 0
.gitignore Ver arquivo

@@ -1,3 +1,4 @@
*.swp
.sass-cache .sass-cache
.DS_Store .DS_Store
.my.cnf .my.cnf


+ 25
- 0
bitshift/parser/__init__.py Ver arquivo

@@ -0,0 +1,25 @@
from .python import parse_py
from .c import parse_c
from .java import parse_java
import pygments.lexers as pgl

_all__ = ["parse"]

# TODO: modify to incorporate tags from stackoverflow
def _lang(codelet):
if codelet.filename is not None:
return pgl.guess_lexer_for_filename(codelet.filename).name

return pgl.guess_lexer(codelet.code)

# dispatches the codelet to the correct parser
def parser(codelet):
lang = _lang(codelet)

if lang == "Python":
parse_py(codelet)
elif lang == "C":
parse_c(codelet)
elif lang == "Java":
parse_java(codelet)


+ 0
- 0
Ver arquivo


+ 0
- 0
Ver arquivo


+ 0
- 0
Ver arquivo


Carregando…
Cancelar
Salvar