2007-12-27 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Thu, 27 Dec 2007 09:55:13 +0000 (09:55 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Thu, 27 Dec 2007 09:55:13 +0000 (09:55 -0000)
* RncParser.jay, RncTokenizer.cs : some changes to fill element
  locations in *.rnc. To make it possible, added some overrides to
  pass BaseUri to Parse() and ParseRnc().
  Allow null nameTable (just create a new instance).

* RelaxngPattern.cs : (RelaxngInclude) when a relative Uri is
  specified as its BaseUri, make it into an absolute path and
  then resolve the URI.

* NvdlRelaxngSupport.cs : pass baseUri to RncParser.

* xmltool.cs : use absolute path as the base uri for *.rnc.

svn path=/trunk/mcs/; revision=91923

mcs/class/Commons.Xml.Relaxng/Commons.Xml.Nvdl/ChangeLog
mcs/class/Commons.Xml.Relaxng/Commons.Xml.Nvdl/NvdlRelaxngSupport.cs
mcs/class/Commons.Xml.Relaxng/Commons.Xml.Relaxng.Rnc/ChangeLog
mcs/class/Commons.Xml.Relaxng/Commons.Xml.Relaxng.Rnc/RncParser.jay
mcs/class/Commons.Xml.Relaxng/Commons.Xml.Relaxng.Rnc/RncTokenizer.cs
mcs/class/Commons.Xml.Relaxng/Commons.Xml.Relaxng/ChangeLog
mcs/class/Commons.Xml.Relaxng/Commons.Xml.Relaxng/RelaxngPattern.cs
mcs/tools/mono-xmltool/ChangeLog
mcs/tools/mono-xmltool/xmltool.cs

index 4b520d130d67bbc0701df38a0bff178e816d92e2..014161df10069200217f2e7e755799df0ea33406 100644 (file)
@@ -1,3 +1,7 @@
+2007-12-27  Atsushi Enomoto <atsushi@ximian.com>
+
+       * NvdlRelaxngSupport.cs : pass baseUri to RncParser.
+
 2006-04-19  Atsushi Enomoto <atsushi@ximian.com>
 
        * NvdlFilteredXmlReader.cs :
index cda6af0bc3a64555b6cb7ceb9f95ed28b9f7a562..db04fe903a45183341b26df3e993552860e5f772 100644 (file)
@@ -27,11 +27,12 @@ namespace Commons.Xml.Nvdl
                        if (schemaUri == null)
                                return null;
                        Uri baseUri = resolver.ResolveUri (null, validate.SourceUri);
+                       Uri absUri = resolver.ResolveUri (baseUri, schemaUri);
                        RelaxngPattern p = RncParser.ParseRnc (
                                new StreamReader ((Stream) resolver.GetEntity (
-                                       resolver.ResolveUri (baseUri, schemaUri),
+                                       absUri,
                                        null,
-                                       typeof (Stream))));
+                                       typeof (Stream))), null, absUri.ToString ());
                        return new NvdlRelaxngValidatorGenerator (p, config);
                }
 
index 7fe4af06ba85260331caaf229412765677e44536..dc4cf015fa9686e535d008aedb00ea9e684f4e01 100644 (file)
@@ -1,3 +1,10 @@
+2007-12-27  Atsushi Enomoto <atsushi@ximian.com>
+
+       * RncParser.jay, RncTokenizer.cs : some changes to fill element
+         locations in *.rnc. To make it possible, added some overrides to
+         pass BaseUri to Parse() and ParseRnc().
+         Allow null nameTable (just create a new instance).
+
 2007-12-17  Atsushi Enomoto <atsushi@ximian.com>
 
        * RncParser.jay : if the parsed pattern is grammar, set
index 8e02d302ee7a05ae4e2d6b516c72f4db0f715cae..1574c95920857e105f3c91b9c2f492abd33a1a65 100644 (file)
@@ -51,7 +51,12 @@ namespace Commons.Xml.Relaxng.Rnc
 
                public static RelaxngPattern ParseRnc (TextReader reader, XmlNameTable nameTable)
                {
-                       return new RncParser (nameTable).Parse (reader);
+                       return ParseRnc (reader, nameTable, null);
+               }
+
+               public static RelaxngPattern ParseRnc (TextReader reader, XmlNameTable nameTable, string baseUri)
+               {
+                       return new RncParser (nameTable).Parse (reader, baseUri);
                }
 
                XmlNamespaceManager nsmgr;
