Re: [Tutor] Parsing problem

2005-07-26 Thread Paul McGuire
> Also interesting is that our processors, which aren't overly > far apart in clock speed, vary so greatly in processing this > problem. Maybe Intel is better *grin* Urp, turns out I have an "Athlon Inside" label right here on the deck of my laptop! Maybe the difference is my 1.2Gb of RAM.

Re: [Tutor] Parsing problem

2005-07-26 Thread Liam Clarke
s, use an Or, which will match the longest, or reorder the MatchFirstto put the most restrictive _expression_ first.Welcome to pyparsing, please let me know how your project goes! -- Paul-Original Message-From: Liam Clarke [mailto:[EMAIL PROTECTED]]Sent: Monday, July 25, 2005 8:31 AMTo: Paul McGu

Re: [Tutor] Parsing problem

2005-07-25 Thread Paul McGuire
integer expression "masks" the real, and since it occurs first, it will match first. The two solutions are: number = (integer ^ real) Or number = (real | integer) That is, use an Or, which will match the longest, or reorder the MatchFirst to put the most restrictive expression first. Welcom

Re: [Tutor] Parsing problem

2005-07-25 Thread Paul McGuire
x27;10'], ['bar', '20' [['foo', '10'], ['bar', '20']] 10 20 -- Paul -Original Message- From: Liam Clarke [mailto:[EMAIL PROTECTED] Sent: Monday, July 25, 2005 7:38 AM To: Paul McGuire Cc: tutor@python.org Subject:

Re: [Tutor] Parsing problem

2005-07-25 Thread Paul McGuire
Liam - The two arguments to Word work this way: - the first argument lists valid *initial* characters - the second argument lists valid *body* or subsequent characters For example, in the identifier definition, identifier = pp.Word(pp.alphas, pp.alphanums + "_/:.") identifiers *must* start wit

Re: [Tutor] Parsing problem

