Re: [Tutor] making a custom file parser?

2012-01-09 Thread Devin Jeanpierre
IIRC, Python's only non-regular feature is backreferences though Probably. I'm not too familiar with a couple other features or how their semantics work, in particular the (?(id)yes|no) syntax. I'm not calling bs or anything, I don't know anything about .net regexes and I'll readily believe

Re: [Tutor] making a custom file parser?

2012-01-08 Thread Devin Jeanpierre
Parsing XML with regular expressions is generally very bad idea. In the general case, it's actually impossible. XML is not what is called a regular language, and therefore cannot be parsed with regular expressions. You can use regular expressions to grab a limited amount of data from a

Re: [Tutor] making a custom file parser?

2012-01-08 Thread Hugo Arts
On Mon, Jan 9, 2012 at 2:19 AM, Devin Jeanpierre jeanpierr...@gmail.com wrote: Parsing XML with regular expressions is generally very bad idea. In the general case, it's actually impossible. XML is not what is called a regular language, and therefore cannot be parsed with regular expressions.

[Tutor] making a custom file parser?

2012-01-07 Thread Alex Hall
Hello all, I have a file with xml-ish code in it, the definitions for units in a real-time strategy game. I say xml-ish because the tags are like xml, but no quotes are used and most tags do not have to end. Also, comments in this file are prefaced by an apostrophe, and there is no multi-line

Re: [Tutor] making a custom file parser?

2012-01-07 Thread Chris Fuller
If it's unambiguous as to which tags are closed and which are not, then it's pretty easy to preprocess the file into valid XML. Scan for the naughty bits (single quotes) and insert escape characters, replace with something else, etc., then scan for the unterminated tags and throw in a / at

Re: [Tutor] making a custom file parser?

2012-01-07 Thread Alex Hall
I had planned to parse myself, but am not sure how to go about it. I assume regular expressions, but I couldn't even find the amount of units in the file by using: unitReg=re.compile(r\unit\(*)\/unit\) unitCount=unitReg.search(fileContents) print number of units: +unitCount.len(groups()) I just

Re: [Tutor] making a custom file parser?

2012-01-07 Thread Hugo Arts
On Sat, Jan 7, 2012 at 8:22 PM, Alex Hall mehg...@gmail.com wrote: I had planned to parse myself, but am not sure how to go about it. I assume regular expressions, but I couldn't even find the amount of units in the file by using: unitReg=re.compile(r\unit\(*)\/unit\)

Re: [Tutor] making a custom file parser?

2012-01-07 Thread Lie Ryan
On 01/08/2012 04:53 AM, Alex Hall wrote: Hello all, I have a file with xml-ish code in it, the definitions for units in a real-time strategy game. I say xml-ish because the tags are like xml, but no quotes are used and most tags do not have to end. Also, comments in this file are prefaced by an