srcgen:语义源代码生成框架
项目描述
srcgen
Srcgen是一个语义代码生成框架。语义意味着代码生成器和生成的代码具有相似的结构;例如,if语句的主体在生成代码和生成的代码中都是缩进的。这里有一个简短的例子
>>> from srcgen.python import PythonModule
>>>
>>> m = PythonModule("foo")
>>> m.import_("sys")
>>> m.import_("os")
>>> m.sep()
>>> m.stmt("x = 5")
>>> with m.if_("x > 8"):
... m.stmt("print 'oh no'")
...
>>> with m.else_():
... m.stmt("print 'oh yes'")
...
>>> print m
import sys
import os
x = 5
if x > 8:
print 'oh no'
else:
print 'oh yes'
当然,您可以嵌套得更深,也可以将常见的代码片段提取到函数中
m = PythonModule("foo")
with m.class_("MyClass"):
with m.method("__init__", "
语言
目前Srcgen支持
C
Python
Cython
HTML/XML
根据公众需求将添加更多语言(欢迎加入我们的努力!)
项目详情
下载文件
下载您平台上的文件。如果您不确定要选择哪个,请了解更多关于安装包的信息。
源分布
srcgen-1.1.0.zip (14.2 kB 查看哈希值)
srcgen-1.1.0.tar.gz (10.3 kB 查看哈希值)
构建发行版
srcgen-1.1.0.win32.exe (208.7 kB 查看哈希值)