Parsing cfg files?
Moderator: Transport Empire Moderators
- uzurpator
- Transport Empire Moderator
- Posts: 2178
- Joined: 10 Jan 2003 12:21
- Location: Katowice, Poland
Parsing cfg files?
I am currently writing a project for school that involves parsing text file to turn it into more sensible form. Since TE will probably use a plethora of configuration files - would a good parser be needed?
I use tools named Lex and Yacc - they are quite efficient. Getting through 60 megabytes of data takes approx 5-10 seconds.
I use tools named Lex and Yacc - they are quite efficient. Getting through 60 megabytes of data takes approx 5-10 seconds.
All art and vehicle stats I authored for TT and derivatives are as of now PUBLIC DOMAIN! Use as you see fit
Just say NO to the TT fan-art sprite licensing madness. Public domain your art as well.
Just say NO to the TT fan-art sprite licensing madness. Public domain your art as well.
*uah* why do you want to take those complicated XML files?
Example for plain text:
Example for XML:
There's just no need for XML in a config file for a simple game (simpler than many of today's games) ... so don't use it ![Rolling Eyes :roll:](./images/smilies/icon_rolleyes.gif)
Example for plain text:
Code: Select all
canals on
Code: Select all
<!definition blabla>
<version>438.34980beta</version>
<xml blabla>
<settings>
<canals value="on" />
</settings>
</xml>
![Rolling Eyes :roll:](./images/smilies/icon_rolleyes.gif)
Exactly TTU's point. XML was primarly designed for cross-platform and mainly cross-application dataformats. Configfiles only tend to be used by the game itself (and at most by a gui-based configuration app).Saskia wrote:*uah* why do you want to take those complicated XML files?
Example for plain text:Example for XML:Code: Select all
canals on
There's just no need for XML in a config file for a simple game (simpler than many of today's games) ... so don't use itCode: Select all
<!definition blabla> <version>438.34980beta</version> <xml blabla> <settings> <canals value="on" /> </settings> </xml>
XML is overkill, and not as readable as custom design.
"Peace cannot be kept by force. It can only be achieved by understanding." - Albert Einstein
Would be great if only it were valid XMLSaskia wrote: Example for XML:Code: Select all
<!definition blabla> <version>438.34980beta</version> <xml blabla> <settings> <canals value="on" /> </settings> </xml>
![Rolling Eyes :roll:](./images/smilies/icon_rolleyes.gif)
Code: Select all
<?xml charset="utf-8" ?>
<setting name="canals" value="1" />
Using plain text, you have to change the parsing code every time you want to change an option. One of the reasons for using XML is that you have a schema definition file independent of the application code itself. The parsing code can just read this blindly, since it doesn't need to know what it does (that's for other parts of the code). This is similar to what grfcodec does - it doesn't know what the format of action 0B might be, and doesn't need to either.
Using a simple textfile with unformatted attribute-value pairs is a solution which provides for less code now, but more maintenance further down the line. XML might be more work to begin with, but it will require much less maintenance, both of our own code and in third-party tools. We are taking on board both correct computing theory and sound engineering. IMO, a long-term solution constitutes better engineering practice than a short-term one.
- uzurpator
- Transport Empire Moderator
- Posts: 2178
- Joined: 10 Jan 2003 12:21
- Location: Katowice, Poland
Code: Select all
%%
canals return tk_canals;
on|off return tk_switch;
%%
%%
parse : tk_canals tk_switch {importantobject.adddata($2)};
%%
All art and vehicle stats I authored for TT and derivatives are as of now PUBLIC DOMAIN! Use as you see fit
Just say NO to the TT fan-art sprite licensing madness. Public domain your art as well.
Just say NO to the TT fan-art sprite licensing madness. Public domain your art as well.
- uzurpator
- Transport Empire Moderator
- Posts: 2178
- Joined: 10 Jan 2003 12:21
- Location: Katowice, Poland
it is - just if:
"The parsing code can just read this blindly, since it doesn't need to know what it does (that's for other parts of the code)"
then the validation is just on the level of XML grammar. It does not validate data it parses. Good parser can do that. And i can make a parser that does just "read ... blindly" in about 20 lines of code. And for txt files that is...
"The parsing code can just read this blindly, since it doesn't need to know what it does (that's for other parts of the code)"
then the validation is just on the level of XML grammar. It does not validate data it parses. Good parser can do that. And i can make a parser that does just "read ... blindly" in about 20 lines of code. And for txt files that is...
All art and vehicle stats I authored for TT and derivatives are as of now PUBLIC DOMAIN! Use as you see fit
Just say NO to the TT fan-art sprite licensing madness. Public domain your art as well.
Just say NO to the TT fan-art sprite licensing madness. Public domain your art as well.
- uzurpator
- Transport Empire Moderator
- Posts: 2178
- Joined: 10 Jan 2003 12:21
- Location: Katowice, Poland
Im not sure what you mean but...
<?xml charset="utf-8" ?>
<setting name="cnaals" value="15463" />
valid scheme? yes
valid data? not really
lex/yacc is parsing by semantics/syntax and is always accurate.
BTW I am toying with an idea txt -> nfo translation using those two tools.
<?xml charset="utf-8" ?>
<setting name="cnaals" value="15463" />
valid scheme? yes
valid data? not really
lex/yacc is parsing by semantics/syntax and is always accurate.
BTW I am toying with an idea txt -> nfo translation using those two tools.
All art and vehicle stats I authored for TT and derivatives are as of now PUBLIC DOMAIN! Use as you see fit
Just say NO to the TT fan-art sprite licensing madness. Public domain your art as well.
Just say NO to the TT fan-art sprite licensing madness. Public domain your art as well.
When the schema dictates that "canals" should be a boolean value, this would either be rejected by the parser, or treated as whatever non-zero values are interpreted as. Admittedly, this would require that it were instead <canals value="off"> or something instead of <setting>.<?xml charset="utf-8" ?>
<setting name="cnaals" value="15463" />
Code: Select all
<xs:element name="canals">
<xs:complexType>
<xs:sequence></xs:sequence>
<xs:attribute name="value" type="xs:boolean" />
</xs:complexType>
</xs:element>
All of this said, I think this decision has already been made, making most of ths discussion moot.
- uzurpator
- Transport Empire Moderator
- Posts: 2178
- Joined: 10 Jan 2003 12:21
- Location: Katowice, Poland
I don't see any "canals" in that example.
Also if you already do validating then on the "scheme" ("canals", "bridges" or whatever) and it means that you have to update your parser (XML) code every time a new switch is introduced or old one changed. With Lex/Yacc you do the same but with much smaller txt files and with much greater speed.
in lex
in yacc
which is simpler and faster?
BTW - for your information - both lex and yacc generate C code so you don't update the parser but just generation rules.
BTW2 - canals can be used by:
canals off
canals on
canals 1
canals 0
canals = off
canals = on
canals = 1
canals = 0
it is trival to make a parser that will use all version of this.
Also if you already do validating then on the "scheme" ("canals", "bridges" or whatever) and it means that you have to update your parser (XML) code every time a new switch is introduced or old one changed. With Lex/Yacc you do the same but with much smaller txt files and with much greater speed.
Code: Select all
<xs:element name="canals">
<xs:complexType>
<xs:sequence></xs:sequence>
<xs:attribute name="value" type="xs:boolean" />
</xs:complexType>
</xs:element>
Code: Select all
canals return tk_canals;
on|off return tk_switch;
Code: Select all
canals : tk_canals tk_switch {importantobject.adddata($2)};
BTW - for your information - both lex and yacc generate C code so you don't update the parser but just generation rules.
BTW2 - canals can be used by:
canals off
canals on
canals 1
canals 0
canals = off
canals = on
canals = 1
canals = 0
it is trival to make a parser that will use all version of this.
All art and vehicle stats I authored for TT and derivatives are as of now PUBLIC DOMAIN! Use as you see fit
Just say NO to the TT fan-art sprite licensing madness. Public domain your art as well.
Just say NO to the TT fan-art sprite licensing madness. Public domain your art as well.
The funny thing is that you need a XSLT definition file (the <xs:...>-thingy posted by Chris) and then you can parse XML files after this scheme.
But Chris, you forgot somthing: XML ist for files that look like this:
and not for
You understand me? Config files contain just a few values, not a document, like a HTML file does, f. e. ![Wink :wink:](./images/smilies/icon_wink.gif)
Using XML is like programming in Java: in two years nobody is interested in this anymore![Laughing :lol:](./images/smilies/icon_lol.gif)
But Chris, you forgot somthing: XML ist for files that look like this:
Code: Select all
text text image
table text image anythingyoudontexpecthere text
image text ...
Code: Select all
canals = on
freighttrains = 5
![Wink :wink:](./images/smilies/icon_wink.gif)
Using XML is like programming in Java: in two years nobody is interested in this anymore
![Laughing :lol:](./images/smilies/icon_lol.gif)
- uzurpator
- Transport Empire Moderator
- Posts: 2178
- Joined: 10 Jan 2003 12:21
- Location: Katowice, Poland
Does not matter ^^. I can make a parser that will go through anything - probably including binaries ^^Saskia wrote:But Chris, you forgot somthing: XML ist for files that look like this:and not forCode: Select all
text text image table text image anythingyoudontexpecthere text image text ...
Code: Select all
canals = on freighttrains = 5
All art and vehicle stats I authored for TT and derivatives are as of now PUBLIC DOMAIN! Use as you see fit
Just say NO to the TT fan-art sprite licensing madness. Public domain your art as well.
Just say NO to the TT fan-art sprite licensing madness. Public domain your art as well.
Who is online
Users browsing this forum: No registered users and 1 guest