@@ -63,6 +68,8 @@ namespace Commons.Xml.Relaxng.Rnc
 
                public RncParser (XmlNameTable nameTable)
                {
+                       if (nameTable == null)
+                               nameTable = new NameTable ();
                        nsmgr = new XmlNamespaceManager (nameTable);
                        dtnsmgr = new XmlNamespaceManager (nameTable);
                        dtnsmgr.AddNamespace ("xsd", "http://www.w3.org/2001/XMLSchema-datatypes");
@@ -77,17 +84,26 @@ namespace Commons.Xml.Relaxng.Rnc
                        get { return tokenizer.Column; }
                }
 
+               public string BaseUri {
+                       get { return tokenizer.BaseUri; }
+               }
+
                // note that this is different notion than that of xmlns.
                public string DefaultNamespace {
                        get { return defaultNamespace; }
                }
 
                public RelaxngPattern Parse (TextReader source)
+               {
+                       return Parse (source, null);
+               }
+
+               public RelaxngPattern Parse (TextReader source, string baseUri)
                {
                        try {
                                if (Environment.GetEnvironmentVariable ("MONO_RELAXNG_COMPACT_DEBUG") == "yes")
                                        debug = new yydebug.yyDebugSimple ();
-                               tokenizer = new RncTokenizer (source);
+                               tokenizer = new RncTokenizer (source, baseUri);
                                RelaxngPattern p = (RelaxngPattern) yyparse (tokenizer);
                                if (p is RelaxngGrammar)
                                        ((RelaxngGrammar) p).IsSourceCompactSyntax = true;
@@ -97,6 +113,12 @@ namespace Commons.Xml.Relaxng.Rnc
                        }\r
                }
 
