Parsing files in python

Kene Meniru kene.meniru at illom.org
Sun Dec 23 18:19:55 CET 2012


Hello: I am writing a program that is made up of a collection of POV-Ray macros. POV-Ray is available at povray.org. It is a ray-tracing program that reads a scene description language (SDL) to create photo-realistic images. At this time my program (for modeling building information) is so huge that I am finding it difficult managing the macros and I am not even near completion.

I am hoping to move this program to python and am wondering the best way to approach this.

I would like to model my program after LaTeX. Basically the user writes a text file using certain key words and numbers and my python program reads this file, calls the classes that will then work together to calculate the information that is needed to create an accurate model. The result of this calculation will be an output to another text file in the appropriate format such as POV-Ray SDL, OpenSCAD script, etc. This file output can then be rendered by the corresponding program to produce the actual 3D model. The macros I have now currently does this but like I said it is getting tedious and most importantly the fun factor is losing its strength for me.

I have been advised to check out python-ply and I have come across others. I have not really tried any yet and before I dive into any one of them I was wondering what else I should know. The following is a sample of what the text file that will be processed by this proposed system will contain. I appreciate any pointers and suggestions. Thank you very much.

------------possible user file content for parsing ------------
// in the following the python interface program reads
//+ the contents of the file "other.file" as if its content
//+ were located at this point.
include other.file

//In the following the python interface makes "snap_size" a
//+  global parameter
declare snap_size = 10


// In the following "buildingLevel" is a class that is
//+  called and passed the parameters in parenthesis.
buildingLevel("FirstLevel", 3000)

// In the following "snapOffset" is a class that is
//+  called and passed the parameters in parenthesis.
snapOffset("Closet-S1_r1", "Closet-S2_r3", <0,0,0>)
------------end of user file content

It should also be possible to include comments using double-slashes, etc.

Sincerely,
Kene (kemeniru at gmail.com)



More information about the Python-list mailing list