示例#1
0
        public void Compile()
        {
            RelaxngGrammar g = null;

            if (this is RelaxngGrammar)
            {
                g = (RelaxngGrammar)this;
            }
            else
            {
                g              = new RelaxngGrammar();
                g.XmlResolver  = this.Resolver;
                g.BaseUri      = this.BaseUri;
                g.LineNumber   = this.LineNumber;
                g.LinePosition = this.LinePosition;
                RelaxngStart st = new RelaxngStart();
                st.BaseUri      = this.BaseUri;
                st.LineNumber   = this.LineNumber;
                st.LinePosition = this.LinePosition;
                st.Pattern      = this;
                g.Starts.Add(st);
                g.Provider = provider;
            }
            startRelaxngPattern = g.Compile(null);
            this.IsCompiled     = true;
        }
示例#2
0
        public RelaxngPattern ReadExternalResource(RelaxngGrammar grammar, Uri uri, string nsContext)
        {
            XmlTextReader  xtr = null;
            RelaxngGrammar g   = null;
            RelaxngPattern p;

            try {
                if (grammar.IsSourceCompactSyntax)
                {
                    p = RncParser.ParseRnc(new StreamReader((Stream)grammar.Resolver.GetEntity(uri, null, typeof(Stream))), null, BaseUri, nsContext);
                }
                else
                {
                    xtr = new XmlTextReader(uri.AbsoluteUri, (Stream)grammar.Resolver.GetEntity(uri, null, typeof(Stream)));
                    RelaxngReader r = new RelaxngReader(xtr, nsContext, grammar.Resolver);
                    r.MoveToContent();
                    p = r.ReadPattern();
                }
            } catch (Exception ex) {             // umm, bad catch though :-(
                throw new RelaxngException(this, String.Format("Could not include grammar {0}: {1}", uri.AbsoluteUri, ex.Message), ex);
            } finally {
                if (xtr != null)
                {
                    xtr.Close();
                }
            }
            p.XmlResolver = grammar.Resolver;
            return(p);
        }
示例#3
0
		void WriteCompact (RncWriter writer)
		{
			RelaxngGrammar g = this as RelaxngGrammar;
			string ns = (g != null ? g.DefaultNamespace : null);
			writer.WriteNamespaces (ns);
			WriteRnc (writer);
		}
示例#4
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)));
            }
        }
示例#5
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;
		}
示例#6
0
 internal override RdpPattern Compile(RelaxngGrammar grammar)
 {
     IsCompiled = true;
     return(new RdpChoice(
                new RdpOneOrMore(makeSingle(grammar)),
                RdpEmpty.Instance));
 }
示例#7
0
		public RelaxngGrammar InferSchema (XmlReader xmlReader,
			RelaxngGrammar grammar)
		{
			return RngInference.Process (xmlReader, grammar,
				occurrence == InferenceOption.Relaxed,
				typeInference == InferenceOption.Relaxed);
		}
示例#8
0
        public RelaxngPattern ReadExternalResource(RelaxngGrammar grammar, Uri uri, string nsContext)
        {
            XmlReader      xtr = null;
            RelaxngGrammar g   = null;
            RelaxngPattern p;

            try {
                if (uri.AbsolutePath.EndsWith(".rnc", StringComparison.OrdinalIgnoreCase))
                {
                    p = RncParser.ParseRnc(new StreamReader((Stream)grammar.Resolver.GetEntity(uri, null, typeof(Stream))), null, uri.AbsoluteUri, nsContext);
                }
                else
                {
#if PORTABLE
                    xtr = XmlReader.Create((Stream)grammar.Resolver.GetEntity(uri, null, typeof(Stream)));
#else
                    xtr = new XmlTextReader(uri.AbsoluteUri, (Stream)grammar.Resolver.GetEntity(uri, null, typeof(Stream)));
#endif
                    RelaxngReader r = new RelaxngReader(xtr, nsContext, grammar.Resolver);
                    r.MoveToContent();
                    p = r.ReadPattern();
                }
            } catch (Exception ex) {             // umm, bad catch though :-(
                throw new RelaxngException(this, String.Format("Could not include grammar {0}: {1}", uri.AbsoluteUri, ex.Message), ex);
            } finally {
                if (xtr != null)
                {
                    xtr.Dispose();
                }
            }
            p.XmlResolver = grammar.Resolver;
            return(p);
        }
