Example #1
0
        private RelaxngChoice ReadChoicePattern()
        {
            RelaxngChoice c = new RelaxngChoice();

            FillLocation(c);
            expect("choice");
            Read();
            ReadPatterns(c);
            expectEnd("choice");
            return(c);
        }
Example #2
0
		private RelaxngChoice ReadChoicePattern ()
		{
			RelaxngChoice c = new RelaxngChoice ();
			FillLocation (c);
			expect ("choice");
			Read ();
			ReadPatterns (c);
			expectEnd ("choice");
			return c;
		}
Example #3
0
		RelaxngPattern CreatePatternFromType (XmlSchemaType type)
		{
			XmlSchemaSimpleType st = type as XmlSchemaSimpleType;
			if (st == null)
				throw new NotSupportedException ("Complex types are not supported as an attribute type.");
			XmlSchemaSimpleTypeRestriction r =
				st.Content as XmlSchemaSimpleTypeRestriction;
			if (r == null)
				throw new NotSupportedException ("Only simple type restriction is supported as an attribute type.");

			RelaxngChoice c = new RelaxngChoice ();
			foreach (XmlSchemaFacet f in r.Facets) {
				XmlSchemaEnumerationFacet en =
					f as XmlSchemaEnumerationFacet;
				if (en == null)
					throw new NotSupportedException ("Only enumeration facet is supported.");
				RelaxngValue v = new RelaxngValue ();
				v.Type = r.BaseTypeName.Name;
				v.DatatypeLibrary = RemapDatatypeLibrary (
					r.BaseTypeName.Namespace);
				v.Value = en.Value;
				c.Patterns.Add (v);
			}
			return c;
		}
Example #4
0
        private void AssembleCombine()
        {
            // calculate combines.
            bool      haveHeadStart = false;
            string    combineStart  = null;
            Hashtable haveHeadDefs  = new Hashtable();
            Hashtable combineDefs   = new Hashtable();

            // 1.calculate combine for starts.
            foreach (RelaxngStart start in starts)
            {
                CheckCombine(ref haveHeadStart,
                             ref combineStart, start.Combine, "start");
            }
            // 2.calculate combine for defines.
            foreach (RelaxngDefine def in defs)
            {
                bool haveHead =
                    haveHeadDefs.ContainsKey(def.Name) ?
                    haveHead = (bool)haveHeadDefs [def.Name]
                           : false;
                string combine = combineDefs [def.Name] as string;
                CheckCombine(ref haveHead, ref combine,
                             def.Combine, String.Format("define name={0}", def.Name));
                haveHeadDefs [def.Name] = haveHead;
                combineDefs [def.Name]  = combine;
                continue;
            }

            // assemble starts and defines with "combine" attribute.

            // 3.assemble starts.
            if (starts.Count == 0)
            {
                if (ParentGrammar == null)
                {
                    throw new RelaxngException(this, "grammar must have at least one start component.");
                }
            }
            else
            {
                assembledStart = ((RelaxngStart)starts [0]).Pattern;
                for (int i = 1; i < starts.Count; i++)
                {
                    RelaxngPattern p2 = ((RelaxngStart)starts [i]).Pattern;;
                    if (combineStart == "interleave")
                    {
                        RelaxngInterleave intlv = new RelaxngInterleave();
                        intlv.Patterns.Add(assembledStart);
                        intlv.Patterns.Add(p2);
                        assembledStart = intlv;
                    }
                    else
                    {
                        RelaxngChoice c = new RelaxngChoice();
                        c.Patterns.Add(assembledStart);
                        c.Patterns.Add(p2);
                        assembledStart = c;
                    }
                }
            }

            // 4.assemble defines
            foreach (RelaxngDefine def in defs)
            {
                string     combine = combineDefs [def.Name] as string;
                RdpPattern p1      =
                    assembledDefs [def.Name] as RdpPattern;
                RdpPattern p2 = def.Compile(this);
                if (p1 != null)
                {
                    if (combine == "interleave")
                    {
                        assembledDefs [def.Name] =
                            new RdpInterleave(p1, p2);
                    }
                    else
                    {
                        assembledDefs [def.Name] =
                            new RdpChoice(p1, p2);
                    }
                }
                else
                {
                    assembledDefs [def.Name] = p2;
                }
            }
        }
