浏览代码

Add docstrings for functions in parser. Add ivar for syntax tree to codelet documentation.

tags/v1.0^2
Benjamin Attal 10 年前
父节点
当前提交
efdcb3793a
共有 2 个文件被更改,包括 16 次插入1 次删除
  1. +2
    -0
      bitshift/codelet.py
  2. +14
    -1
      bitshift/parser/__init__.py

+ 2
- 0
bitshift/codelet.py 查看文件

@@ -18,6 +18,8 @@ class Codelet(object):
code was last modified.
:ivar rank: (float) A quanitification of the source code's quality, as
per available ratings (stars, forks, upvotes, etc.).
:ivar symbols: Dictionary containing dictionaries of functions, classes,
variable definitions, etc.
"""

def __init__(self, name, code, filename, language, authors, code_url,


+ 14
- 1
bitshift/parser/__init__.py 查看文件

@@ -7,13 +7,26 @@ _all__ = ["parse"]

# TODO: modify to incorporate tags from stackoverflow
def _lang(codelet):
"""
Private function to identify the language of a codelet.

:param codelet: The codelet object to identified.

:type code: 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):
"""
Dispatch codelet to correct parser by language of code.

:param codelet: The codelet object to parsed.

:type code: Codelet
"""
lang = _lang(codelet)

if lang == "Python":


正在加载...
取消
保存