views:

103

answers:

1

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......

+4  A: 

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.

Ninefingers
+1 Parser Generator != ORM
delnan
yes you are right, framework is already there with OSV and ORM, but its like an add-on for that framework, which would be either generated from excel or text file with validating parser.
Tumbleweed
+1 - I think SQLAlchemy is what the OP is looking for
Paul McGuire
No I know sqlAlchemy and Django both, what I want is to generate python class which has predefined structure but it should be generated from Excel so user can directly create classes and views and developers just need to write business logic code, so current framework provides views based on XML file and to create models we've predifned well working OSV and ORM, problem is how to convert xls->csv-->python module !
Tumbleweed
Ah I see. If you're trying to make generated data models I would honestly advice... not doing it. That is why you employ developers / sql people. Or else use UML class generators. Excel isn't really suited to this task - how do you validate what's been input? How do you match Excel fields to SQL fields. And what is the point of ORM when you go from database->abstract class model to talk to a database? The idea is you start with a model that is abstract from the database and go from there. I'd teach your people how to write classes or build a tool that does that directly.
Ninefingers
lol, they knows excel only :-Dso what I proposed is like xls template which will be later on converted to csv for parsing and it will have template likeobject, testfield_name, attribute_type,size, attribute2,.....name,varchar,256and based on this template it would generate the classes which will be accepted by my ORM or rejected with proper error msg.....
Tumbleweed