Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'python,': 0.02; 'syntax': 0.03; 'output': 0.04; '------------': 0.07; 'method,': 0.07; 'parameter': 0.07; 'parsing': 0.07; 'works.': 0.07; 'python': 0.09; 'brackets': 0.09; 'library...': 0.09; 'porting': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'semantics': 0.09; 'subject:files': 0.09; 'subject:python': 0.11; ':-)': 0.13; '(the': 0.15; 'dec': 0.15; '"from': 0.16; '24,': 0.16; 'angle': 0.16; 'cleanly': 0.16; 'directive': 0.16; 'invoked.': 0.16; 'nesting': 0.16; 'parser.': 0.16; 'preprocessor': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'later': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'example.': 0.17; 'saying': 0.18; '(or': 0.18; 'module': 0.19; 'code.': 0.20; 'translate': 0.20; 'parameters': 0.20; 'import': 0.21; 'thanks.': 0.21; 'fairly': 0.21; 'parse': 0.22; 'this:': 0.23; 'script': 0.24; 'least': 0.25; 'header:User- Agent:1': 0.26; 'possibly': 0.27; 'interface': 0.27; "doesn't": 0.28; 'there.': 0.28; 'header:X-Complaints-To:1': 0.28; 'chris': 0.28; 'leverage': 0.29; 'class': 0.29; 'function': 0.30; 'sense': 0.31; 'located': 0.31; 'file': 0.32; 'skip:- 10': 0.32; "aren't": 0.33; 'ones,': 0.33; 'received:comcast.net': 0.33; 'to:addr :python-list': 0.33; 'point.': 0.33; 'skip:- 20': 0.34; 'skip:b 20': 0.34; 'text': 0.34; 'done': 0.34; 'pm,': 0.35; 'something': 0.35; 'received:org': 0.36; 'but': 0.36; 'wanted': 0.36; 'two': 0.37; 'passed': 0.37; 'quite': 0.37; 'subject:: ': 0.38; 'files': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'called': 0.39; 'little': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'sincerely': 0.60; "you'll": 0.62; 'between': 0.63; 'legal': 0.65; 'header:Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'calls,': 0.84; 'effectively,': 0.84; 'voiced': 0.84; 'glad': 0.86 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Kene Meniru Subject: Re: Parsing files in python Followup-To: gmane.comp.python.general Date: Mon, 24 Dec 2012 06:35:06 -0500 Organization: illom.org References: <20121223171955.GB32535@ifeobi.illom.net> <50d82440.d441340a.3779.ffffe491@mx.google.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: c-69-143-75-245.hsd1.md.comcast.net User-Agent: KNode/4.4.7 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Kene.Meniru@illom.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 59 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1356348917 news.xs4all.nl 6951 [2001:888:2000:d::a6]:45201 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35454 Chris Angelico wrote: > On Mon, Dec 24, 2012 at 9:32 PM, Kene Meniru > wrote: >> You are saying I can create a python module that can parse this file >> format without using a system like python-ply? I know how to parse >> strings using python but considering that text files that describe a >> whole building may be quite large I thought perhaps the re module may not >> be adequate. > > Effectively, what you do is leverage the Python parser. Your script > would look like this: > > ------------possible user file content for parsing ------------ > # Boiler-plate to make this work > from pypovray import * > > # in the following the python interface program reads > # the contents of the file "other.file" as if its content > # were located at this point. > import other.file > > #In the following the python interface makes "snap_size" a > # global parameter > snap_size = 10 > > > # In the following "buildingLevel" is a class (or function) 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 > > Note the extreme similarity to your original example. Everything > between the two snip-lines is perfectly legal Python code. (The > semantics of a Python import aren't quite the same as a C preprocessor > #include, so that might need a little tweaking, depending on what you > wanted to achieve there. Possibly "from other.file import *" would do > it.) Instead of writing a file parser, with all the complexities that > that entails, all you need to write is a set of functions/classes that > can be invoked. > > The only part that doesn't work cleanly is the vector, since its > syntax doesn't work in Python. You'll need to use round brackets > instead of angle ones, as in the above example, and on output to > Python, translate them. But that's fairly straight-forward, and by > this method, you get *everything else* done for you - parsing, nesting > of function calls, the entire Python standard library... the works. > > ChrisA Thanks. This makes sense and it is something I can start right away porting my code. Sincerely glad I voiced my thoughts. The import directive will have to be tackled later but that is not for at least a year or so :-)