Example #5
0
		RelaxngPattern CreatePatternFromParticleCore (XmlSchemaParticle xsdp)
		{
			XmlSchemaGroupBase gb = xsdp as XmlSchemaGroupBase;
			if (xsdp is XmlSchemaAny) {
				RelaxngRef r = new RelaxngRef ();
				r.Name = "anyType";
				return r;
			}
			if (gb is XmlSchemaSequence) {
				RelaxngGroup grp = new RelaxngGroup ();
				foreach (XmlSchemaParticle xsdc in gb.Items)
					grp.Patterns.Add (CreatePatternFromParticle (xsdc));
				return grp;
			}
			if (gb is XmlSchemaChoice) {
				RelaxngChoice rc = new RelaxngChoice ();
				foreach (XmlSchemaParticle xsdc in gb.Items)
					rc.Patterns.Add (CreatePatternFromParticle (xsdc));
				return rc;
			}
			return CreateElement ((XmlSchemaElement) xsdp);
		}
Example #6
0
		RelaxngGrammar DtdXsd2Rng (XmlSchema xsd, string ns)
		{
			g = new RelaxngGrammar ();
			g.DefaultNamespace = ns;
			RelaxngStart start = new RelaxngStart ();
			g.Starts.Add (start);
			RelaxngChoice choice = new RelaxngChoice ();
			start.Pattern = choice;

			// There are only elements.
			foreach (XmlSchemaElement el in xsd.Items) {
				RelaxngDefine def = DefineElement (el);
				g.Defines.Add (def);
				RelaxngRef dref = new RelaxngRef ();
				dref.Name = def.Name;
				choice.Patterns.Add (dref);
			}

			return g;
		}
Example #7
0
		public void WriteChoice (RelaxngChoice p)
		{
			WritePatterns (p.Patterns, '|', false);
		}
		// Note that it does not return the changed sequence.
		private RelaxngSingleContentPattern ToSequenceOfChoice (
			RelaxngElement ct, RelaxngGroup s)
		{
			RelaxngSingleContentPattern scp =
				laxOccurence ?
				(RelaxngSingleContentPattern)
				new RelaxngZeroOrMore () :
				new RelaxngOneOrMore ();
			RelaxngChoice c = new RelaxngChoice ();
			foreach (RelaxngPattern p in s.Patterns)
				c.Patterns.Add (p);
			scp.Patterns.Add (c);
			ct.Patterns.Clear ();
			ct.Patterns.Add (scp);
			return scp;
		}
Example #9
0
		private void AssembleCombine ()
		{
			// calculate combines.
			bool haveHeadStart = false;
			string combineStart = null;
			Hashtable haveHeadDefs = new Hashtable ();
			Hashtable combineDefs = new Hashtable ();

			// 1.calculate combine for starts.
			foreach (RelaxngStart start in starts)
				CheckCombine (ref haveHeadStart, 
					ref combineStart, start.Combine, "start");
			// 2.calculate combine for defines.
			foreach (RelaxngDefine def in defs) {
				bool haveHead = 
					haveHeadDefs.ContainsKey (def.Name) ?
					haveHead = (bool) haveHeadDefs [def.Name]
					: false;
				string combine = combineDefs [def.Name] as string;
				CheckCombine (ref haveHead, ref combine,
					def.Combine, String.Format ("define name={0}", def.Name));
				haveHeadDefs [def.Name] = haveHead;
				combineDefs [def.Name] = combine;
				continue;
			}

			// assemble starts and defines with "combine" attribute.

			// 3.assemble starts.
			if (starts.Count == 0) {
				if (ParentGrammar == null)
					throw new RelaxngException (this, "grammar must have at least one start component.");
			} else {
				assembledStart = ((RelaxngStart)starts [0]).Pattern;
				for (int i=1; i<starts.Count; i++) {
					RelaxngPattern p2 = ((RelaxngStart) starts [i]).Pattern;;
					if (combineStart == "interleave") {
						RelaxngInterleave intlv = new RelaxngInterleave ();
						intlv.Patterns.Add (assembledStart);
						intlv.Patterns.Add (p2);
						assembledStart = intlv;
					} else {
						RelaxngChoice c = new RelaxngChoice ();
						c.Patterns.Add (assembledStart);
						c.Patterns.Add (p2);
						assembledStart = c;
					}
				}
			}

			// 4.assemble defines
			foreach (RelaxngDefine def in defs) {
				string combine = combineDefs [def.Name] as string;
				RdpPattern p1 = 
					assembledDefs [def.Name] as RdpPattern;
				RdpPattern p2 = def.Compile (this);
				if (p1 != null) {
					if (combine == "interleave") {
						assembledDefs [def.Name] =
							new RdpInterleave (p1, p2);
					} else {
						assembledDefs [def.Name] =
							new RdpChoice (p1, p2);
					}
				} else {
					assembledDefs [def.Name] = p2;
				}
			}

		}