handling tcl files in ruby

S

salamond

Hi, all.

Here's the problem occurred to me.

I'm having several tcl files like this:

data {
name {jarod}
id {1131321}
}

data {
name {hhhh}
id {2929292}
}

I defined a couple of proc like proc data, to auto generate arrays for me.
(arrays in tcl is like hash in ruby)
I just source file_name in my tcl_project, so that those arrays are
generated automatcially.

because of this, I might have something like :
data {
name {jarod}
id {123455}
}
source a.tcl ;# a.tcl is another data file


Now I have to let ruby understand all these data files.

Options that I'm having:
1 translate all data files to xml, let ruby parse xml files
I've already tried the first one, but the result isn't so good,
new xml files are hard to understand and maintain.
2 write my own ruby parser,
I've tried google, there seems to be a couple of ruby parser on
rubyforge. not look into it till now.
3 call tcl in ruby to parse all those files.
I've found that there's no tcl_array_to_ruby_hash function
available in ruby/tk package.

I think the best way is to keep the current format, but I'm not sure
if it is the right thing to do.
so does any body have experiences on this kind of staff or any
suggestions or ideas?

thanks

JaordZZ
 
J

Joel VanderWerf

salamond said:
Hi, all.

Here's the problem occurred to me.

I'm having several tcl files like this:

data {
name {jarod}
id {1131321}
}

data {
name {hhhh}
id {2929292}
}

I defined a couple of proc like proc data, to auto generate arrays for me.
(arrays in tcl is like hash in ruby)
I just source file_name in my tcl_project, so that those arrays are
generated automatcially.

because of this, I might have something like :
data {
name {jarod}
id {123455}
}
source a.tcl ;# a.tcl is another data file


Now I have to let ruby understand all these data files.

Options that I'm having:
1 translate all data files to xml, let ruby parse xml files
I've already tried the first one, but the result isn't so good,
new xml files are hard to understand and maintain.
2 write my own ruby parser,
I've tried google, there seems to be a couple of ruby parser on
rubyforge. not look into it till now.
3 call tcl in ruby to parse all those files.
I've found that there's no tcl_array_to_ruby_hash function
available in ruby/tk package.

I think the best way is to keep the current format, but I'm not sure
if it is the right thing to do.
so does any body have experiences on this kind of staff or any
suggestions or ideas?

Suggestion: look for a json (or yaml) emitter in tcl, or write one (it
should be easy--a limited ruby json emitter is about 50 LOC). Dump your
tcl structures to json, and that can be loaded in ruby using any of the
ruby json libs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top