1 package com.thaiopensource.relaxng.impl; 2 3 class MixedTextDerivFunction extends EndAttributesFunction { 4 5 MixedTextDerivFunction(ValidatorPatternBuilder builder) { 6 super(builder); 7 } 8 9 public Object caseText(TextPattern p) { 10 return p; 11 } 12 13 public Object caseGroup(GroupPattern p) { 14 final Pattern p1 = p.getOperand1(); 15 final Pattern p2 = p.getOperand2(); 16 final Pattern q1 = memoApply(p1); 17 Pattern tem = (q1 == p1) ? p : getPatternBuilder().makeGroup(q1, p2); 18 if (!p1.isNullable()) 19 return tem; 20 return getPatternBuilder().makeChoice(tem, memoApply(p2)); 21 } 22 23 public Object caseInterleave(InterleavePattern p) { 24 final Pattern p1 = p.getOperand1(); 25 final Pattern p2 = p.getOperand2(); 26 final Pattern q1 = memoApply(p1); 27 final Pattern q2 = memoApply(p2); 28 final Pattern i1 = (q1 == p1) ? p : getPatternBuilder().makeInterleave(q1, p2); 29 final Pattern i2 = (q2 == p2) ? p : getPatternBuilder().makeInterleave(p1, q2); 30 return getPatternBuilder().makeChoice(i1, i2); 31 } 32 33 public Object caseOneOrMore(OneOrMorePattern p) { 34 return getPatternBuilder().makeGroup(memoApply(p.getOperand()), 35 getPatternBuilder().makeOptional(p)); 36 } 37 38 public Object caseOther(Pattern p) { 39 return getPatternBuilder().makeNotAllowed(); 40 } 41 42 PatternMemo apply(PatternMemo memo) { 43 return memo.mixedTextDeriv(this); 44 } 45 } 46 | Popular Tags |