コード例 #1
0
 protected Frag build() {
   Frag frag = new Frag();
   frag.start = new State();
   // Create NFA fragment that
   // have one starting state that branches out to NFAs created by the children expressions
   //  ---> pattern 1 --->
   //   |
   //   ---> pattern 2 --->
   //   ...
   for (PatternExpr pattern : patterns) {
     // Build child NFA
     Frag f = pattern.build();
     // Add child NFA to next states of fragment start
     frag.start.add(f.start);
     // Add child NFA out (unlinked) states to out (unlinked) states of this fragment
     frag.add(f.out);
   }
   return frag;
 }
コード例 #2
0
    protected Frag build() {
      ConjStartState conjStart = new ConjStartState(patterns.size());
      Frag frag = new Frag();
      frag.start = conjStart;
      // Create NFA fragment that
      // have one starting state that branches out to NFAs created by the children expressions
      // AND START ---> pattern 1 --->  AND END (0/n)
      //            |
      //             ---> pattern 2 ---> AND END (1/n)
      //             ...
      for (int i = 0; i < patterns.size(); i++) {
        PatternExpr pattern = patterns.get(i);
        // Build child NFA
        Frag f = pattern.build();
        // Add child NFA to next states of fragment start
        frag.start.add(f.start);

        f.connect(new ConjEndState(conjStart, i));
        // Add child NFA out (unlinked) states to out (unlinked) states of this fragment
        frag.add(f.out);
      }
      return frag;
    }