python - pcpp预处理器API怎么用?
问题描述
我有一个 C 头文件,需要对其进行解析以在构建时进行一些检查。所以我目前正在尝试使用pcpp
它。除了源代码中的注释外,我在github上没有找到任何关于如何使用 API 的示例。示例参考似乎不再起作用。我尝试了以下方法:
#!/usr/bin/python3.7
import sys
import pcpp
def check_directive(directive):
#do the checking
#...
class Checker(pcpp.Preprocessor):
def on_directive_handle(self, directive, toks, ifpassthru, precedingtoks):
print("Checking directive...")
check_directive(directive)
super(pcpp.Preprocessor, on_directive_handle)
if __name__ == "__main__":
c_header_path = sys.argv[1]
with open(c_header_path) as fd:
c_header = fd.read()
checker = Checker()
checker.parsegen(c_header)
但是没有进行检查,也没有Checking directive...
产生诊断输出。
有人可以提供使用 API 的工作示例吗?或者可能为这种任务建议另一个 python 模块?
解决方案
推荐阅读
- android - 在 Android Studio 中从 Activity 更改为 Fragment
- node.js - File Watcher 给出错误代码 255 - Syntaxerror
- twilio-studio - 工作室通话结束时的 URL?
- dart - Flutter:无法允许用户输入
- powershell - 直到再次循环或循环结束,Powershell 输出才会显示
- python - Python re.findall 在某些网站上挂起
- shell - 不知道为什么我的 cronjob 在 Ubuntu 16.04 中重新启动时没有运行
- html - 如何在我的 html 项目中上传和使用 .CSS、.js 和一些音频文件?(所以只需要 HTML 文件)
- aframe - 如何使用触摸和拖动和捏合来放大和缩小aframe 0.9.0
- php - 提交表单后显示 [::1] 拒绝连接错误如何解决