import java.io.*; import java.util.*; import java.util.regex.*; /** * S式を取り扱うクラス * created by Toyohisa Nakada (2008.11.15) */ public class SExp { /** S式の個々の要素 */ private Vector m_atoms = new Vector(); /** デフォルトコンストラクタ */ protected SExp() throws Exception{ } /** コンストラクタ */ public SExp(String expression) throws Exception{ parse(expression); } /** S式の文字列表現 */ public String toString(){ String expression = ""; for(int cnt=0;cnt findAll(String first_element) throws Exception{ Vector rets = new Vector(); findAll(first_element,this,rets); return rets; } private static void findAll(String first_element,SExp exp,Vector rets) throws Exception{ if(exp.get(0).toString().equals(first_element)){ rets.add(exp); } for(int cnt=1;cnt findAll(Pattern ptn) throws Exception{ Vector rets = new Vector(); findAll(ptn,this,rets); return rets; } public Vector findAll(Object name) throws Exception{ if(name instanceof Pattern){ return findAll((Pattern)name); }else if(name instanceof String){ return findAll((String)name); } throw new Exception("[SExp] could not find a type of input object"); } /** 引数のPatternは、Pattern.compile(String)を使うとよい。 */ private static void findAll(Pattern ptn,SExp exp,Vector rets) throws Exception{ Matcher m = ptn.matcher(exp.get(0).toString()); if(m.matches()){ rets.add(exp); } for(int cnt=1;cnt objs = exp.findAll("\\(p \"SamplePlayer0\".*"); for(int cnt=0;cnt