示例#9
0
		public static RelaxngGrammar Process (XmlReader xmlReader, 
			RelaxngGrammar grammar,
			bool laxOccurence,
			bool laxTypeInference)
		{
			RngInference impl = new RngInference (xmlReader,
				grammar, laxOccurence, laxTypeInference);
			impl.Run ();
			return impl.grammar;
		}
示例#10
0
		internal override RdpPattern Compile (RelaxngGrammar grammar)
		{
			IsCompiled = true;
			RdpNameClass cnc = nc.Compile (grammar);
			this.checkInvalidAttrNameClass (cnc);

			return new RdpAttribute (cnc,
				(p != null) ?
					p.Compile (grammar) :
					RdpText.Instance);
		}
示例#11
0
 private static string GetUniqueName(string name, RelaxngGrammar grammar)
 {
     foreach (RelaxngDefine def in grammar.Defines)
     {
         if (def.Name == name)
         {
             return(GetUniqueName(name + '_', grammar));
         }
     }
     return(name);
 }
示例#12
0
		internal void Compile (RelaxngGrammar grammar)
		{
			foreach (RelaxngDiv div in divs)
				div.Compile (grammar);
			foreach (RelaxngInclude inc in includes)
				inc.Compile (grammar).Compile (grammar); // compile compiled divs
			foreach (RelaxngStart start in starts)
				grammar.Starts.Add (start);
			foreach (RelaxngDefine define in defines)
				grammar.Defines.Add (define);
		}
示例#13
0
        private RelaxngGrammar ReadGrammarPattern()
        {
            RelaxngGrammar grammar = new RelaxngGrammar();

            FillLocation(grammar);
            grammar.DefaultNamespace = Reader.GetAttribute("ns");
            Read();
            this.readGrammarIncludeContent(grammar.Starts, grammar.Defines, grammar.Divs, grammar.Includes);
            expectEnd("grammar");

            return(grammar);
        }
示例#14
0
 private void ResetCompileState()
 {
     startPattern = null;
     assembledDefs.Clear();
     assembledStart = null;
     compiledStart  = null;
     elementReplacedDefs.Clear();
     includedUris.Clear();
     parentGrammar = null;
     refPatterns.Clear();
     checkedDefs.Clear();
     unresolvedPatterns.Clear();
     ElementDefMap.Clear();
 }
示例#15
0
		private RdpPattern makeSingle (RelaxngGrammar g)
		{
			// Flatten patterns into RdpGroup. 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++) {
				p = new RdpGroup (p,
					((RelaxngPattern) patterns [i]).Compile (g));
			}
			return p;
		}
示例#16
0
 internal override RdpNameClass Compile(RelaxngGrammar g)
 {
     if (except != null)
     {
         RdpNameClass exc = except.Compile(g);
         if (FindInvalidType(exc, true))
         {
             throw new RelaxngException(except, "anyName except cannot have anyName children.");
         }
         return(new RdpAnyNameExcept(exc));
     }
     else
     {
         return(RdpAnyName.Instance);
     }
 }
示例#17
0
 internal override RdpNameClass Compile(RelaxngGrammar g)
 {
     if (except != null)
     {
         RdpNameClass exc = except.Compile(g);
         if (FindInvalidType(exc, false))
         {
             throw new RelaxngException(except, "nsName except cannot have anyName nor nsName children.");
         }
         return(new RdpNsNameExcept(ns, exc));
     }
     else
     {
         return(new RdpNsName(ns));
     }
 }
