473,466 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Need ideas on how to approach this.

I want to make a program that reads the content of a LUA array save file..
More precicely a save file from a World of Warcraft plugin called
CharacterProfiler, which dumps alot of information about your characters
into that save file.

Anyhow, I want to extract a couple of lines of it and save it into a
database and I need help on figuring out a good way of reading the file.
The problem is that the file can look pretty different depending on the
proffessions and class of the characters etc. etc..

Is it possible to get an xml parser to read it or something?

I would appriciate all angles of approaching this..
Right now im thinking about just starting with getting rid of the stuff I
dont want in the file.. Like I only want the characters from a certain
server.. Trollbane. And I only want information about characters in the
guild Sacred Order Of Azeroth...
So if I just catch the part in the file where it starts with ["Trollbane"] =
{ and counts the '{' and '}' to get the one that ends the trollbane server..

Anyway, Im attaching the whole save file so that you can take a look at it..
Hope someone can give me some ideas.

EDIT: Aww, it was to big to send with..Im uploading it to a webspace
http://www1.shellkonto.se/artix/CharacterProfiler.lua

Mar 21 '07 #1
2 1791
Anders B wrote:
I want to make a program that reads the content of a LUA array save file..
More precicely a save file from a World of Warcraft plugin called
CharacterProfiler, which dumps alot of information about your characters
into that save file.

Anyhow, I want to extract a couple of lines of it and save it into a
database and I need help on figuring out a good way of reading the file.
The problem is that the file can look pretty different depending on the
proffessions and class of the characters etc. etc..

Is it possible to get an xml parser to read it or something?

I would appriciate all angles of approaching this..
Right now im thinking about just starting with getting rid of the stuff I
dont want in the file.. Like I only want the characters from a certain
server.. Trollbane. And I only want information about characters in the
guild Sacred Order Of Azeroth...
So if I just catch the part in the file where it starts with
["Trollbane"] =
{ and counts the '{' and '}' to get the one that ends the trollbane
server..

Anyway, Im attaching the whole save file so that you can take a look at
it..
Hope someone can give me some ideas.

EDIT: Aww, it was to big to send with..Im uploading it to a webspace
http://www1.shellkonto.se/artix/CharacterProfiler.lua
Just a hint: to get a grip on the file structure I'd use an editor
supporting lua with folding capabilities like notepad++
With alt-0..8 alt-shift-0..8 you can (un)fold levels 0 for all up to
level 8 and see line numbers.

http://notepad-plus.sourceforge.net/

--
Greetings
Matthias
Mar 21 '07 #2
Anders B wrote:
<backposted />

I don't know Lua nor the specific format it uses, but based on the
file you posted, I suppose you could come up with a LUA -XML
translator quite easily, with a minimum of hair pulling (there will be
some, though), and a maximum of fun for, say, a rainny afternoom.

To write such parser, you could start with a "grammar" for the file
format, which would be something like the follwoing (again, roughly
based on the file you posted):

Items = Item+ EOF
Item = Name '=' ContentBlock
ContentBlock = '{' Content* '}'
Content = (AttributeOrItem
| UnamedItem
| Nil
| SubItem) ','

AttributeOrItem = Name '=' (Literal | ContentBlock)
UnamedItem = ContentBlock
Nil = NIL
SubItem = Literal

Name = Identifier
| ('[' Literal ']')

Where Identifier, Literal, NIL and EOF are tokens (as well as the
symbols "{", "}", "[", "]", "," and "="). In the pseudo-grammar above,
the '+' symbol means that the preceding item may exist one or more
times; the '*' means that the preceding item is on optional sequence;
and the '|' symbol indicates alternatives.

While parsing this grammar, you could map each construct to a XML-like
element:

Item -<item name="name">...</item>
Attribute -<attribute name="name" value="value" />
Nil -<item name="" />
UnamedItem -<item name=""... </item>
SubItem -<subitem value="value" />

To build a parser from this grammar, you'd first need a Lexer which
would return each different token on demand. This is somewhat tricky,
and would be a whole lot of fun in itself (you see that my concept of
fun leaves a lot to be desired)...

Then, for each non-terminal in the grammar above (a non-terminal is
one of the names to the left of the equal sign: Items, Item,
ContentBlock, etc) you would create a parsing method responsible for
"recognizing" the pattern to the right of the equal sign and to emit
the text of your XML structure as you go...

This kind of parser is called Recursive Descent, and is easy to build
by hand. For example, this could be the interface to your parser:

Function ParseItems As Boolean
Function ParseItem As Boolean
Function ParseContentBlock As Boolean
Function ParseContent As Boolean
Function ParseAttributeOrItem As Boolean
Function ParseUnamedItem As Boolean
Function ParseNil As Boolean
Function ParseSubItem As Boolean
Function ParseName(ByRef Name As String) As Boolean

To give you a glympse of the kind of code involved, see how the
ParseContentBlock method could be written:

<aircode>
Function ParseContentBlock As Boolean
'Parses a '{', followed by an optional sequence
'of Content, followed by an '}'

If Not MatchToken("{") Then Return False
Do While ParseContent
Loop
RequireToken("}")
Return True
End Function
</aircode>

The interesting thing is that only at specific places you'll need to
be concerned with actually emiting the data to your XML structure.
Say, for instance, in ParseAttributeOrItem, which will, as its name
says, recognize an attribute or an Item and generate the according
translation:

<aircode>
Function ParseAttributeOrItem As Boolean
'Will parse a Name followed by an '='
'followed by either a Literal or a ContentBlock

Dim Name As String
If Not ParseName(Name) Then Return False

RequireToken("=")

If CurrentToken.IsLiteral Then
'Creates an attribute
Emit("<attribute name={0} value={1} />", _
Quoted(Name), Quoted(CurrentToken.Value))
NextToken

ElseIf CurrentToken.IsOpenBrace Then
'ContentBlock starts with an open brace
'Create a new item
Emit("<item name={0}>", Quoted(Name))
ParseContentBlock
Emit("</item>")

Else 'Error
Throw new ParseError("Expected literal or '{'")

End If
Return True
End Function
</aircode>

As you can see, it's an almost literal translation of the production
content (a production is the set of rules describing a given non-
terminal) into code.

The thing with Recursive Descent Parsers is that they are, as the name
suggests, recursive. You saw, for example, that ParseAttributeOrItem
will call ParseContentBlock when it sees a '{' following the '=' char.
But if you look at the production for ContentBlock, you'll see that it
calls Content, which may call AttributeOrItem recursivelly. This is
the thing that allows the parser to keep track of the different
structures generated by the parsing process, and what differentiates
parsers from, say, Regular Expressions (which usually lack this
recursion power):

<aircode>
Function ParseContent As Boolean
'will parse an AttributeOrItem or an
'UnamedItem or a Nil or a SubItem,
'followed by a ','

Dimk Ok As Boolean
If CurrentToken.IsIdentifierOrOpenBracket Then
Ok = ParseAttributeOrItem

ElseIf CurrentToken.IsOpenBrace Then
Ok = ParseUnamedItem

ElseIf CurrentToken.IsNil Then
Ok = ParseNil

ElseIf CurrentToken.IsLiteral Then
Ok = ParseSubItem

End If

If Ok Then RequireToken(",")

Return Ok

End Function
</aircode>

Hope this gives you some ideas.

Regards,

Branco.
I want to make a program that reads the content of a LUA array save file..
More precicely a save file from a World of Warcraft plugin called
CharacterProfiler, which dumps alot of information about your characters
into that save file.

Anyhow, I want to extract a couple of lines of it and save it into a
database and I need help on figuring out a good way of reading the file.
The problem is that the file can look pretty different depending on the
proffessions and class of the characters etc. etc..

Is it possible to get an xml parser to read it or something?

I would appriciate all angles of approaching this..
Right now im thinking about just starting with getting rid of the stuff I
dont want in the file.. Like I only want the characters from a certain
server.. Trollbane. And I only want information about characters in the
guild Sacred Order Of Azeroth...
So if I just catch the part in the file where it starts with ["Trollbane"] =
{ and counts the '{' and '}' to get the one that ends the trollbane server..

Anyway, Im attaching the whole save file so that you can take a look at it..
Hope someone can give me some ideas.

EDIT: Aww, it was to big to send with..Im uploading it to a webspacehttp://www1.shellkonto.se/artix/CharacterProfiler.lua

Mar 21 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jaime Wyant | last post by:
*long post alert!* Can anyone give me some pointers on writing "self-updating" python programs? I have an application that is almost ready for beta testing. I want to be able to fix any bugs...
14
by: Onideus Mad Hatter | last post by:
Well in theory it was a good idea: http://www.backwater-productions.net/_test_platform/game/index.html Press "4" to move left, press "6" to move right. The question remains though...is there...
11
by: darcykahle | last post by:
I have stumbled upon an interesting issue with regard to compaction of an access frontend database which resides on a DFS target that utilizes FRS to mirror the sharepoint, and I was wondering if...
10
by: Tom | last post by:
I am looking for some ideas for how to design the layout of the form for data entry and to display the data for the following situation: There are many sales associates. A sales associate can work...
1
by: RC | last post by:
-------------------------------------------------------------------------------- All, Need ideas on how to approach this: Have to compare account numbers in one table to account numbers in...
10
by: Luke Meyers | last post by:
So, just a little while ago I had this flash of insight. It occurred to me that, while of course in general there are very good reasons for the conventional two-file header/implementation...
43
by: SLH | last post by:
hi people. im trying to validate input received via a text area on an ASP page before writing it to a database. i cant use client side javascript due to policy, so it all has to happen on the...
27
true911m
by: true911m | last post by:
I would like to solicit your thoughts and ideas (code can come later) about how you would approach a project idea I just tossed together. I chose this as a testbed for me to play with objects,...
1
by: Bob Alston | last post by:
Looking for design approach ideas for collecting data from multiple remote, standalone databases. I have built one of these in Access. Another I am told was built in Access. some others the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.