473,238 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,238 software developers and data experts.

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 1780
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.