2005-07-25 Thread Paul McGuire
s is about the only optimization I can think of. -- Paul -Original Message- From: Liam Clarke [mailto:[EMAIL PROTECTED] Sent: Monday, July 25, 2005 7:38 AM To: Paul McGuire Cc: tutor@python.org Subject: Re: [Tutor] Parsing problem Hi Paul, Well various tweaks and such done, it parses perfectly,

Re: [Tutor] Parsing problem

2005-07-25 Thread Paul McGuire
-Original Message- From: Liam Clarke [mailto:[EMAIL PROTECTED] Sent: Sunday, July 24, 2005 10:21 AM To: Paul McGuire Cc: tutor@python.org Subject: Re: [Tutor] Parsing problem Hi Paul, That is fantastic. It works, and using that pp.group is the key with the nested braces. I just ran th

Re: [Tutor] Parsing problem

2005-07-25 Thread Liam Clarke
ted string.  Probably good practice to always enclosein quotes the _expression_ being assigned to a Forward using '<<'.-- Paul-Original Message-From: Liam Clarke [mailto: [EMAIL PROTECTED]]Sent: Saturday, July 23, 2005 9:03 AMTo: Paul McGuireCc: tutor@python.orgSubject: Re: [

Re: [Tutor] Parsing problem

2005-07-25 Thread Paul McGuire
^ RHS ) + RBRACE ) ) -- Paul -Original Message- From: Liam Clarke [mailto:[EMAIL PROTECTED] Sent: Sunday, July 24, 2005 10:21 AM To: Paul McGuire Cc: tutor@python.org Subject: Re: [Tutor] Parsing problem Hi Paul, That is fantastic. It works, and using that pp.group is the key with the nest

Re: [Tutor] Parsing problem

2005-07-25 Thread Liam Clarke
Hi Paul, Well various tweaks and such done, it parses perfectly, so much thanks, I think I now have a rough understanding of the basics of pyparsing. Now, onto the fun part of optimising it. At the moment, I'm looking at 2 - 5 minutes to parse a 2000 line country section, and that's with psyco.

Re: [Tutor] Parsing problem

2005-07-24 Thread Liam Clarke
Hi Paul, My apologies, as I was jumping into my car after sending that email, it clicked in my brain. "Oh yeah... initial & body..." But good to know about how to accept valid numbers. Sorry, getting a bit too quick to fire off emails here. Regards, Liam ClarkeOn 7/25/05, Paul McGuire <[EMA

Re: [Tutor] Parsing problem

2005-07-23 Thread Paul McGuire
x27;, so RHS only worked if it was handed a quoted string. Probably good practice to always enclose in quotes the expression being assigned to a Forward using '<<'. -- Paul -Original Message- From: Liam Clarke [mailto:[EMAIL PROTECTED] Sent: Saturday, July 23, 2005 9:03

Re: [Tutor] Parsing problem

2005-07-23 Thread Liam Clarke
*sigh* I just read the documentation more carefully and found the difference between the | operator and the ^ operator. Input - j = { line = { foo = 10 bar = 20 } } New code sel = pp.Forward() values = ((pp.Word(pp.printables) + pp.Suppress("=") + pp.Word(pp.printables)) ^ sel) sel << (pp.Wo

Re: [Tutor] Parsing problem

2005-07-23 Thread Liam Clarke
Hmmm... just a quick update, I've been poking around and I'm obviously making some error of logic. Given a line -  f = "j = { line = { foo = 10 bar = 20 } }" And given the following code - select = pp.Forward()select << pp.Word(pp.printables) + pp.Suppress("=") + pp.Suppress("{") + pp.OneO

Re: [Tutor] Parsing problem

2005-07-23 Thread Liam Clarke
Howdy, I've attempted to follow your lead and have started from scratch, I could just copy and paste your solution (which works pretty well), but I want to understand what I'm doing *grin* However, I've been hitting a couple of ruts in the path to enlightenment. Is there a way to tell pyparsing

[Tutor] Parsing problem

2005-07-21 Thread Paul McGuire
Liam, Kent, and Danny - It sure looks like pyparsing is taking on a life of its own! I can see I no longer am the only one pitching pyparsing at some of these applications! Yes, Liam, it is possible to create dictionary-like objects, that is, ParseResults objects that have named values in them.

Re: [Tutor] Parsing problem

2005-07-20 Thread Liam Clarke
Well, I've been poking around and... well.. this is way better than writing complex regexes. To suit my needs, I need something that can handle - foo = bar foo = 20 foo = { bar 20 } foo = { bar = 20 baz} foo = {bar = 20 baz { dave henry}} OK, so the last one's extreme. So far, I can handle down

Re: [Tutor] Parsing problem

2005-07-18 Thread Liam Clarke
Thanks guys, I daresay I will have a lot of questions regarding this, but at least I have a point to start digging and a better shovel! Cheers, Liam ClarkeOn 7/19/05, Danny Yoo <[EMAIL PROTECTED]> wrote: On Mon, 18 Jul 2005, Liam Clarke wrote:> country = {> tag = ENG> ai = {> flags = { }> combat

Re: [Tutor] Parsing problem

2005-07-18 Thread Danny Yoo
On Mon, 18 Jul 2005, Liam Clarke wrote: > country = { > tag = ENG > ai = { > flags = { } > combat = { DAU FRA ORL PRO } > continent = { } > area = { } > region = { "British Isles" "NorthSeaSea" "ECAtlanticSea" "NAtlanticSea" > "TagoSea" "WCAtlanticSea" } > war = 60 > ferocity = no > } > } [Long

Re: [Tutor] Parsing problem

2005-07-18 Thread Kent Johnson
Liam Clarke wrote: > What I need to do, is to turn this into a data structure, and I think > this relates to XML in a way. Basically, I want to parse the above (I > assume I'll be counting braces to find where I am) so that a country > object called ENG has a dictionary called ai, which points t

[Tutor] Parsing problem

2005-07-18 Thread Liam Clarke
Hi all, I am a Europa Universalis II freak, and in attempting to recreate a lost saved game, I had to delve into the mechanics of the save game file. Which, luckily, is plain text. It's formatted like this - country = {     tag = ENG     ai = {     flags = { }     combat = { DAU