Beispiel #1
0
		public RdpPattern MakeChoice (RdpPattern p1, RdpPattern p2)
		{
			if (p1.PatternType == RelaxngPatternType.NotAllowed)
				return p2;
			if (p2.PatternType == RelaxngPatternType.NotAllowed)
				return p1;
			if (p1 == p2)
				return p1;
			// choice-leaves support
			if (p1.PatternType == RelaxngPatternType.Empty)
				return MakeChoiceLeaf (p2);
			if (p2.PatternType == RelaxngPatternType.Empty)
				return MakeChoiceLeaf (p1);

			if (p1.GetHashCode () > p2.GetHashCode ()) {
				RdpPattern tmp = p1;
				p1 = p2;
				p2 = tmp;
			}

			Hashtable p1Table = setupTable (typeof (RdpChoice), p1);
			if (p1Table [p2] == null) {
				RdpChoice c = new RdpChoice (p1, p2);
				c.setInternTable (this.patternPool);
				p1Table [p2] = c;
			}
			return (RdpChoice) p1Table [p2];
		}
Beispiel #2
0
		internal override RdpPattern Compile (RelaxngGrammar grammar)
		{
//			RdpParamList rdpl = new RdpParamList ();
//			foreach (RelaxngParam prm in this.paramList)
//				rdpl.Add (prm.Compile (grammar));
			RdpPattern p = null;
			if (this.except != null) {
				if (except.Patterns.Count == 0)
					throw new RelaxngException (this, "data except pattern have no children.");
				p = except.Patterns [0].Compile (grammar);
				for (int i=1; i<except.Patterns.Count; i++)
					p = new RdpChoice (p,
						except.Patterns [i].Compile (grammar));
			}

			IsCompiled = true;
			if (this.except != null)
				return new RdpDataExcept (new RdpDatatype (DatatypeLibrary, Type, ParamList, grammar.Provider), p);
			else
				return new RdpData (new RdpDatatype (DatatypeLibrary, Type, ParamList, grammar.Provider));
		}
Beispiel #3
0
		public RdpChoice MakeChoiceLeaf (RdpPattern p)
		{
			if (patternPool == null) // could be null for RdpElement etc.
				patternPool = new Hashtable ();
			Hashtable leaves = (Hashtable) patternPool [typeof (RdpEmpty)];
			if (leaves == null) {
				leaves = new Hashtable ();
				patternPool [typeof (RdpEmpty)] = leaves;
			}
			RdpChoice leaf = leaves [p] as RdpChoice;
			if (leaf == null) {
				leaf = new RdpChoice (RdpEmpty.Instance, p);
				leaf.setInternTable (patternPool);
				leaves [p] = leaf;
			}
			return leaf;
		}
Beispiel #4
0
		internal RdpPattern makeBinary (RelaxngGrammar g)
		{
			// Flatten patterns. See 4.12.
			if (patterns.Count == 0)
				throw new RelaxngException (this, "No pattern contents.");

			RdpPattern p = ((RelaxngPattern) patterns [0]).Compile (g);
			if (patterns.Count == 1)
				return p;

			for (int i=1; i<patterns.Count; i++) {
				RdpPattern cp =
					((RelaxngPattern) patterns [i]).Compile (g);
				switch (this.PatternType) {
				case RelaxngPatternType.Choice:
					p = new RdpChoice (p, cp);
					break;
				case RelaxngPatternType.Group:
					p = new RdpGroup (p, cp);
					break;
				case RelaxngPatternType.Interleave:
					p = new RdpInterleave (p, cp);
					break;
				}
			}

			return p;
		}