示例#18
0
		internal override RdpPattern Compile (RelaxngGrammar grammar)
		{
			grammar.CheckIncludeRecursion (Href);
			grammar.IncludedUris.Add (Href, Href);
			if (grammar.Resolver == null)
				throw new RelaxngException (this, "To compile 'include' element, XmlResolver is required.");
			Uri uri = grammar.Resolver.ResolveUri (BaseUri != String.Empty ? new Uri (BaseUri) : null, Href);
			RelaxngPattern p = ReadExternalResource (grammar, uri, ns);

			p.DataProvider = grammar.Provider;
			RdpPattern ret = p.Compile (grammar);

			grammar.IncludedUris.Remove (Href);

			return ret;

		}
示例#19
0
        internal RdpNameClass Compile(RelaxngGrammar g)
        {
            // Flatten names into RdpGroup. See 4.12.
            if (names.Count == 0)
            {
                return(null);
            }
            RdpNameClass p = ((RelaxngNameClass)names [0]).Compile(g);

            for (int i = 1; i < names.Count; i++)
            {
                p = new RdpNameClassChoice(
                    ((RelaxngNameClass)names [i]).Compile(g),
                    p);
            }
            return(p);
        }
示例#20
0
        internal override RdpNameClass Compile(RelaxngGrammar g)
        {
            // Flatten names into RdpChoice. See 4.12.
            if (names.Count == 0)
            {
                return(null);
            }
            RdpNameClass p = ((RelaxngNameClass)names [0]).Compile(g);

            if (names.Count == 1)
            {
                return(p);
            }

            for (int i = 1; i < names.Count; i++)
            {
                p = new RdpNameClassChoice(p, ((RelaxngNameClass)names [i]).Compile(g));
            }
            return(p);
        }
		public RelaxngPattern ReadExternalResource (RelaxngGrammar grammar, Uri uri, string nsContext)
		{
			XmlTextReader xtr = null;
			RelaxngGrammar g = null;
			try {
				if (grammar.IsSourceCompactSyntax) {
					return RncParser.ParseRnc (new StreamReader ((Stream) grammar.Resolver.GetEntity (uri, null, typeof (Stream))), null, BaseUri, nsContext);
				} else {
					xtr = new XmlTextReader (uri.AbsoluteUri, (Stream) grammar.Resolver.GetEntity (uri, null, typeof (Stream)));
					RelaxngReader r = new RelaxngReader (xtr, nsContext, grammar.Resolver);
					r.MoveToContent ();
					return r.ReadPattern ();
				}
			} catch (Exception ex) { // umm, bad catch though :-(
				throw new RelaxngException (this, String.Format("Could not include grammar {0}: {1}", uri.AbsoluteUri, ex.Message), ex);
			} finally {
				if (xtr != null)
					xtr.Close ();
			}
		}
