📄 bnftool.java
字号:
package com.corba.mnq.tool;
import com.corba.mnq.tool.idl.IdlAttribute;
import com.corba.mnq.tool.idl.IdlConstant;
import com.corba.mnq.tool.idl.IdlExcept;
import com.corba.mnq.tool.idl.IdlFile;
import com.corba.mnq.tool.idl.IdlInterface;
import com.corba.mnq.tool.idl.IdlModule;
import com.corba.mnq.tool.idl.IdlOperation;
import com.corba.mnq.tool.idl.IdlType;
import java.util.List;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class BNFTool {
private BNFTool() {
}
/** used for java.util.logging */
private static final Logger LOG = Logger.getLogger(BNFTool.class.getName());
public static String identifier = "[_]?[a-zA-Z]\\w*";
public static String identifier_catch = "[_]?([a-zA-Z]\\w*)";
// firstgroup identifier, secondgroup positive_int_const
public static String declarator = identifier_catch + "(?>\\s*\\[([^\\],]*)\\])?";
public static String declarators = identifier + "(?>\\s*\\[([^\\],]*)\\])?" + "(?>\\s*,\\s*"
+ identifier + "(?>\\s*\\[([^\\],]*)\\])?)*";
public static String space = "\\s*";
public static String floating_pt_type = "(?>float)|(?>double)|(?>long\\s+double)";
public static String integer_type = "(?>short)|(?>long)|(?>long\\s+long)|(?>unsigned\\s+short)|(?>unsigned\\s+long)|(?>unsigned\\s+long\\s+long)";
public static String base_type_spec = floating_pt_type + "|" + integer_type
+ "|(?>char)|(?>wchar)|(?>boolean)|(?>octet)|(?>any)|(?>Object)|(?>ValueBase)";
public static String scoped_name = "(?>::\\s*)?" + identifier + "(?>\\s*::\\s*" + identifier
+ ")*";
public static String param_type_spec = base_type_spec + "|(?>string)|(?>wstring)" + "|(?>"
+ scoped_name + ")";
public static String const_type = floating_pt_type + "|" + integer_type
+ "|(?>char)|(?>wchar)|(?>boolean)|(?>octet)" + "|(?>string)|(?>wstring)" + "|(?>"
+ scoped_name + ")";
public static String op_type_spec = base_type_spec + "|(?>string)|(?>wstring)" + "|(?>void)"
+ "|(?>" + scoped_name + ")";
public static String findOperations(String input, List ops, String parent, IdlFile fn) {
String ret = "";
// gruoup 1--oneway, group 2--rtype, group 3--name,
// group 4--parameters, group 5--raises group 6--context
String op_dcl = "(?>(oneway)\\s+)?" + "(" + op_type_spec + ")" + "\\s+" + identifier_catch
+ "\\s*\\((" + "[^\\(\\)]*" + ")\\)" + "\\s*" + "(?>raises\\s*\\((" + "[^\\(\\)]*"
+ ")\\)" + "\\s*)?" + "(?>context\\s*\\((" + "[^\\(\\)]*" + ")\\)" + "\\s*)?" + ";";
Pattern pOp = Pattern.compile(op_dcl, Pattern.DOTALL + Pattern.MULTILINE);
Matcher mOp = pOp.matcher(input);
while (mOp.find()) {
String one = mOp.group(0);
String oneway = mOp.group(1);
String rtype = mOp.group(2);
String name = mOp.group(3);
String paras = mOp.group(4);
String raises = mOp.group(5);
String context = mOp.group(6);
// ready to create the node
IdlOperation on = new IdlOperation();
on.sName = name;
on.cName = parent + "::" + name;
on.content = one;
on.fn = fn;
if (oneway == null) {
on.oneway = false;
} else {
on.oneway = true;
}
on.rtype = rtype.replaceAll("\\s+", "").replaceAll("::_", "::");
on.paras = paras;
on.raises = raises;
on.context = context;
ops.add(on);
// put the node in the map
Warehouse.cname2node.put(on.cName, on);
}
ret = mOp.replaceAll("");
return ret;
}
public static String findExceptions(String input, List exceps, String parent, IdlFile fn) {
String ret = "";
// group 1--name, group 2--value;
String except_dcl = "exception\\s+" + identifier_catch + "\\s*\\{" + "("
+ nestingPair(5, '{', '}') + ")" + "\\}\\s*;";
Pattern pExcept = Pattern.compile(except_dcl, Pattern.DOTALL + Pattern.MULTILINE);
Matcher mExcept = pExcept.matcher(input);
while (mExcept.find()) {
String one = mExcept.group(0);
String name = mExcept.group(1);
String val = mExcept.group(2);
// ready to create the node
IdlExcept en = new IdlExcept();
en.sName = name;
en.cName = parent + "::" + name;
en.content = one;
en.fn = fn;
en.val = val;
exceps.add(en);
// put the node in the map
Warehouse.cname2node.put(en.cName, en);
}
ret = mExcept.replaceAll("");
return ret;
}
public static String findTypes(String input, List types, String parent, IdlFile fn) {
String ret = "";
// group 1--type, group 2--declarators
String type_dcl = "typedef\\s+(" + param_type_spec + ")\\s+(" + declarators + ")\\s*;";
Pattern pType = Pattern.compile(type_dcl, Pattern.DOTALL + Pattern.MULTILINE);
Matcher mType = pType.matcher(input);
while (mType.find()) {
String one = mType.group(0);
String declarators = mType.group(2);
String type = mType.group(1);
// group 1--name, group 2--arraylength
Pattern pDeclarator = Pattern.compile(declarator, Pattern.DOTALL + Pattern.MULTILINE);
Matcher mDeclarator = pDeclarator.matcher(declarators);
while (mDeclarator.find()) {
String name = mDeclarator.group(1);
String alen = mDeclarator.group(2);
int len = parsePositiveIntConst(alen);
// ready to create the node
IdlType tn = new IdlType();
tn.sName = name;
tn.cName = parent + "::" + name;
tn.content = one;
tn.fn = fn;
tn.type = type.replaceAll("\\s+", "").replaceAll("::_", "::");
tn.len = len;
types.add(tn);
// put the node in the map
Warehouse.cname2node.put(tn.cName, tn);
Warehouse.allType.add(tn.cName);
}
}
ret = mType.replaceAll("");
// group 1--name, group 2--value;
String struct_dcl = "struct\\s+" + identifier_catch + "\\s*\\{" + "("
+ nestingPair(5, '{', '}') + ")" + "\\}\\s*;";
pType = Pattern.compile(struct_dcl, Pattern.DOTALL + Pattern.MULTILINE);
mType = pType.matcher(ret);
while (mType.find()) {
String one = mType.group(0);
String name = mType.group(1);
String val = mType.group(2);
// ready to create the node
IdlType tn = new IdlType();
tn.sName = name;
tn.cName = parent + "::" + name;
tn.content = one;
tn.fn = fn;
tn.type = "struct";
tn.val = val;
types.add(tn);
// put the node in the map
Warehouse.cname2node.put(tn.cName, tn);
Warehouse.allType.add(tn.cName);
}
ret = mType.replaceAll("");
// group 1--name, group 2--swithtype, group 3--value
String union_dcl = "union\\s+" + identifier_catch + "\\s+switch\\s*\\(([^\\(\\)]*)\\)\\s*"
+ "\\{" + "(" + nestingPair(5, '{', '}') + ")" + "\\}\\s*;";
pType = Pattern.compile(union_dcl, Pattern.DOTALL + Pattern.MULTILINE);
mType = pType.matcher(ret);
while (mType.find()) {
String one = mType.group(0);
String name = mType.group(1);
String stype = mType.group(2);
String val = mType.group(3);
// ready to create the node
IdlType tn = new IdlType();
tn.sName = name;
tn.cName = parent + "::" + name;
tn.content = one;
tn.fn = fn;
tn.type = "union";
tn.val = val;
tn.stype = stype.replaceAll("\\s+", "").replaceAll("::_", "::");
types.add(tn);
// put the node in the map
Warehouse.cname2node.put(tn.cName, tn);
Warehouse.allType.add(tn.cName);
}
ret = mType.replaceAll("");
// group 1--name, group 2--value
String enu_dcl = "enum\\s+" + identifier_catch + "\\s*\\{" + "(" + nestingPair(5, '{', '}')
+ ")" + "\\}\\s*;";
pType = Pattern.compile(enu_dcl, Pattern.DOTALL + Pattern.MULTILINE);
mType = pType.matcher(ret);
while (mType.find()) {
String one = mType.group(0);
String name = mType.group(1);
String val = mType.group(2);
// ready to create the node
IdlType tn = new IdlType();
tn.sName = name;
tn.cName = parent + "::" + name;
tn.content = one;
tn.fn = fn;
tn.type = "enum";
tn.val = val;
types.add(tn);
// put the node in the map
Warehouse.cname2node.put(tn.cName, tn);
Warehouse.allType.add(tn.cName);
}
ret = mType.replaceAll("");
// group 1--itype, group 2--declarators
String seq_dcl = "typedef\\s+sequence\\s*" + "\\<\\s*" + "(" + param_type_spec + ")"
+ "[^\\>]*\\>\\s*" + "(" + "[^;]*" + ")\\s*;";
pType = Pattern.compile(seq_dcl, Pattern.DOTALL + Pattern.MULTILINE);
mType = pType.matcher(ret);
while (mType.find()) {
String one = mType.group(0);
String itype = mType.group(1);
String declarators = mType.group(2);
// group 1--name, group 2--arraylength
Pattern pDeclarator = Pattern.compile(declarator, Pattern.DOTALL + Pattern.MULTILINE);
Matcher mDeclarator = pDeclarator.matcher(declarators);
while (mDeclarator.find()) {
String name = mDeclarator.group(1);
String alen = mDeclarator.group(2);
int len = parsePositiveIntConst(alen);
// ready to create the node
IdlType tn = new IdlType();
tn.sName = name;
tn.cName = parent + "::" + name;
tn.content = one;
tn.fn = fn;
tn.type = "sequence";
tn.itype = itype.replaceAll("\\s+", "").replaceAll("::_", "::");
tn.len = len;
types.add(tn);
// put the node in the map
Warehouse.cname2node.put(tn.cName, tn);
Warehouse.allType.add(tn.cName);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -