antlr生成python代码可行吗?

发布于 2024-09-13 16:38:23 字数 176 浏览 6 评论 0原文

要求是生成几个继承 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若相惜即相离 2024-09-20 16:38:23

我认为你误解了 ANTLR 项目的意义。 ANTLR 是一个解析器生成器,大致意思是:

  • 您为您选择的语言创建一个语法器。这很可能是Python,或者是Python 的混合体。
  • 您通过 ANTLR 运行它,它为您提供多种能够解析您的语言的语言的代码。

这对于生成自定义脚本语言和自然语言处理领域非常有用,两者(有效)相关。

你的问题听起来更像是你正在尝试生成一些Python代码来为企业应用程序的业务情况建模(讨厌因为我使用这个术语)。我建议您不要重新发明轮子来实现这一目标,例如 SQLAlchemyDjango,两者都提供了基本的 ORM 实现,并允许您派生代表数据并包含处理逻辑的子类。

如果您正在寻找一种解决方案来根据 UML 等描述为您生成此内容,我确信有人也在尝试这样做。

I think you have misunderstood the point of the ANTLR project. ANTLR is a parser generator, which means roughly:

  • You create a grammer for a language of your choosing. This could well be python, or a hybrid of it.
  • You run it through ANTLR which gives you code in a number of Languages capable of parsing your language.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文