示例#22
0
        // compile into div
        internal RelaxngDiv Compile(RelaxngGrammar grammar)
        {
            grammar.CheckIncludeRecursion(Href);
            grammar.IncludedUris.Add(Href);
            if (grammar.Resolver == null)
            {
                throw new RelaxngException(this, "To compile 'include' element, XmlResolver is required.");
            }
            Uri baseUri = null;

            try {
                if (BaseUri != null && BaseUri != String.Empty)
                {
                    baseUri = new Uri(BaseUri);
                }
#if PORTABLE
            } catch {
                throw;
            }
#else
            } catch (UriFormatException) {
示例#23
0
		public RelaxngPattern ReadExternalResource (RelaxngGrammar grammar, Uri uri, string nsContext)
		{
			XmlTextReader xtr = null;
			RelaxngGrammar g = null;
			RelaxngPattern p;
			try {
				if (uri.AbsolutePath.EndsWith(".rnc", StringComparison.InvariantCultureIgnoreCase)) {
					p = RncParser.ParseRnc (new StreamReader ((Stream) grammar.Resolver.GetEntity (uri, null, typeof (Stream))), null, uri.AbsoluteUri, nsContext);
				} else {
					xtr = new XmlTextReader (uri.AbsoluteUri, (Stream) grammar.Resolver.GetEntity (uri, null, typeof (Stream)));
					RelaxngReader r = new RelaxngReader (xtr, nsContext, grammar.Resolver);
					r.MoveToContent ();
					p = r.ReadPattern ();
				}
			} catch (Exception ex) { // umm, bad catch though :-(
				throw new RelaxngException (this, String.Format("Could not include grammar {0}: {1}", uri.AbsoluteUri, ex.Message), ex);
			} finally {
				if (xtr != null)
					xtr.Close ();
			}
			p.XmlResolver = grammar.Resolver;
			return p;
		}
示例#24
0
 internal RdpPattern Compile(RelaxngGrammar grammar)
 {
     return(makeSingle(grammar));
 }
示例#25
0
 internal override RdpPattern Compile(RelaxngGrammar grammar)
 {
     return(RdpNotAllowed.Instance);
 }
示例#26
0
		internal override RdpPattern Compile (RelaxngGrammar grammar)
		{
			IsCompiled = true;
			return new RdpChoice (
				makeSingle (grammar), RdpEmpty.Instance);
		}
示例#27
0
		private RelaxngGrammar ReadGrammarPattern ()
		{
			RelaxngGrammar grammar = new RelaxngGrammar ();
			FillLocation (grammar);
			grammar.DefaultNamespace = Reader.GetAttribute ("ns");
			Read ();
			this.readGrammarIncludeContent (grammar.Starts, grammar.Defines, grammar.Divs, grammar.Includes);
			expectEnd ("grammar");

			return grammar;
		}
示例#28
0
        // Compile from this simplified syntax to derivatives.
        internal override RdpPattern Compile(RelaxngGrammar grammar)
        {
            ResetCompileState();

            parentGrammar = grammar;

            // First, process includes and divs. RELAX NG 4.1 - 4.15.
            ArrayList compiledDivs = new ArrayList();

            foreach (RelaxngInclude inc in includes)
            {
                compiledDivs.Add(inc.Compile(this));
            }
            compiledDivs.AddRange(divs);
            foreach (RelaxngDiv div in compiledDivs)
            {
                div.Compile(this);
            }

            // Check constraints. RELAX NG 4.16
            foreach (RelaxngStart start in starts)
            {
                start.Pattern.CheckConstraints();
            }
            foreach (RelaxngDefine define in defs)
            {
                foreach (RelaxngPattern p in define.Patterns)
                {
                    p.CheckConstraints();
                }
            }

            // Assemble combine into the same name defines/start.
            // see RELAX NG 4.17.
            AssembleCombine();

            // 4.18 : <grammar> must have at least one <start>.
            if (assembledStart == null)
            {
                throw new RelaxngException("A grammar elements must contain at least one start element.");
            }
            compiledStart = assembledStart.Compile(this);

            // Assemble all define components into top grammar and
            // return start patterns for descendant grammars.
            // see RELAX NG 4.18.
            CollectGrammars();
            if (parentGrammar != null)
            {
                return(compiledStart);
            }
            assembledStart = null; // no use anymore

            // 4.19 (a) remove non-reachable defines

            /*
             *                      compiledStart.MarkReachableDefs ();
             *                      ArrayList tmp = new ArrayList ();
             *                      foreach (DictionaryEntry entry in this.assembledDefs)
             *                              if (!reachableDefines.ContainsKey (entry.Key))
             *                                      tmp.Add (entry.Key);
             *                      foreach (string key in tmp)
             *                              assembledDefs.Remove (key);
             */
            // 4.19 (b) check illegal recursion
            CheckRecursion(compiledStart, 0);
            // here we collected element-replaced definitions
            foreach (DictionaryEntry entry in elementReplacedDefs)
            {
                assembledDefs.Add(entry.Key, entry.Value);
            }
            startPattern = compiledStart;
            // 4.20,21 reduce notAllowed and empty.
            bool b;

            do
            {
                b            = false;
                startPattern = startPattern.ReduceEmptyAndNotAllowed(ref b, new Hashtable());
            }while (b);

            Hashtable ht = new Hashtable();

            startPattern.setInternTable(ht);

            // Check Constraints: RELAX NG spec 7
            // 7.1.1-4, 7.3, 7.4
            startPattern.CheckConstraints(false, false, false, false, false, false);
            // 7.1.5
            CheckStartPatternContent(startPattern);

            // 4.19 (c) expandRef - actual replacement
            startPattern = compiledStart.ExpandRef(assembledDefs);

            // 7.2
            RdpContentType ct = startPattern.ContentType;

            // return its start pattern.
            IsCompiled = true;
            return(startPattern);
        }
示例#29
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;
		}
