Im interested in parsing a text file that has a very specific, yet
somewhat complicated (for me) format. Sample attached. Looks something
like this:
BeanCounterDB = {
["settings"] = {
["profile.Default"] = {
["columnsortcurSort"] = 12,
["util.beancounter.mailrecolor"] = "both",
["columnsortcurDir"] = -1,
["configator.left"] = 282.666712026266,
["configator.top"] = 651.6666718914553,
},
The file contains a hierarchy of keys and values. Keys look like
"["string"]". Values are assigned by "=". Values can be "{}" or
"<string>", or <number> or lists of keys/values assignments separated by
"," and enclosed by "{" and "}" respectively.
This is all very much like xml, just that not sufficiently alike to just
make search and replace and then use an xml parser.
Anyone has any suggestions/pointers what I should do or where I should
look to be able to obtain some sort of datastructure (array of objects,
lists etc.) representing the data in such a file?
Thanks!
NOTE: Attachment contains more data than I put in the post, but still
not a full file, as the only such full file I have is rather large.
on 2009-07-03 11:49
on 2009-07-03 12:03
On Fri, Jul 3, 2009 at 11:49 AM, Catalin Tilimpea<ctilimpea@gmail.com> wrote: > ["configator.left"] = 282.666712026266, > ["configator.top"] = 651.6666718914553, > }, I wrote this little Treetop based parser for a very small subset of Lua some time ago. It might help: http://gist.github.com/140038
on 2009-07-03 18:40
dunno if that'll be any help, but it looks pretty simmilar to
YAML, here's a little regex magic to convert it to valid yaml:
http://pastie.org/533386
beware though, that will only work if
(a) the whole file equally well formatted (i.e. no trailing spaces
at the end of lines, no extra spaces between "foo" = "bar" etc.)
(b) you don't need that " -- [1]" stuff at the end of some of the lines
(i didn't know what that was for)
(c) indentation is the same for the whole file
(d) you don't mind that everything is in arrays, even stuff with only
one
entry
Point (a) is pretty relative, the regexps can be easily adjusted to
allow
any
amount of spaces between the different parts and at end of lines.
Disclaimer: I haven't tested this thoroughly, just ran it over your
snippet.
No guarantees it'll work with your whole file...
Greetz,
k
on 2009-07-03 23:50
Lars Christensen wrote: > On Fri, Jul 3, 2009 at 11:49 AM, Catalin Tilimpea<ctilimpea@gmail.com> > wrote: >> � � �["configator.left"] = 282.666712026266, >> � � �["configator.top"] = 651.6666718914553, >> � �}, > > I wrote this little Treetop based parser for a very small subset of > Lua some time ago. It might help: > > http://gist.github.com/140038 Thanks a bunch. That's what I'm looking for. However, I can't require treetop for some reason. I have even explicitly included the path to treetop.rb in the path environment var and still no joy (I get "no such file -- treetop"). Any suggestions?
on 2009-07-04 13:20
Lars Christensen wrote: > I wrote this little Treetop based parser for a very small subset of > Lua some time ago. It might help: > > http://gist.github.com/140038 Lars, I'm a maintainer of Treetop. Would you be so kind as to publish this snippet at <http://snippets.dzone.com/tag/Treetop>? Clifford Heath.
on 2009-07-05 23:19
On Fri, Jul 3, 2009 at 5:49 AM, Catalin Tilimpea<ctilimpea@gmail.com> wrote: > Anyone has any suggestions/pointers what I should do or where I should > look to be able to obtain some sort of datastructure (array of objects, > lists etc.) representing the data in such a file? If you can afford to have Lua installed and execute it to get what you need, you might consider RubyLuaBridge http://rubyluabridge.rubyforge.org/
on 2009-07-06 02:57
On Mon, Jul 6, 2009 at 6:18 AM, Gregory Brown<gregory.t.brown@gmail.com> wrote: > On Fri, Jul 3, 2009 at 5:49 AM, Catalin Tilimpea<ctilimpea@gmail.com> wrote: > >> Anyone has any suggestions/pointers what I should do or where I should >> look to be able to obtain some sort of datastructure (array of objects, >> lists etc.) representing the data in such a file? > > If you can afford to have Lua installed and execute it to get what you > need, you might consider RubyLuaBridge > > http://rubyluabridge.rubyforge.org/ There is also rufus-lua : http://github.com/jmettraux/rufus-lua/ http://jmettraux.wordpress.com/2009/03/16/ruby-to-lua/ Cheers,
on 2009-07-06 03:28
Gregory Brown wrote: > On Fri, Jul 3, 2009 at 5:49 AM, Catalin Tilimpea<ctilimpea@gmail.com> > wrote: > >> Anyone has any suggestions/pointers what I should do or where I should >> look to be able to obtain some sort of datastructure (array of objects, >> lists etc.) representing the data in such a file? > > If you can afford to have Lua installed and execute it to get what you > need, you might consider RubyLuaBridge > > http://rubyluabridge.rubyforge.org/ For the whole project I don't think i can, but maybe for small bits. Thanks all anyways: combining all the things said in this thread I am getting started to parse that file.
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.