浏览代码

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 年前
父节点
当前提交
d88e68e16e
共有 5 个文件被更改,包括 26 次插入0 次删除
  1. +1
    -0
      .gitignore
  2. +25
    -0
      bitshift/parser/__init__.py
  3. +0
    -0
     
  4. +0
    -0
     
  5. +0
    -0
     

+ 1
- 0
.gitignore 查看文件

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


+ 25
- 0
bitshift/parser/__init__.py 查看文件

@@ -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
查看文件


+ 0
- 0
查看文件


+ 0
- 0
查看文件


正在加载...
取消
保存