示例#30
0
		internal RdpPattern Compile (RelaxngGrammar grammar)
		{
			return makeSingle (grammar);
		}
示例#31
0
		internal abstract RdpNameClass Compile (RelaxngGrammar g);
示例#32
0
		internal override RdpPattern Compile (RelaxngGrammar grammar)
		{
			return RdpNotAllowed.Instance;
		}
示例#33
0
		internal override RdpPattern Compile (RelaxngGrammar grammar)
		{
			return RdpText.Instance;
		}
示例#34
0
		internal abstract RdpPattern Compile (RelaxngGrammar grammar);
示例#35
0
		public void Compile ()
		{
			RelaxngGrammar g = null;
			if (this is RelaxngGrammar)
				g = (RelaxngGrammar) this;
			else {
				g = new RelaxngGrammar ();
				g.XmlResolver = this.Resolver;
				g.BaseUri = this.BaseUri;
				g.LineNumber = this.LineNumber;
				g.LinePosition = this.LinePosition;
				RelaxngStart st = new RelaxngStart ();
				st.BaseUri = this.BaseUri;
				st.LineNumber = this.LineNumber;
				st.LinePosition = this.LinePosition;
				st.Pattern = this;
				g.Starts.Add (st);
				g.Provider = provider;
			}
			startRelaxngPattern = g.Compile (null);
			this.IsCompiled = true;
		}
示例#36
0
		internal void Compile (RelaxngGrammar grammar)
		{
			foreach (RelaxngDiv div in divs)
				div.Compile (grammar);
			foreach (RelaxngInclude inc in includes)
				inc.Compile (grammar).Compile (grammar); // compile compiled divs
			foreach (RelaxngStart start in starts)
				grammar.Starts.Add (start);
			foreach (RelaxngDefine define in defines)
				grammar.Defines.Add (define);
		}
示例#37
0
		internal override RdpNameClass Compile (RelaxngGrammar g)
		{
			if (except != null) {
				RdpNameClass exc = except.Compile (g);
				if (FindInvalidType (exc, false))
					throw new RelaxngException (except, "nsName except cannot have anyName nor nsName children.");
				return new RdpNsNameExcept (ns, exc);
			} else {
				return new RdpNsName (ns);
			}
		}
示例#38
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));
		}
示例#39
0
		internal override RdpNameClass Compile (RelaxngGrammar g)
		{
			// Flatten names into RdpChoice. See 4.12.
			if (names.Count == 0)
				return null;
			RdpNameClass p = ((RelaxngNameClass) names [0]).Compile (g);
			if (names.Count == 1)
				return p;

			for (int i=1; i<names.Count; i++)
				p = new RdpNameClassChoice (p, ((RelaxngNameClass) names [i]).Compile (g));
			return p;
		}
