提交 6e5284e0 authored 作者: Thomas Mueller's avatar Thomas Mueller

Support '[' and ']' (for Apache Jackrabbit)

上级 1b31e3e9
...@@ -129,6 +129,8 @@ public class Bnf { ...@@ -129,6 +129,8 @@ public class Bnf {
addFixedRule("@az_@", RuleFixed.AZ_UNDERSCORE); addFixedRule("@az_@", RuleFixed.AZ_UNDERSCORE);
addFixedRule("@af@", RuleFixed.AF); addFixedRule("@af@", RuleFixed.AF);
addFixedRule("@digit@", RuleFixed.DIGIT); addFixedRule("@digit@", RuleFixed.DIGIT);
addFixedRule("@open_bracket@", RuleFixed.OPEN_BRACKET);
addFixedRule("@close_bracket@", RuleFixed.CLOSE_BRACKET);
} }
/** /**
...@@ -315,6 +317,8 @@ public class Bnf { ...@@ -315,6 +317,8 @@ public class Bnf {
syntax = StringUtils.replaceAll(syntax, "a-f", "@af@"); syntax = StringUtils.replaceAll(syntax, "a-f", "@af@");
syntax = StringUtils.replaceAll(syntax, "A-F", "@af@"); syntax = StringUtils.replaceAll(syntax, "A-F", "@af@");
syntax = StringUtils.replaceAll(syntax, "0-9", "@digit@"); syntax = StringUtils.replaceAll(syntax, "0-9", "@digit@");
syntax = StringUtils.replaceAll(syntax, "'['", "@openBracket@");
syntax = StringUtils.replaceAll(syntax, "']'", "@closeBracket@");
StringTokenizer tokenizer = getTokenizer(syntax); StringTokenizer tokenizer = getTokenizer(syntax);
while (tokenizer.hasMoreTokens()) { while (tokenizer.hasMoreTokens()) {
String s = tokenizer.nextToken(); String s = tokenizer.nextToken();
......
...@@ -21,6 +21,7 @@ public class RuleFixed implements Rule { ...@@ -21,6 +21,7 @@ public class RuleFixed implements Rule {
static final int ANY_WORD = 7; static final int ANY_WORD = 7;
static final int ANY_EXCEPT_2_DOLLAR = 8; static final int ANY_EXCEPT_2_DOLLAR = 8;
static final int HEX_START = 10, CONCAT = 11, AZ_UNDERSCORE = 12, AF = 13, DIGIT = 14; static final int HEX_START = 10, CONCAT = 11, AZ_UNDERSCORE = 12, AF = 13, DIGIT = 14;
static final int OPEN_BRACKET = 15, CLOSE_BRACKET = 16;
private final int type; private final int type;
...@@ -54,6 +55,10 @@ public class RuleFixed implements Rule { ...@@ -54,6 +55,10 @@ public class RuleFixed implements Rule {
return "F"; return "F";
case DIGIT: case DIGIT:
return "0"; return "0";
case OPEN_BRACKET:
return "[";
case CLOSE_BRACKET:
return "]";
default: default:
throw new AssertionError("type="+type); throw new AssertionError("type="+type);
} }
...@@ -89,6 +94,10 @@ public class RuleFixed implements Rule { ...@@ -89,6 +94,10 @@ public class RuleFixed implements Rule {
return "A-F"; return "A-F";
case DIGIT: case DIGIT:
return "0-9"; return "0-9";
case OPEN_BRACKET:
return "[";
case CLOSE_BRACKET:
return "]";
default: default:
throw new AssertionError("type="+type); throw new AssertionError("type="+type);
} }
...@@ -126,6 +135,10 @@ public class RuleFixed implements Rule { ...@@ -126,6 +135,10 @@ public class RuleFixed implements Rule {
return "" + (char) ('A' + r.nextInt('F' - 'A')); return "" + (char) ('A' + r.nextInt('F' - 'A'));
case DIGIT: case DIGIT:
return "" + (char) ('0' + r.nextInt(10)); return "" + (char) ('0' + r.nextInt(10));
case OPEN_BRACKET:
return "[";
case CLOSE_BRACKET:
return "]";
default: default:
throw new AssertionError("type="+type); throw new AssertionError("type="+type);
} }
...@@ -247,6 +260,12 @@ public class RuleFixed implements Rule { ...@@ -247,6 +260,12 @@ public class RuleFixed implements Rule {
s = s.substring(1); s = s.substring(1);
} }
break; break;
case OPEN_BRACKET:
s = s.substring(1);
break;
case CLOSE_BRACKET:
s = s.substring(1);
break;
default: default:
throw new AssertionError("type=" + type); throw new AssertionError("type=" + type);
} }
...@@ -326,6 +345,12 @@ public class RuleFixed implements Rule { ...@@ -326,6 +345,12 @@ public class RuleFixed implements Rule {
sentence.add("digit", "1", Sentence.KEYWORD); sentence.add("digit", "1", Sentence.KEYWORD);
} }
break; break;
case OPEN_BRACKET:
sentence.add("[", "[", Sentence.KEYWORD);
break;
case CLOSE_BRACKET:
sentence.add("]", "]", Sentence.KEYWORD);
break;
default: default:
throw new AssertionError("type="+type); throw new AssertionError("type="+type);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论