macro_extractor.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:skydoc 作者: bazelbuild 项目源码 文件源码
def _add_macro_doc(self, stmt):
    # The defaults array contains default values for the last arguments.
    # The first shift arguments are mandatory.
    shift = len(stmt.args.args) - len(stmt.args.defaults)

    rule = self.__language.rule.add()
    rule.name = stmt.name
    rule.type = build_pb2.RuleDefinition.MACRO

    doc = ast.get_docstring(stmt)
    if doc:
      extracted_docs = common.parse_docstring(doc)
      rule.documentation = extracted_docs.doc
      if extracted_docs.example_doc:
        rule.example_documentation = extracted_docs.example_doc
    else:
      extracted_docs = common.ExtractedDocs(
          doc="", attr_docs={}, example_doc="", output_docs={})

    for i in range(len(stmt.args.args)):
      attr = rule.attribute.add()
      attr_name = stmt.args.args[i].id
      attr.name = attr_name

      if attr_name in extracted_docs.attr_docs:
        attr.documentation = extracted_docs.attr_docs[attr_name]

      if i < shift:  # The first arguments are mandatory
        attr.mandatory = True
        attr.type = build_pb2.Attribute.UNKNOWN
      else:
        node = stmt.args.defaults[i - shift]
        attr.mandatory = False
        attr.type = get_type(node)
        if attr.type == build_pb2.Attribute.BOOLEAN:
          attr.default = node.id

    for template, doc in extracted_docs.output_docs.iteritems():
      output = rule.output.add()
      output.template = template
      output.documentation = doc
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号