RdpPattern ReplaceAfterHeadWithEmpty(RdpPattern p) { if (p is RdpAbstractSingleContent) { return(new RdpChoice(RdpEmpty.Instance, p)); } RdpAbstractBinary ab = p as RdpAbstractBinary; if (ab == null) { return(p); } if (ab is RdpGroup) { return(new RdpGroup(ReplaceAfterHeadWithEmpty(ab.LValue), ReplaceAfterHeadWithEmpty(ab.RValue))); } else if (ab is RdpChoice) { return(new RdpChoice(ReplaceAfterHeadWithEmpty(ab.LValue), ReplaceAfterHeadWithEmpty(ab.RValue))); } else if (ab is RdpInterleave) { return(new RdpInterleave(ReplaceAfterHeadWithEmpty(ab.LValue), ReplaceAfterHeadWithEmpty(ab.RValue))); } else if (ab is RdpAfter) { return(new RdpAfter(RdpEmpty.Instance, ab.RValue)); } throw new SystemException("INTERNAL ERROR: unexpected pattern: " + p.GetType()); }
// Error recovery feature can be enabled by using // InvalidNodeFound event of type RelaxngValidationEventHandler. // // Other than startTagOpenDeriv, it is (again) based on // James Clark's derivative algorithm. // http://www.thaiopensource.com/relaxng/derivative.html // For invalid start tag, we just recover from it by using // xs:any-like pattern for unexpected node occurence. RdpPattern MakeGroupHeadOptional(RdpPattern p) { if (p is RdpAbstractSingleContent) { return(new RdpChoice(RdpEmpty.Instance, p)); } RdpAbstractBinary ab = p as RdpAbstractBinary; if (ab == null) { return(p); } if (ab is RdpGroup) { return(new RdpGroup(new RdpChoice(RdpEmpty.Instance, ab.LValue), ab.RValue)); } else if (ab is RdpChoice) { return(new RdpChoice(MakeGroupHeadOptional(ab.LValue), MakeGroupHeadOptional(ab.RValue))); } else if (ab is RdpInterleave) { return(new RdpInterleave(MakeGroupHeadOptional(ab.LValue), MakeGroupHeadOptional(ab.RValue))); } else if (ab is RdpAfter) // FIXME: is it correct? { return(new RdpAfter(MakeGroupHeadOptional(ab.LValue), MakeGroupHeadOptional(ab.RValue))); } throw new SystemException("INTERNAL ERROR: unexpected pattern: " + p.GetType()); }
RdpPattern ReplaceAttributesWithEmpty(RdpPattern p) { if (p is RdpAttribute) { return(RdpEmpty.Instance); } RdpAbstractSingleContent asc = p as RdpAbstractSingleContent; if (asc is RdpList) { return(new RdpList(ReplaceAttributesWithEmpty(asc.Child))); } if (asc is RdpOneOrMore) { return(new RdpOneOrMore(ReplaceAttributesWithEmpty(asc.Child))); } else if (asc is RdpElement) { return(asc); // should not be expected to contain any attribute as RdpElement. } RdpAbstractBinary ab = p as RdpAbstractBinary; if (ab == null) { return(p); } if (ab is RdpGroup) { return(new RdpGroup(ReplaceAttributesWithEmpty(ab.LValue), ReplaceAttributesWithEmpty(ab.RValue))); } else if (ab is RdpChoice) { return(new RdpChoice(ReplaceAttributesWithEmpty(ab.LValue), ReplaceAttributesWithEmpty(ab.RValue))); } else if (ab is RdpInterleave) { return(new RdpInterleave(ReplaceAttributesWithEmpty(ab.LValue), ReplaceAttributesWithEmpty(ab.RValue))); } else if (ab is RdpAfter) // FIXME: is it correct? { return(new RdpAfter(ReplaceAttributesWithEmpty(ab.LValue), ReplaceAttributesWithEmpty(ab.RValue))); } throw new SystemException("INTERNAL ERROR: unexpected pattern: " + p.GetType()); }