示例#40
0
		internal override RdpPattern Compile (RelaxngGrammar grammar)
		{
			IsCompiled = true;
			return new RdpValue (new RdpDatatype (DatatypeLibrary,
				Type, null, grammar.Provider), value);
		}
示例#41
0
		// compile into div
		internal RelaxngDiv Compile (RelaxngGrammar grammar)
		{
			grammar.CheckIncludeRecursion (Href);
			grammar.IncludedUris.Add (Href, Href);
			if (grammar.Resolver == null)
				throw new RelaxngException (this, "To compile 'include' element, XmlResolver is required.");
			Uri baseUri = null;
			try {
				if (BaseUri != null && BaseUri != String.Empty)
					baseUri = new Uri (BaseUri);
			} catch (UriFormatException) {
				if (File.Exists (BaseUri))
					baseUri = new Uri (Path.GetFullPath (BaseUri));
			}
			Uri uri = grammar.Resolver.ResolveUri (baseUri, Href);

			RelaxngGrammar g = ReadExternalResource (grammar, uri, (ns != null && ns.Length != 0) || !grammar.IsSourceCompactSyntax ? ns : grammar.DefaultNamespace) as RelaxngGrammar;
			if (g == null)
				throw new RelaxngException (this, "Included syntax must start with \"grammar\" element.");
			g.DataProvider = grammar.Provider;
			g.IsSourceCompactSyntax = grammar.IsSourceCompactSyntax;

			// process recursive inclusions.
			foreach (RelaxngInclude inc in g.Includes)
				g.Divs.Add (inc.Compile (grammar));

			// process this own div children.
			// each div subelements are also compiled.
			foreach (RelaxngDiv cdiv in divs)
				cdiv.Compile (g);
			foreach (RelaxngDiv cdiv in g.Divs)
				cdiv.Compile (g);

			// replace redifinitions into div.
			// starts.
			if (this.Starts.Count > 0 && g.Starts.Count == 0)
				throw new RelaxngException (this, "When the included grammar does not contain start components, this include component must not contain start components.");
			RelaxngGrammarContentList appliedStarts = (this.starts.Count > 0) ?
				this.starts : g.Starts;

			RelaxngDiv div = new RelaxngDiv ();
			div.BaseUri = this.BaseUri;
			div.LinePosition = this.LinePosition;
			div.LineNumber = this.LineNumber;

			foreach (RelaxngStart start in appliedStarts)
				div.Starts.Add (start);

			// defines.
			Hashtable overrides = new Hashtable ();
			Hashtable originalDefs = new Hashtable ();
			foreach (RelaxngDefine def in defines) {
				overrides.Add (def.Name, def.Name);
				div.Defines.Add (def);
			}
			foreach (RelaxngDefine def in g.Defines) {
				originalDefs [def.Name] = def.Name;
				if (!overrides.ContainsKey (def.Name)) {
					div.Defines.Add (def);
				}
				// else discard.
			}

			foreach (string name in overrides.Values)
				if (!originalDefs.ContainsKey (name))
					throw new RelaxngException (this, "The include component must not contain define components whose name does not appear in the included grammar component.");

			grammar.IncludedUris.Remove (Href);
			return div;
		}
示例#42
0
		internal override RdpPattern Compile (RelaxngGrammar grammar)
		{

			IsCompiled = true;
			return new RdpList (makeSingle (grammar));
		}
