Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'syntax': 0.03; '------------': 0.07; 'parameter': 0.07; 'parser': 0.07; 'parsing': 0.07; 'rest,': 0.07; 'python': 0.09; 'macros': 0.09; 'subject:files': 0.09; 'way:': 0.09; 'def': 0.10; 'subject:python': 0.11; 'language': 0.14; 'dec': 0.15; '24,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hello:': 0.16; 'hmm.': 0.16; 'instance:': 0.16; 'macros.': 0.16; 'top:': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'instance,': 0.17; 'input': 0.18; 'parameters': 0.20; 'import': 0.21; 'fairly': 0.21; 'pipe': 0.22; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'wonder': 0.27; 'message-id:@mail.gmail.com': 0.27; 'interface': 0.27; "doesn't": 0.28; 'there.': 0.28; 'received:209.85.212': 0.28; 'actual': 0.28; 'surprised': 0.29; "they'll": 0.29; 'vector': 0.29; 'class': 0.29; "i'm": 0.29; 'located': 0.31; 'code': 0.31; 'file': 0.32; 'skip:- 10': 0.32; 'comments': 0.33; 'to:addr :python-list': 0.33; 'point.': 0.33; 'skip:- 20': 0.34; "can't": 0.34; 'skip:b 20': 0.34; 'received:google.com': 0.34; 'needed': 0.35; 'whatever': 0.35; 'problem,': 0.35; 'software,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'should': 0.36; 'possible': 0.37; 'available.': 0.37; 'does': 0.37; '(for': 0.37; 'passed': 0.37; 'rather': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'comment': 0.38; 'description': 0.39; 'to:addr:python.org': 0.39; 'called': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'skip:u 10': 0.60; 'real': 0.61; 'times': 0.63; 'love': 0.63; 'managing': 0.64; 'great': 0.64; 'wanting': 0.65; 'lack': 0.71; "it'd": 0.84; 'scene': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=n/deuagr4yuWhU0wLmDHzTKRcUdT3MHi53sw9vFF7VE=; b=ykvwCNH2TYrRK8aTI4P1h4+ewEmVJvBW/gi+7Go4sRgkivHG9HZyqicF+7zwHYaim6 ZMCMkx1IBBHGEvFUY2c88Q+uaHXs07qTj0SO74tUhwJFy+fe9xx84cpnTOfphBk2QNYs teDVEZpnCtKXepM5iSEwVyH+r6PmSEyXR1kBs4EeiXfpRRG4nFm9KmIsf8kkohpFeMcS qo5OfDaEw5W6bacRbT0mmr5Xz7juYu1tP+uFJvh+ZLWEtUvL3LKLkjXdg3hrseAxEE5U uoPlHRVyOHD127yEvceQ50H8MdMkUIBk8M/TzvhyNKch/MTn5gA7qbvoMqvv7SmHtjcq 4U9Q== MIME-Version: 1.0 In-Reply-To: <20121223171955.GB32535@ifeobi.illom.net> References: <20121223171955.GB32535@ifeobi.illom.net> Date: Mon, 24 Dec 2012 11:32:17 +1100 Subject: Re: Parsing files in python From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list 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: 56 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1356309147 news.xs4all.nl 6942 [2001:888:2000:d::a6]:33472 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35420 On Mon, Dec 24, 2012 at 4:19 AM, Kene Meniru wrote: > 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 tha= t reads a scene description language (SDL) to create photo-realistic images= . At this time my program (for modeling building information) is so huge th= at I am finding it difficult managing the macros and I am not even near com= pletion. I love POV-Ray! Great software, but the input language does at times lack something, so I'm not surprised that you're wanting a pre-parser. > ------------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 =3D 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. Hmm. That's a fairly complex file format you have there. I wonder if it'd be possible to use an actual language parser for it - for instance, to make this a real Python program. You'd have to use # for a comment rather than //, and vector syntax may be a problem, but for the rest, you should be able to do it all with just one extra line at the top: from povray_macros import * You then write all your macros in a file called povray_macros.py and they'll be conveniently available. For instance: def buildingLevel(name, altitude): print("... whatever POV-Ray code is needed ...") Unfortunately POV-Ray doesn't seem to support reading from stdin, so you can't simply pipe your program into the renderer. But you can do it this way: my_file_whatever_it_is.py >temp.pov povray +Itemp.pov ChrisA