Exemple #1
0
        private RelaxngInterleave ReadInterleavePattern()
        {
            RelaxngInterleave i = new RelaxngInterleave();

            FillLocation(i);
            expect("interleave");
            Read();
            ReadPatterns(i);
            expectEnd("interleave");
            return(i);
        }
Exemple #2
0
		private RelaxngInterleave ReadInterleavePattern ()
		{
			RelaxngInterleave i = new RelaxngInterleave ();
			FillLocation (i);
			expect ("interleave");
			Read ();
			ReadPatterns (i);
			expectEnd ("interleave");
			return i;
		}
Exemple #3
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;
                }
            }
        }
Exemple #4
0
		public void WriteInterleave (RelaxngInterleave p)
		{
			WritePatterns (p.Patterns, '&', false);
		}
		private void InferAttributes (RelaxngElement ct, bool isNew)
		{
			RelaxngInterleave attList = null;
			Hashtable table = null;

			do {
				if (source.NamespaceURI == NamespaceXmlns)
					continue;

				if (table == null) {
					attList = GetAttributes (ct);
					table = CollectAttrTable (attList);
				}
				QName attrName = new QName (
					source.LocalName, source.NamespaceURI);
				RelaxngPattern attr = table [attrName]
					as RelaxngPattern;
				if (attr == null) {
					if (attList == null) {
						attList = new RelaxngInterleave ();
						ct.Patterns.Insert (0, attList);
					}
					attList.Patterns.Add (
						InferNewAttribute (
						attrName, isNew));
				} else {
					table.Remove (attrName);
					if (attrName.Namespace.Length > 0) {
						RelaxngDefine ga = GetGlobalAttribute (attrName);
						InferMergedAttribute (
							ga.Patterns [0]);
					}
					else
						InferMergedAttribute (attr);
				}
			} while (source.MoveToNextAttribute ());

			// mark all attr definitions that did not appear
			// as optional.
			if (table != null) {
				foreach (RelaxngPattern attr in table.Values) {
					if (attr is RelaxngOptional)
						continue;
					attList.Patterns.Remove (attr);
					RelaxngOptional opt = new RelaxngOptional ();
					opt.Patterns.Add (attr);
					attList.Patterns.Add (opt);
				}
			}
		}
		// get attribute definition table.
		private Hashtable CollectAttrTable (RelaxngInterleave attList)
		{
			Hashtable table = new Hashtable ();
			if (attList == null)
				return table;
			foreach (RelaxngPattern p in attList.Patterns) {
				RelaxngAttribute a = p as RelaxngAttribute;
				if (a == null)
					a = (RelaxngAttribute)
						((RelaxngOptional) p)
						.Patterns [0];
				RelaxngName rn = a.NameClass as RelaxngName;
				table.Add (new QName (
					rn.LocalName, rn.Namespace),
					a);
			}
			return table;
		}
Exemple #7
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;
				}
			}

		}