Exemplo n.º 1
0
 public NodePattern getNodePattern(String name) {
   Object obj = variables.get(name);
   if (obj != null) {
     if (obj instanceof SequencePattern) {
       SequencePattern seqPattern = (SequencePattern) obj;
       if (seqPattern.getPatternExpr() instanceof SequencePattern.NodePatternExpr) {
         return ((SequencePattern.NodePatternExpr) seqPattern.getPatternExpr()).nodePattern;
       } else {
         throw new Error(
             "Invalid node pattern class: "
                 + seqPattern.getPatternExpr().getClass()
                 + " for variable "
                 + name);
       }
     } else if (obj instanceof SequencePattern.NodePatternExpr) {
       SequencePattern.NodePatternExpr pe = (SequencePattern.NodePatternExpr) obj;
       return pe.nodePattern;
     } else if (obj instanceof NodePattern) {
       return (NodePattern) obj;
     } else if (obj instanceof String) {
       try {
         SequencePattern.NodePatternExpr pe =
             (SequencePattern.NodePatternExpr) parser.parseNode(this, (String) obj);
         return pe.nodePattern;
       } catch (Exception pex) {
         throw new RuntimeException("Error parsing " + obj + " to node pattern", pex);
       }
     } else {
       throw new Error(
           "Invalid node pattern variable class: " + obj.getClass() + " for variable " + name);
     }
   }
   return null;
 }
Exemplo n.º 2
0
 public SequencePattern.PatternExpr getSequencePatternExpr(String name, boolean copy) {
   Object obj = variables.get(name);
   if (obj != null) {
     if (obj instanceof SequencePattern) {
       SequencePattern seqPattern = (SequencePattern) obj;
       return seqPattern.getPatternExpr();
     } else if (obj instanceof SequencePattern.PatternExpr) {
       SequencePattern.PatternExpr pe = (SequencePattern.PatternExpr) obj;
       return (copy) ? pe.copy() : pe;
     } else if (obj instanceof NodePattern) {
       return new SequencePattern.NodePatternExpr((NodePattern) obj);
     } else if (obj instanceof String) {
       try {
         return parser.parseSequence(this, (String) obj);
       } catch (Exception pex) {
         throw new RuntimeException("Error parsing " + obj + " to sequence pattern", pex);
       }
     } else {
       throw new Error("Invalid sequence pattern variable class: " + obj.getClass());
     }
   }
   return null;
 }
Exemplo n.º 3
0
 public void bind(String name, SequencePattern pattern) {
   bind(name, pattern.getPatternExpr());
 }