473,508 Members | 2,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Language Work Benches in Py

Hi,
I recently read Martin Fowler's article on language workbenches and
domain specific
languages(http://www.martinfowler.com/articles...orkbench.html).
I then had the pleasure of reading Rainer Jowsig's implementation of
the sample in Lisp(http://lispm.dyndns.org/news?ID=NEWS-2005-07-08-1).

The lisp code was so sexy that I was inspired to write a sample in
Python. I'm relatively new to coding in Python so I'd love any barbs,
comments or criticisms about the code. You can find my article here :
(http://billionairebusinessman.blogsp...hands-in.html).

I also made a screen cast of the same
(http://openenterpriseafrica.com/neo/...ython.wmv.bz2).
Unfortunately, I had to make it using a windows machine so it's encoded
as wmv. (If anyone finds it useful and is inspired to encode it in a
more palatable format e.g. mov, I'd be honoured to create a torrent and
host it)

Sep 3 '05 #1
1 991
I realize that I forgot to post the sample code:). Below is my
implementation:

#DSL data
#1234567890123456789012345678901234567890123456789 01234567890,

dsldata=(
'SVCLFOWLER 10101MS0120050313.........................',
'SVCLHOHPE 10201DX0320050315........................',
'SVCLTWO x10301MRP220050329..............................',
'USGE10301TWO x50214..7050329...............................')

#Class mappings
Mappings={'svcl':{
(4,18):'CustomerName',
(19,23):'CustomerID',
(24,27) :'CallTypeCode',
(28,35) : 'DateOfCallString'},
'usge':{(4,8) :'CustomerID',
(9,22):'CustomerName',
(30,30):'Cycle',
(31,36): 'ReadDate'}}
def generateClass(data):
'generate the class and instance with attributes'

className = data[:4].lower() #1)
mappingData= Mappings[className] #2)
class Klass:pass #3)
Klass. __name__=className #4)
# print Klass

for key in mappingData.keys(): #5)
fielddata=data[key[0]:key[1]]
print 'actual data->',fielddata
setattr(Klass,mappingData[key],fielddata) #6)
return Klass
def parseData():
'parse the data and generate a list of objects'
classes= [generateClass(item) for item in dsldata]
return classes

def printKlassData(Klass):
print Klass
for key in Klass.__dict__:
print ('attr->%s value->%s')%(key,Klass.__dict__[key])

if __name__=='__main__':
for Klass in parseData():
printKlassData (Klass)

Sep 7 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

49
2791
by: Ville Vainio | last post by:
I don't know if you have seen this before, but here goes: http://text.userlinux.com/white_paper.html There is a jab at Python, though, mentioning that Ruby is more "refined". -- Ville...
7
1623
by: has | last post by:
<BLUSH> Careless talk costs lives, as they say. In my case, a throwaway comment that Python could trounce the notoriously underpowered and undersupported AppleScript language for "serious number...
33
2692
by: Quest Master | last post by:
I am interested in developing an application where the user has an ample amount of power to customize the application to their needs, and I feel this would best be accomplished if a scripting...
1
1293
by: marina madeleine | last post by:
Could some clarify for me - I thought the scripting language for Access was SQL and that to script in Access one would need to learn SQL. Why then is the Access database under visual basic? What...
22
13642
by: Matt | last post by:
Some people identify Microsoft C# is Proprietary programming language. What is Proprietary programming language then? How does it differ from other languages such as C++, or Java?? Please...
25
2548
by: Dave | last post by:
I want to spend two minutes on my soapbox. I love C#. I am so productive in it it's ridiculous. But it's so easy to write code that uses poor design principles. Example: just making...
13
4474
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
27
1841
by: notnorwegian | last post by:
(might not be the right forum for this but...) what is the definition of a highlevel-language? well there isnt one specifically and wikipedia and the like gives just a very general description...
4
2301
by: edgy | last post by:
Hello, I am a beginner with PHP, and I have made a language switcher on a site that I am looking for your feedback on. First of all, the page is http://www.mankar.ca My question regarding...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7383
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4707
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3194
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1557
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.