static RdpPattern () { RdpPattern anyAtts = new RdpList (new RdpAttribute (RdpAnyName.Instance, RdpText.Instance)); RdpElement anyElement = new RdpElement (RdpAnyName.Instance, null); Anything = new RdpChoice (RdpEmpty.Instance, new RdpChoice (anyAtts, new RdpChoice (RdpText.Instance, new RdpList (anyElement)))); anyElement.Children = Anything; }
internal static string DebugRdpPattern (RdpPattern p, Hashtable visitedPattern) { if (p is RdpText) return "<text/>\n"; if (p is RdpEmpty) return "<empty/>\n"; if (p is RdpNotAllowed) return "<notAllowed/>\n"; if (visitedPattern.Contains (p)) return "<" + p.PatternType + " ref='" + p.GetHashCode () + "'/>"; visitedPattern.Add (p, p); string intl = "(id=" + p.GetHashCode () + ") "; RdpAbstractSingleContent s = p as RdpAbstractSingleContent; if (s != null) intl = DebugRdpPattern (s.Child, visitedPattern); RdpAbstractBinary b = p as RdpAbstractBinary; if (b != null) intl = DebugRdpPattern (b.LValue, visitedPattern) + DebugRdpPattern (b.RValue, visitedPattern); RdpData data = p as RdpData; if (data != null) intl = String.Format ("name={0},ns={1},type={2} {3}", data.Datatype.LocalName, data.Datatype.NamespaceURI, data.Datatype.GetType (), data is RdpDataExcept ? DebugRdpPattern (((RdpDataExcept) data).Except, visitedPattern) : String.Empty); RdpValue value = p as RdpValue; if (value != null) intl = String.Format ("name={0},ns={1},value={2} type={3}", value.Datatype.LocalName, value.Datatype.NamespaceURI, value.Value, value.Datatype.GetType ()); RdpElement el = p as RdpElement; if (el != null) intl = DebugNameClass (el.NameClass) + DebugRdpPattern (el.Children, visitedPattern); RdpAttribute at = p as RdpAttribute; if (at != null) intl = DebugNameClass (at.NameClass) + DebugRdpPattern (at.Children, visitedPattern); string str = String.Format ("<{0} id='id{1}'>\n{2}\n</{0}>", p.PatternType.ToString (), p.GetHashCode (), intl); return str; }
public void ElementStartTagOpenDeriv () { result = pattern1.StartTagOpenDeriv ("bar", "urn:foo"); AssertPattern ("#element.start.1", RelaxngPatternType.NotAllowed, result); result = pattern1.StartTagOpenDeriv ("foo", "urn:bar"); AssertPattern ("#element.start.2", RelaxngPatternType.NotAllowed, result); result = pattern1.StartTagOpenDeriv ("foo", "urn:foo"); AssertPattern ("#element.start.3", RelaxngPatternType.After, result); RdpAfter after= result as RdpAfter; AssertPattern ("#element.start.4", RelaxngPatternType.Empty, after.LValue); AssertPattern ("#element.start.5", RelaxngPatternType.Empty, after.RValue); }
private Hashtable setupTable (Type type, RdpPattern p) { if (patternPool == null) // could be null for RdpElement etc. patternPool = new Hashtable (); Hashtable typePool = (Hashtable) patternPool [type]; if (typePool == null) { typePool = new Hashtable (); patternPool [type] = typePool; } Hashtable pTable = (Hashtable) typePool [p]; if (pTable == null) { pTable = new Hashtable (); typePool [p] = pTable; } return pTable; }
public RdpAfter (RdpPattern l, RdpPattern r) : base (l, r) { }
public RdpPattern MakeGroup (RdpPattern p1, RdpPattern p2) { if (p1.PatternType == RelaxngPatternType.Empty) return p2; Hashtable p1Table = setupTable (typeof (RdpGroup), p1); if (p1Table [p2] == null) { RdpGroup g = new RdpGroup (p1, p2); g.setInternTable (this.patternPool); p1Table [p2] = g; } return (RdpGroup) p1Table [p2]; }
private void AssertPattern (string s, RelaxngPatternType expected, RdpPattern p) { AssertEquals (s, expected, p.PatternType); }
internal RdpFlip MakeFlip (RdpBinaryFunction func, RdpPattern p) { if (patternPool == null) // could be null for RdpElement etc. patternPool = new Hashtable (); // Though this method takes function argument, all // p1 callers have different pattern types, so we don't // have to distinguish tables by func. Hashtable table = patternPool [func] as Hashtable; if (table == null) { table = new Hashtable (); patternPool [func] = table; } RdpFlip f = table [p] as RdpFlip; if (f != null) return f; f = new RdpFlip (func, p); table [p] = f; return f; }
internal override RdpPattern ExpandRef (Hashtable defs) { if (!expanded) { l = l.ExpandRef (defs); r = r.ExpandRef (defs); } return this; }
public RdpAbstractBinary (RdpPattern l, RdpPattern r) { this.l = l; this.r = r; }
// After(this, p) public virtual RdpPattern After (RdpPattern p) { if (this is RdpNotAllowed || p is RdpNotAllowed) return RdpNotAllowed.Instance; else return MakeAfter (this, p); }
public RdpAfter MakeAfter (RdpPattern p1, RdpPattern p2) { Hashtable p1Table = setupTable (typeof (RdpAfter), p1); if (p1Table [p2] == null) { RdpAfter a = new RdpAfter (p1, p2); a.setInternTable (this.patternPool); p1Table [p2] = a; } return (RdpAfter) p1Table [p2]; }
public RdpAttribute (RdpNameClass nameClass, RdpPattern p) { this.nameClass = nameClass; this.children = p; }
public override RdpPattern TextDeriv (string s, XmlReader reader) { if (s == cachedValue && !IsContextDependent) return cachedPattern; cachedPattern = TextDerivCore (s, reader); cachedValue = s; return cachedPattern; }
internal override RdpPattern ReduceEmptyAndNotAllowed (ref bool result, Hashtable visited) { if (visited.Contains (this)) return this; visited.Add (this, this); if (except.PatternType == RelaxngPatternType.NotAllowed) { result = true; return new RdpData (this.Datatype); } else { except = except.ReduceEmptyAndNotAllowed (ref result, visited); return this; } }
public RdpInterleave MakeInterleave (RdpPattern p1, RdpPattern p2) { if (p1.GetHashCode () > p2.GetHashCode ()) { RdpPattern tmp = p1; p1 = p2; p2 = tmp; } Hashtable p1Table = setupTable (typeof (RdpInterleave), p1); if (p1Table [p2] == null) { RdpInterleave i = new RdpInterleave (p1, p2); i.setInternTable (this.patternPool); p1Table [p2] = i; } return (RdpInterleave) p1Table [p2]; }
public RdpDataExcept (RdpDatatype dt, RdpPattern except) : base (dt) { this.except = except; }
// Choice(this, p) public virtual RdpPattern Choice (RdpPattern p) { if (p is RdpNotAllowed) return this; else if (this is RdpNotAllowed) return p; else return MakeChoice (this, p); }
// Interleave(this, p) public virtual RdpPattern Interleave (RdpPattern p) { if (p is RdpNotAllowed || this is RdpNotAllowed) return RdpNotAllowed.Instance; else if (p is RdpEmpty) return this; else if (this is RdpEmpty) return p; else return MakeInterleave (this, p); }
internal override RdpPattern ExpandRef (Hashtable defs) { if (!isExpanded) { isExpanded = true; children = children.ExpandRef (defs); } return this; }
public RdpOneOrMore (RdpPattern p) : base (p) { }
internal override RdpPattern ReduceEmptyAndNotAllowed (ref bool result, Hashtable visited) { if (visited.Contains (this)) return this; visited.Add (this, this); if (children.PatternType == RelaxngPatternType.NotAllowed) { result = true; return RdpNotAllowed.Instance; } else { children = children.ReduceEmptyAndNotAllowed (ref result, visited); return this; } }
public RdpElement (RdpNameClass nameClass, RdpPattern p) { this.nameClass = nameClass; this.children = p; }
public RdpOneOrMore MakeOneOrMore (RdpPattern p) { if (patternPool == null) // could be null for RdpElement etc. patternPool = new Hashtable (); Hashtable pTable = (Hashtable) patternPool [typeof (RdpOneOrMore)]; if (pTable == null) { pTable = new Hashtable (); patternPool [typeof (RdpOneOrMore)] = pTable; } if (pTable [p] == null) { RdpOneOrMore oom = new RdpOneOrMore (p); oom.setInternTable (patternPool); pTable [p] = oom; } return (RdpOneOrMore) pTable [p]; }
public RdpChoice (RdpPattern l, RdpPattern r) : base (l, r) { }
public RdpAbstractSingleContent (RdpPattern p) { this.child = p; }
public void SetUp () { pattern1 = new RdpElement (new RdpName ("foo", "urn:foo"), RdpEmpty.Instance); }
internal override RdpPattern ReduceEmptyAndNotAllowed (ref bool result, Hashtable visited) { if (visited.Contains (this)) return this; visited.Add (this, this); children = children.ReduceEmptyAndNotAllowed (ref result, visited); return this; }
short expanding; // FIXME: It is totally not required, but there is // some bugs in simplification and without it it causes infinite loop. internal override RdpPattern ExpandRef (Hashtable defs) { if (!isExpanded) { isExpanded = true; if (expanding == 100) throw new RelaxngException (String.Format ("Invalid recursion was found. Name is {0}", nameClass)); expanding++; children = children.ExpandRef (defs); expanding--; } return this; }
public RdpList (RdpPattern p) : base (p) { }