+               private void FillLocation (RelaxngElementBase el)
+               {
+                       el.BaseUri = BaseUri;
+                       el.LineNumber = Line;
+                       el.LinePosition = Column;
+               }
 
                private void FillGrammarContent (IList source, IList starts, IList defines, IList divs, IList includes)
                {
@@ -309,6 +331,7 @@ TopLevelBody /* returns RelaxngPattern */
        | Grammar
        {
                RelaxngGrammar g = new RelaxngGrammar ();
+               FillLocation (g);
                if (nsmgr.DefaultNamespace != String.Empty)
                        g.DefaultNamespace = nsmgr.DefaultNamespace;
                RelaxngGrammarContentList list = (RelaxngGrammarContentList) $1;
@@ -373,6 +396,7 @@ Start /* returns RelaxngStart */
        : KeywordStart AssignOp Pattern
        {
                RelaxngStart start = new RelaxngStart ();
+               FillLocation (start);
                start.Combine = (string) $2;
                start.Pattern = (RelaxngPattern) $3;
                $$ = start;
@@ -383,6 +407,7 @@ Define /* returns RelaxngDefine */
        : Identifier AssignOp Pattern
        {
                RelaxngDefine def = new RelaxngDefine ();
+               FillLocation (def);
                def.Name = (string) $1;
                def.Combine = (string) $2;
                def.Patterns.Add ((RelaxngPattern) $3);
@@ -410,6 +435,7 @@ Include /* returns RelaxngInclude */
        {
                // FIXME: OptInherit is not handled properly.
                RelaxngInclude include = new RelaxngInclude ();
+               FillLocation (include);
                include.Href = (string) $2;
                include.NSContext = (string) $3;
                FillGrammarContent ((IList) $4, include.Starts, include.Defines, include.Divs, null);
@@ -501,6 +527,7 @@ Div /* returns RelaxngDiv */
        : KeywordDiv OpenCurly Grammar CloseCurly
        {
                RelaxngDiv div = new RelaxngDiv ();
+               FillLocation (div);
                FillGrammarContent ((IList) $3, div.Starts, div.Defines, div.Divs, div.Includes);
                $$ = div;
        }
@@ -510,6 +537,7 @@ IncludeDiv /* returns RelaxngDiv */
        : KeywordDiv OpenCurly IncludeBody CloseCurly
        {
                RelaxngDiv div = new RelaxngDiv ();
+               FillLocation (div);
                FillGrammarContent ((IList) $3, div.Starts, div.Defines, div.Divs, div.Includes);
                $$ = div;
        }
@@ -529,6 +557,7 @@ InnerPattern /* returns RelaxngPattern */
        {
                RelaxngPatternList list = (RelaxngPatternList) $1;
                RelaxngChoice choice = new RelaxngChoice ();
+               FillLocation (choice);
                for (int i = 0; i < list.Count; i++)
                        choice.Patterns.Add (list [i]);
                // This is said as to return Elements, while ApplyAnnotations() is said to return Element
@@ -538,6 +567,7 @@ InnerPattern /* returns RelaxngPattern */
        {
                RelaxngPatternList list = (RelaxngPatternList) $1;
                RelaxngGroup group = new RelaxngGroup ();
+               FillLocation (group);
                for (int i = 0; i < list.Count; i++)
                        group.Patterns.Add (list [i]);
                // This is said as to return Elements, while ApplyAnnotations() is said to return Element
@@ -547,6 +577,7 @@ InnerPattern /* returns RelaxngPattern */
        {
                RelaxngPatternList list = (RelaxngPatternList) $1;
                RelaxngInterleave interleave = new RelaxngInterleave ();
+               FillLocation (interleave);
                for (int i = 0; i < list.Count; i++)
                        interleave.Patterns.Add (list [i]);
                // This is said as to return Elements, while ApplyAnnotations() is said to return Element
@@ -631,18 +662,21 @@ RepeatedPrimary /* returns RelaxngPattern */
        : AnnotatedPrimary Asterisk
        {
                RelaxngZeroOrMore zom = new RelaxngZeroOrMore ();
+               FillLocation (zom);
                zom.Patterns.Add ((RelaxngPattern) $1);
                $$ = zom;
        }
        | AnnotatedPrimary Plus
        {
                RelaxngOneOrMore oom = new RelaxngOneOrMore ();
+               FillLocation (oom);
                oom.Patterns.Add ((RelaxngPattern) $1);
                $$ = oom;
        }
        | AnnotatedPrimary Question
        {
                RelaxngOptional opt = new RelaxngOptional ();
+               FillLocation (opt);
                opt.Patterns.Add ((RelaxngPattern) $1);
                $$ = opt;
        }
@@ -692,6 +726,7 @@ Primary /* returns RelaxngPattern */
        {
                RelaxngNameClass nc = (RelaxngNameClass) $2;
                RelaxngElement el = new RelaxngElement ();
+               FillLocation (el);
                el.NameClass = nc;
                FillElementDefaultNS (el.NameClass);
                el.Patterns.Add ((RelaxngPattern) $4);
@@ -702,6 +737,7 @@ Primary /* returns RelaxngPattern */
                RelaxngNameClass nc = (RelaxngNameClass) $2;
 
                RelaxngAttribute attr = new RelaxngAttribute ();
+               FillLocation (attr);
                attr.NameClass = nc;
                FillAttributeDefaultNS (attr.NameClass);
                attr.Pattern = (RelaxngPattern) $4;
@@ -710,18 +746,21 @@ Primary /* returns RelaxngPattern */
        | KeywordMixed OpenCurly Pattern CloseCurly
        {
                RelaxngMixed mixed = new RelaxngMixed ();
+               FillLocation (mixed);
                mixed.Patterns.Add ((RelaxngPattern) $3);
                $$ = mixed;
        }
        | KeywordList OpenCurly Pattern CloseCurly
        {
                RelaxngList list = new RelaxngList ();
+               FillLocation (list);
                list.Patterns.Add ((RelaxngPattern) $3);
                $$ = list;
        }
        | DatatypeName OptParams
        {
                RelaxngData data = new RelaxngData ();
+               FillLocation (data);
                XmlQualifiedName dtName = (XmlQualifiedName) $1;
                data.DatatypeLibrary = dtName.Namespace;
                data.Type = dtName.Name;
@@ -733,6 +772,7 @@ Primary /* returns RelaxngPattern */
        | DatatypeName DatatypeValue
        {
                RelaxngValue value = new RelaxngValue ();
+               FillLocation (value);
                XmlQualifiedName dtName = (XmlQualifiedName) $1;
                if (dtName.Namespace != RelaxngGrammar.NamespaceURI)
                        value.DatatypeLibrary = dtName.Namespace;
@@ -744,6 +784,7 @@ Primary /* returns RelaxngPattern */
        | DatatypeValue
        {
                RelaxngValue value = new RelaxngValue ();
+               FillLocation (value);
                value.Value = (string) $1;
 
                // RELAX NG default type
@@ -754,37 +795,47 @@ Primary /* returns RelaxngPattern */
        }
        | KeywordEmpty
        {
-               $$ = new RelaxngEmpty ();
+               RelaxngEmpty empty = new RelaxngEmpty ();
+               FillLocation (empty);
+               $$ = empty;
        }
        | KeywordNotAllowed
        {
-               $$ = new RelaxngNotAllowed ();
+               RelaxngNotAllowed na = new RelaxngNotAllowed ();
+               FillLocation (na);
+               $$ = na;
        }
        | KeywordText
        {
-               $$ = new RelaxngText ();
+               RelaxngText text = new RelaxngText ();
+               FillLocation (text);
+               $$ = text;
        }
        | Ref
        {
                RelaxngRef r = new RelaxngRef ();
+               FillLocation (r);
                r.Name = (string) $1;
                $$ = r;
        }
        | KeywordParent Ref
        {
                RelaxngParentRef pref = new RelaxngParentRef ();
+               FillLocation (pref);
                pref.Name = (string) $2;
                $$ = pref;
        }
        | KeywordGrammar OpenCurly Grammar CloseCurly
        {
                RelaxngGrammar g = new RelaxngGrammar ();
+               FillLocation (g);
                FillGrammarContent ((IList) $3, g.Starts, g.Defines, g.Divs, g.Includes);
                $$ = g;
        }
        | KeywordExternal AnyURILiteral OptInherit
        {
                RelaxngExternalRef extref = new RelaxngExternalRef ();
+               FillLocation (extref);
                extref.Href = (string) $2;
                extref.NSContext = (string) $3;
                $$ = extref;
@@ -796,11 +847,13 @@ DataExcept /* returns RelaxngData */
        {
                XmlQualifiedName type = (XmlQualifiedName) $1;
                RelaxngData data = new RelaxngData ();
+               FillLocation (data);
                data.Type = type.Name;
                data.DatatypeLibrary = type.Namespace;
                foreach (RelaxngParam p in (RelaxngParamList) $2)
                        data.ParamList.Add (p);
                data.Except = new RelaxngExcept ();
+               FillLocation (data.Except);
                data.Except.Patterns.Add ((RelaxngPattern) $4);
                $$ = data;
        }
@@ -858,6 +911,7 @@ Param /* returns RelaxngParam */
        : Annotations IdentifierOrKeyword Equal Literal
        {
                RelaxngParam prm = new RelaxngParam ();
+               FillLocation (prm);
                prm.Name = (string) $2;
                prm.Value = (string) $4;
 
@@ -881,6 +935,7 @@ InnerNameClass /* returns RelaxngNameClass */
        | NameClassChoice
        {
                RelaxngNameChoice cho = new RelaxngNameChoice ();
+               FillLocation (cho);
                RelaxngNameClassList list = (RelaxngNameClassList) $1;
                for (int i = 0; i < list.Count; i++)
                        cho.Children.Add ((RelaxngNameClass) list [i]);
@@ -946,15 +1001,19 @@ ExceptNameClass
        : NsName Minus LeadAnnotatedSimpleNameClass
        {
                RelaxngNsName nsName = new RelaxngNsName ();
+               FillLocation (nsName);
                nsName.Namespace = nsmgr.LookupNamespace ((string) $1);
                nsName.Except = new RelaxngExceptNameClass ();
+               FillLocation (nsName.Except);
                nsName.Except.Names.Add ((RelaxngNameClass) $3);
                $$ = nsName;
        }
        | Asterisk Minus LeadAnnotatedSimpleNameClass
        {
                RelaxngAnyName anyName = new RelaxngAnyName ();
+               FillLocation (anyName);
                anyName.Except = new RelaxngExceptNameClass ();
+               FillLocation (anyName.Except);
                anyName.Except.Names.Add ((RelaxngNameClass) $3);
                $$ = anyName;
        }
@@ -964,6 +1023,7 @@ SimpleNameClass /* returns RelaxngNameClass */
        : IdentifierOrKeyword
        {
                RelaxngName name = new RelaxngName ();
+               FillLocation (name);
                name.LocalName = (string) $1;
                name.Namespace = null;
                $$ = name;
@@ -973,6 +1033,7 @@ SimpleNameClass /* returns RelaxngNameClass */
                string cname = (string) $1;
                XmlQualifiedName qname = SplitQName (nsmgr, cname);
                RelaxngName name = new RelaxngName ();
+               FillLocation (name);
                name.LocalName = qname.Name;
                name.Namespace = qname.Namespace;
                $$ = name;
@@ -980,12 +1041,15 @@ SimpleNameClass /* returns RelaxngNameClass */
        | NsName
        {
                RelaxngNsName nsName = new RelaxngNsName ();
+               FillLocation (nsName);
                nsName.Namespace = nsmgr.LookupNamespace ((string) $1);
                $$ = nsName;
        }
        | Asterisk
        {
-               $$ = new RelaxngAnyName ();
+               RelaxngAnyName anyName= new RelaxngAnyName ();
+               FillLocation (anyName);
+               $$ = anyName;
        }
        ;
 
index 0d79f5f7115668bc56ac87697575c1346b17c901..7908f696a955d2a3a48b192e38d440c6fdb54ab7 100644 (file)
@@ -53,10 +53,12 @@ namespace Commons.Xml.Relaxng.Rnc
                int savedLineNumber = 1;\r
                int savedLinePosition;\r
                bool nextIncrementLine;\r
+               string baseUri;\r
 \r
-               public RncTokenizer (TextReader source)\r
+               public RncTokenizer (TextReader source, string baseUri)\r
                {\r
                        this.source = source;\r
+                       this.baseUri = baseUri;\r
                }\r
 \r
                public bool IsElement {\r
@@ -71,6 +73,10 @@ namespace Commons.Xml.Relaxng.Rnc
                        get { return savedLinePosition; }\r
                }\r
 \r
+               public string BaseUri {\r
+                       get { return baseUri; }\r
+               }\r
+\r
                // jay interface implementation\r
 \r
                public int token ()\r
index b72c47bd381419a34858af3b601f74e71724bdc8..b1002694b1ec0177512309e9115e7be4c9b1b8ae 100644 (file)
@@ -1,3 +1,9 @@
+2007-12-27  Atsushi Enomoto <atsushi@ximian.com>
+
+       * RelaxngPattern.cs : (RelaxngInclude) when a relative Uri is
+         specified as its BaseUri, make it into an absolute path and
+         then resolve the URI.
+
 2007-12-17  Atsushi Enomoto <atsushi@ximian.com>
 
        * RelaxngPattern.cs : (RelaxngInclude) when it is constructed from
index 8dfa8cfb1fd2789bd71b5f8c0c6174eb15de7ba4..846e2c6ccd14f34f22b20d663e7831557b9a88ae 100644 (file)
@@ -317,12 +317,20 @@ namespace Commons.Xml.Relaxng
                        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 != null && BaseUri != String.Empty ? new Uri (BaseUri) : null, Href);
+                       Uri baseUri = null;
+                       try {
+                               if (BaseUri != null && BaseUri != String.Empty)
+                                       baseUri = new Uri (BaseUri);
+                       } catch (UriFormatException) {
+                               if (Path.IsPathRooted (BaseUri))
+                                       baseUri = new Uri (Path.GetFullPath (BaseUri));
+                       }
+                       Uri uri = grammar.Resolver.ResolveUri (baseUri, Href);
                        XmlTextReader xtr = null;
                        RelaxngGrammar g = null;
                        try {
                                if (grammar.IsSourceCompactSyntax) {
-                                       g = RncParser.ParseRnc (new StreamReader ((Stream) grammar.Resolver.GetEntity (uri, null, typeof (Stream)))) as RelaxngGrammar;
+                                       g = RncParser.ParseRnc (new StreamReader ((Stream) grammar.Resolver.GetEntity (uri, null, typeof (Stream))), null, BaseUri) as RelaxngGrammar;
                                } else {
                                        xtr = new XmlTextReader (uri.AbsoluteUri, (Stream) grammar.Resolver.GetEntity (uri, null, typeof (Stream)));
                                        RelaxngReader r = new RelaxngReader (xtr, ns, grammar.Resolver);
index cef80fda68b24871eea4d1f0f012b9f7fcab8040..9845262a689bdd63ae98f719866795d5fc22c471 100644 (file)
@@ -1,3 +1,7 @@
+2007-12-27  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * xmltool.cs : use absolute path as the base uri for *.rnc.
+
 2006-11-07  Atsushi Enomoto  <atsushi@ximian.com>
 
        * xmltool.cs : compile schema to validate the schema itself. It is
index 829e1827eddb4f5b9e37c859fe2b238b7778bcb7..72f2af7a0d56c8eeaf1fa4730d1c8a5873d768cd 100644 (file)
@@ -121,7 +121,7 @@ environment variable that affects behavior:
                static void ValidateRelaxngCompact (string [] args)
                {
                        StreamReader sr = new StreamReader (args [1]);
-                       RelaxngPattern p = RncParser.ParseRnc (sr);
+                       RelaxngPattern p = RncParser.ParseRnc (sr, null, Path.GetFullPath (args [1]));
                        sr.Close ();
                        ValidateRelaxng (p, args);
                }