antlr生成python代码可行吗?
要求是生成几个继承 ORM 基类的类, 这个类可能有几个静态属性,如列和其他东西, 以及一些可以在运行时针对小型业务逻辑进行评估的Python表达式,
我的问题是,使用antlr来处理此类事情是可行的,因为我对antlr不太熟悉,但谷歌建议我使用antlr python代码生成器...
请指教......
the requirement is to generate several classes which inherits the base ORM class,
and this class may have several static properties like columns and other things,
and little bit python expressions that can be eval at run time for small business logic,
my question is, it is feasible to use antlr for such kind of things, as I'm not much familiar with antlr but google suggested me to use antlr for python code generator...
please advice......
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你误解了 ANTLR 项目的意义。 ANTLR 是一个解析器生成器,大致意思是:
这对于生成自定义脚本语言和自然语言处理领域非常有用,两者(有效)相关。
你的问题听起来更像是你正在尝试生成一些Python代码来为企业应用程序的业务情况建模(讨厌因为我使用这个术语)。我建议您不要重新发明轮子来实现这一目标,例如 SQLAlchemy 和 Django,两者都提供了基本的 ORM 实现,并允许您派生代表数据并包含处理逻辑的子类。
如果您正在寻找一种解决方案来根据 UML 等描述为您生成此内容,我确信有人也在尝试这样做。
I think you have misunderstood the point of the ANTLR project. ANTLR is a parser generator, which means roughly:
This is useful in generating custom scripting languages and the natural language processing domain, both of which are (effectively) related.
Your problem sounds more like you are trying to generate some python code to model a business situation for an enterprise application (loathe as I am to use that term). Rather than reinvent the wheel I suggest you take a look at existing frameworks for achieving this such as SQLAlchemy and Django, both of which provide a base ORM implementation and allow you to derive subclasses which represent your data and include processing logic.
If you are looking for a solution to generate this for you from a description such as UML, I am sure someone is trying to do this too.