< prev index next >

src/java.base/share/classes/java/util/regex/PrintPattern.java

Print this page




 178             } else if (node instanceof Pattern.BranchConn) {
 179                 return;
 180             } else if (node instanceof Pattern.CharProperty) {
 181                 str = pmap.get(((Pattern.CharProperty)node).predicate);
 182                 if (str == null)
 183                     str = toString(node);
 184                 else
 185                     str = "Single \"" + str + "\"";
 186                 print(node, str, depth);
 187             } else if (node instanceof Pattern.SliceNode) {
 188                 str = name + "  \"" +
 189                       toStringCPS(((Pattern.SliceNode)node).buffer) + "\"";
 190                 print(node, str, depth);
 191             } else if (node instanceof Pattern.CharPropertyGreedy) {
 192                 Pattern.CharPropertyGreedy gcp = (Pattern.CharPropertyGreedy)node;
 193                 String pstr = pmap.get(gcp.predicate);
 194                 if (pstr == null)
 195                     pstr = gcp.predicate.toString();
 196                 else
 197                     pstr = "Single \"" + pstr + "\"";
 198                 str = name + " " + pstr;
 199                 if (gcp.cmin == 0)
 200                     str += "*";
 201                 else if (gcp.cmin == 1)
 202                     str += "+";
 203                 else
 204                     str += "{" + gcp.cmin + ",}";
 205                 print(node, str, depth);
 206             } else if (node instanceof Pattern.BackRef) {
 207                 str = "GroupBackRef " + ((Pattern.BackRef)node).groupIndex / 2;
 208                 print(node, str, depth);
 209             } else if (node instanceof Pattern.LastNode) {
 210                 print(node, "END", depth);
 211             } else if (node == Pattern.accept) {
 212                 return;
 213             } else {
 214                 print(node, name, depth);
 215             }
 216             node = node.next;
 217         }
 218     }
 219 
 220     public static void main(String[] args) {
 221         Pattern p = Pattern.compile(args[0]);
 222         System.out.println("   Pattern: " + p);
 223         walk(p.root, 0);
 224     }


 178             } else if (node instanceof Pattern.BranchConn) {
 179                 return;
 180             } else if (node instanceof Pattern.CharProperty) {
 181                 str = pmap.get(((Pattern.CharProperty)node).predicate);
 182                 if (str == null)
 183                     str = toString(node);
 184                 else
 185                     str = "Single \"" + str + "\"";
 186                 print(node, str, depth);
 187             } else if (node instanceof Pattern.SliceNode) {
 188                 str = name + "  \"" +
 189                       toStringCPS(((Pattern.SliceNode)node).buffer) + "\"";
 190                 print(node, str, depth);
 191             } else if (node instanceof Pattern.CharPropertyGreedy) {
 192                 Pattern.CharPropertyGreedy gcp = (Pattern.CharPropertyGreedy)node;
 193                 String pstr = pmap.get(gcp.predicate);
 194                 if (pstr == null)
 195                     pstr = gcp.predicate.toString();
 196                 else
 197                     pstr = "Single \"" + pstr + "\"";
 198                 str = name + " " + pstr + ((gcp.cmin == 0) ? "*" : "+");






 199                 print(node, str, depth);
 200             } else if (node instanceof Pattern.BackRef) {
 201                 str = "GroupBackRef " + ((Pattern.BackRef)node).groupIndex / 2;
 202                 print(node, str, depth);
 203             } else if (node instanceof Pattern.LastNode) {
 204                 print(node, "END", depth);
 205             } else if (node == Pattern.accept) {
 206                 return;
 207             } else {
 208                 print(node, name, depth);
 209             }
 210             node = node.next;
 211         }
 212     }
 213 
 214     public static void main(String[] args) {
 215         Pattern p = Pattern.compile(args[0]);
 216         System.out.println("   Pattern: " + p);
 217         walk(p.root, 0);
 218     }
< prev index next >