1 21 22 package net.percederberg.grammatica.parser.re; 23 24 import java.io.IOException ; 25 import java.io.PrintWriter ; 26 27 import net.percederberg.grammatica.parser.LookAheadReader; 28 29 36 class CombineElement extends Element { 37 38 41 private Element elem1; 42 43 46 private Element elem2; 47 48 54 public CombineElement(Element first, Element second) { 55 elem1 = first; 56 elem2 = second; 57 } 58 59 67 public Object clone() { 68 return new CombineElement(elem1, elem2); 69 } 70 71 88 public int match(Matcher m, LookAheadReader input, int start, int skip) 89 throws IOException { 90 91 int length1 = -1; 92 int length2 = 0; 93 int skip1 = 0; 94 int skip2 = 0; 95 96 while (skip >= 0) { 97 length1 = elem1.match(m, input, start, skip1); 98 if (length1 < 0) { 99 return -1; 100 } 101 length2 = elem2.match(m, input, start + length1, skip2); 102 if (length2 < 0) { 103 skip1++; 104 skip2 = 0; 105 } else { 106 skip2++; 107 skip--; 108 } 109 } 110 111 return length1 + length2; 112 } 113 114 120 public void printTo(PrintWriter output, String indent) { 121 elem1.printTo(output, indent); 122 elem2.printTo(output, indent); 123 } 124 125 } 126 | Popular Tags |