示例#43
0
        // 4.19 (b)
        private void CheckRecursion(RdpPattern p, int depth)
        {
            RdpAbstractBinary binary = p as RdpAbstractBinary;

            if (binary != null)
            {
                // choice, interleave, group
                CheckRecursion(binary.LValue, depth);
                CheckRecursion(binary.RValue, depth);
                return;
            }
            RdpAbstractSingleContent single = p as RdpAbstractSingleContent;

            if (single != null)
            {
                CheckRecursion(single.Child, depth);
                return;
            }

            switch (p.PatternType)
            {
            case RelaxngPatternType.Ref:
                // get checkRecursionDepth from table.
                int    checkRecursionDepth = -1;
                object checkedDepth        = checkedDefs [p];
                if (checkedDepth != null)
                {
                    checkRecursionDepth = (int)checkedDepth;
                }
                // get refPattern
                RdpUnresolvedRef pref       = p as RdpUnresolvedRef;
                RelaxngGrammar   target     = pref.TargetGrammar;
                RdpPattern       refPattern = pref.RefPattern;
                if (refPattern == null)
                {
                    // FIXME: fill line info
                    throw new RelaxngException("No matching define found for " + pref.Name);
                }

                if (checkRecursionDepth == -1)
                {
                    checkedDefs [p] = depth;
                    /*test*/
                    if (refPattern.PatternType != RelaxngPatternType.Element)
                    {
                        CheckRecursion(refPattern, depth);
                    }
                    checkedDefs [p] = -2;
                }
                else if (depth == checkRecursionDepth)
                {
                    // FIXME: fill line info
                    throw new RelaxngException(String.Format("Detected illegal recursion. Ref name is {0}.", pref.Name));
                }

                break;

            case RelaxngPatternType.Attribute:
                CheckRecursion(((RdpAttribute)p).Children, depth);
                break;

            case RelaxngPatternType.DataExcept:
                CheckRecursion(((RdpDataExcept)p).Except, depth);
                break;

            case RelaxngPatternType.Element:
                RdpElement el = p as RdpElement;
                CheckRecursion(el.Children, depth + 1); // +1
                break;

            case RelaxngPatternType.List:
                CheckRecursion(((RdpList)p).Child, depth);
                break;
            }
        }
示例#44
0
		internal override RdpPattern Compile (RelaxngGrammar grammar)
		{
			return new RdpElement (
				nc.Compile (grammar), this.makeSingle (grammar));
		}
示例#45
0
        // remove ref and parentRef.
        // add new defines for each elements.
        private void CheckReferences(RdpPattern p)
        {
            RdpAbstractBinary binary = p as RdpAbstractBinary;

            if (binary != null)
            {
                // choice, interleave, group
                CheckReferences(binary.LValue);
                CheckReferences(binary.RValue);
                return;
            }
            RdpAbstractSingleContent single = p as RdpAbstractSingleContent;

            if (single != null)
            {
                CheckReferences(single.Child);
                return;
            }

            switch (p.PatternType)
            {
            case RelaxngPatternType.Ref:
                // FIXME: This should not re-expand ref
                RdpUnresolvedRef pref = p as RdpUnresolvedRef;
                if (pref.RefPattern != null)
                {
                    break;
                }

                RelaxngGrammar target = pref.TargetGrammar;
                if (target == null)
                {
                    // FIXME: fill line info
                    throw new RelaxngException("Referenced definition was not found.");
                }
                RdpPattern defP = target.assembledDefs [pref.Name] as RdpPattern;
                if (defP == null)
                {
                    target.unresolvedPatterns.Add(p);
                }
                else
                {
                    ArrayList al = target.refPatterns [defP] as ArrayList;
                    if (al == null)
                    {
                        al = new ArrayList();
                        target.refPatterns [defP] = al;
                    }
                    al.Add(p);
                    pref.RefPattern = defP;
                }
                break;

            case RelaxngPatternType.Attribute:
                CheckReferences(((RdpAttribute)p).Children);
                break;

            case RelaxngPatternType.DataExcept:
                CheckReferences(((RdpDataExcept)p).Except);
                break;

            case RelaxngPatternType.Element:
                RdpElement el = p as RdpElement;
                CheckReferences(el.Children);
                string name = ElementDefMap [el] as string;
                if (name == null)
                {
                    // add new define
                    int    idx     = 0;
                    string newName = "element0";
                    if (el.NameClass is RdpName)
                    {
                        newName = ((RdpName)el.NameClass).LocalName;
                    }
                    while (true)
                    {
                        if (assembledDefs [newName] == null)
                        {
                            elementReplacedDefs [newName] = el.Children;
                            break;
                        }
                        newName = "element" + ++idx;
                    }
                    ElementDefMap [el] = newName;
                }
                // Even though the element is replaced with ref,
                // derivative of ref is RdpElement in fact...
                break;

            case RelaxngPatternType.List:
                CheckReferences(((RdpList)p).Child);
                break;

            case RelaxngPatternType.Empty:
            case RelaxngPatternType.NotAllowed:
            case RelaxngPatternType.Text:
            case RelaxngPatternType.Value:
                break;

                //case RelaxngPatternType.ExternalRef:
                //case RelaxngPatternType.Include:
                // Mixed, Optional, ZeroOrMore are already removed.
                // Choice, Group, Interleave, OneOrMore are already proceeded.
            }
        }
