Parsing a TCL List with java
I am writing a new client for a client/server application. The server was written in TCL and returns responses in TCL list format, in some cases as nested lists.
Ex: {data { bob frank ted } 6 7}
What I would like to do is pull out the nested part of the list {bob frank ted} and turn it into a java array {bob, frank, ted} and the remaining members into a second array {data,8,7}
I have looked at regular expressions, the stringtokenizer, and various parsing classes - is there a single clean way of doing this?
TIA
Darrell
[560 byte] By [
dotwella] at [2007-11-27 1:34:16]

Try something like this:import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Main {
public static void main(String[] args) {
String line = "{data { bob frank ted } 6 7}";
String inner = myGroup(line);
String outer = line.replace(inner, "");
System.out.println(line+"\n=\n"+inner+"\n+\n"+outer);
}
static String myGroup(String s) {
Pattern pattern = Pattern.compile("\\{([^{}]*?)\\}");
Matcher matcher = pattern.matcher(s);
return matcher.find() ? matcher.group() : null;
}
}
Or perhaps: http://tcljava.sourceforge.net/docs/website/index.html