예제 #1
0
		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;
		}
예제 #2
0
		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);
		}
예제 #4
0
		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;
		}
예제 #5
0
		public RdpAfter (RdpPattern l, RdpPattern r) : base (l, r)
		{
		}
예제 #6
0
		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);
		}
예제 #8
0
		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;
		}
예제 #9
0
		internal override RdpPattern ExpandRef (Hashtable defs)
		{
			if (!expanded) {
				l = l.ExpandRef (defs);
				r = r.ExpandRef (defs);
			}
			return this;
		}
예제 #10
0
		public RdpAbstractBinary (RdpPattern l, RdpPattern r)
		{
			this.l = l;
			this.r = r;
		}
예제 #11
0
		// After(this, p)
		public virtual RdpPattern After (RdpPattern p)
		{
			if (this is RdpNotAllowed || p is RdpNotAllowed)
				return RdpNotAllowed.Instance;
			else
				return MakeAfter (this, p);
		}
예제 #12
0
		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];
		}
예제 #13
0
		public RdpAttribute (RdpNameClass nameClass, RdpPattern p)
		{
			this.nameClass = nameClass;
			this.children = p;
		}
예제 #14
0
		public override RdpPattern TextDeriv (string s, XmlReader reader)
		{
			if (s == cachedValue && !IsContextDependent)
				return cachedPattern;
			cachedPattern = TextDerivCore (s, reader);
			cachedValue = s;
			return cachedPattern;
		}
예제 #15
0
		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;
			}
		}
예제 #16
0
		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];
		}
예제 #17
0
		public RdpDataExcept (RdpDatatype dt, RdpPattern except)
			: base (dt)
		{
			this.except = except;
		}
예제 #18
0
		// 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);
		}
예제 #19
0
		// 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);
		}
예제 #20
0
		internal override RdpPattern ExpandRef (Hashtable defs)
		{
			if (!isExpanded) {
				isExpanded = true;
				children = children.ExpandRef (defs);
			}
			return this;
		}
예제 #21
0
		public RdpOneOrMore (RdpPattern p) : base (p)
		{
		}
예제 #22
0
		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;
			}
		}
예제 #23
0
		public RdpElement (RdpNameClass nameClass, RdpPattern p)
		{
			this.nameClass = nameClass;
			this.children = p;
		}
예제 #24
0
		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];
		}
예제 #25
0
		public RdpChoice (RdpPattern l, RdpPattern r) : base (l, r)
		{
		}
예제 #26
0
		public RdpAbstractSingleContent (RdpPattern p)
		{
			this.child = p;
		}
		public void SetUp ()
		{
			pattern1 = new RdpElement (new RdpName ("foo", "urn:foo"), RdpEmpty.Instance);
		}
예제 #28
0
		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;
		}
예제 #29
0
		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;
		}
예제 #30
0
		public RdpList (RdpPattern p) : base (p)
		{
		}