示例#46
0
		internal RdpPattern Compile (RelaxngGrammar grammar)
		{
			return p.Compile (grammar);
		}
示例#47
0
 internal override RdpPattern Compile(RelaxngGrammar grammar)
 {
     IsCompiled = true;
     return(new RdpValue(new RdpDatatype(DatatypeLibrary,
                                         Type, null, grammar.Provider), value));
 }
示例#48
0
		internal RdpParam Compile (RelaxngGrammar grammar)
		{
			IsCompiled = true;
			return new RdpParam (name, value);
		}
示例#49
0
 internal RdpPattern Compile(RelaxngGrammar grammar)
 {
     return(p.Compile(grammar));
 }
示例#50
0
 internal override RdpNameClass Compile(RelaxngGrammar g)
 {
     return(new RdpName(ncname, ns));
 }
示例#51
0
 internal override RdpPattern Compile(RelaxngGrammar grammar)
 {
     return(RdpText.Instance);
 }
示例#52
0
		internal override RdpPattern Compile (RelaxngGrammar grammar)
		{
			IsCompiled = true;
			return makeBinary (grammar);
		}
示例#53
0
		internal override RdpNameClass Compile (RelaxngGrammar g)
		{
			if (except != null) {
				RdpNameClass exc = except.Compile (g);
				if (FindInvalidType (exc, true))
					throw new RelaxngException (except, "anyName except cannot have anyName children.");
				return new RdpAnyNameExcept (exc);
			} else
				return RdpAnyName.Instance;
		}
示例#54
0
		internal override RdpPattern Compile (RelaxngGrammar grammar)
		{
			IsCompiled = true;
			return new RdpInterleave (makeSingle (grammar), RdpText.Instance);
		}
示例#55
0
		internal override RdpNameClass Compile (RelaxngGrammar g)
		{
			return new RdpName (ncname, ns);
		}
示例#56
0
 internal abstract RdpNameClass Compile(RelaxngGrammar g);
示例#57
0
		internal RdpNameClass Compile (RelaxngGrammar g)
		{
			// Flatten names into RdpGroup. See 4.12.
			if (names.Count == 0)
				return null;
			RdpNameClass p = ((RelaxngNameClass) names [0]).Compile (g);
			for (int i=1; i<names.Count; i++) {
				p = new RdpNameClassChoice (
					((RelaxngNameClass) names [i]).Compile (g),
					p);
			}
			return p;
		}
示例#58
0
文件: dtd2rng.cs 项目: nobled/mono
		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;
		}
示例#59
0
 public RelaxngValidatingReader(XmlReader reader, XmlReader grammarXml, RelaxngDatatypeProvider provider)
     : this(reader, RelaxngGrammar.Read(grammarXml, provider))
 {
 }
示例#60
0
		private RdpPattern makeSingle (RelaxngGrammar g)
		{
			// Flatten patterns into RdpGroup. 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++) {
				p = new RdpGroup (p,
					((RelaxngPattern) patterns [i]).Compile (g));
			}
			return p;
		}