Author: atsushi
Date: 2006-04-18 02:27:08 -0400 (Tue, 18 Apr 2006)
New Revision: 59575

Modified:
   trunk/mcs/class/Commons.Xml.Relaxng/Commons.Xml.Nvdl/ChangeLog
   trunk/mcs/class/Commons.Xml.Relaxng/Commons.Xml.Nvdl/NvdlSimplified.cs
   trunk/mcs/class/Commons.Xml.Relaxng/Commons.Xml.Nvdl/NvdlValidator.cs
Log:
2006-04-18  Atsushi Enomoto <[EMAIL PROTECTED]>

        * NvdlSimplified.cs, NvdlValidator.cs :
          fixed several context path related bugs.
          - Path steps must be trimmed.
          - MatchPath() always returned false.
          - nested mode in context is always ignored.



Modified: trunk/mcs/class/Commons.Xml.Relaxng/Commons.Xml.Nvdl/ChangeLog
===================================================================
--- trunk/mcs/class/Commons.Xml.Relaxng/Commons.Xml.Nvdl/ChangeLog      
2006-04-18 04:50:35 UTC (rev 59574)
+++ trunk/mcs/class/Commons.Xml.Relaxng/Commons.Xml.Nvdl/ChangeLog      
2006-04-18 06:27:08 UTC (rev 59575)
@@ -1,3 +1,11 @@
+2006-04-18  Atsushi Enomoto <[EMAIL PROTECTED]>
+
+       * NvdlSimplified.cs, NvdlValidator.cs :
+         fixed several context path related bugs.
+         - Path steps must be trimmed.
+         - MatchPath() always returned false.
+         - nested mode in context is always ignored.
+
 2006-04-11  Atsushi Enomoto <[EMAIL PROTECTED]>
 
        * NvdlRelaxngSupport.cs : without ReportDetails RELAX NG support

Modified: trunk/mcs/class/Commons.Xml.Relaxng/Commons.Xml.Nvdl/NvdlSimplified.cs
===================================================================
--- trunk/mcs/class/Commons.Xml.Relaxng/Commons.Xml.Nvdl/NvdlSimplified.cs      
2006-04-18 04:50:35 UTC (rev 59574)
+++ trunk/mcs/class/Commons.Xml.Relaxng/Commons.Xml.Nvdl/NvdlSimplified.cs      
2006-04-18 06:27:08 UTC (rev 59575)
@@ -683,12 +683,14 @@
 
        internal class SimpleContext : SimplifiedItem
        {
+               readonly NvdlContext source;
                readonly string useModeName; // It is never used in validation.
                SimpleMode useMode;
                SimplePath [] path;
 
                public SimpleContext (NvdlContext context)
                {
+                       source = context;
                        FillLocation (context);
 
                        this.useModeName = context.UseMode;
@@ -701,7 +703,7 @@
                                                Nvdl.Whitespaces);
                                        if (spath.Length == 0)
                                                continue;
-                                       ParsePath (al, spath);
+                                       ParsePath (al, TrimName (spath));
                                }
                                path = (SimplePath []) al.ToArray (
                                        typeof (SimplePath));
@@ -713,25 +715,28 @@
                private void ParsePath (ArrayList al, string path)
                {
                        ArrayList steps = new ArrayList ();
-                       int start = 0;
+                       int start = path.Length > 0 && path [0] == '/' ? 1 : 0;
                        do {
                                int idx = path.IndexOf ('/', start);
                                if (idx < 0) {
-                                       steps.Add (new SimplePathStep 
(path.Substring (start), false));
+                                       steps.Add (new SimplePathStep (TrimName 
(path.Substring (start)), false));
                                        start = path.Length;
-                               }
-                               else if (path.Length > idx + 1 && path [idx + 
1] == '/') {
-                                       steps.Add (new SimplePathStep 
(path.Substring (start, idx - start), true));
+                               } else if (path.Length > idx + 1 && path [idx + 
1] == '/') {
+                                       steps.Add (new SimplePathStep (TrimName 
(path.Substring (start, idx - start)), true));
                                        start = idx + 2;
                                } else {
-                                       steps.Add (new SimplePathStep 
(path.Substring (start, idx - start), false));
+                                       steps.Add (new SimplePathStep (TrimName 
(path.Substring (start, idx - start)), false));
                                        start = idx + 1;
                                }
-                               
                        } while (start < path.Length);
                        al.Add (new SimplePath (steps.ToArray (typeof 
(SimplePathStep)) as SimplePathStep []));
                }
 
+               string TrimName (string src)
+               {
+                       return src.TrimStart (Nvdl.Whitespaces).TrimEnd 
(Nvdl.Whitespaces);
+               }
+
                internal SimplePath [] Path {
                        get { return path; }
                }
@@ -744,6 +749,8 @@
                {
                        if (useModeName != null)
                                useMode = ctx.GetCompiledMode (useModeName);
+                       else if (source.NestedMode != null)
+                               useMode = ctx.GetCompiledMode (source);
                        else
                                useMode = current;
 

Modified: trunk/mcs/class/Commons.Xml.Relaxng/Commons.Xml.Nvdl/NvdlValidator.cs
===================================================================
--- trunk/mcs/class/Commons.Xml.Relaxng/Commons.Xml.Nvdl/NvdlValidator.cs       
2006-04-18 04:50:35 UTC (rev 59574)
+++ trunk/mcs/class/Commons.Xml.Relaxng/Commons.Xml.Nvdl/NvdlValidator.cs       
2006-04-18 06:27:08 UTC (rev 59575)
@@ -110,7 +110,7 @@
                        } else {
                                foreach (NvdlInterpretation pi in
                                        parentState.ilist) {
-                                       PopulateInterp (dispatcher, pi);
+                                       PopulateInterp (dispatcher, pi, 
parentState);
                                }
                        }
 
@@ -134,9 +134,10 @@
                }
 
                private void PopulateInterp (
-                       NvdlDispatcher d, NvdlInterpretation i)
+                       NvdlDispatcher d, NvdlInterpretation i,
+                       NvdlSection parentState)
                {
-                       SimpleMode m = FindContextMode (i.Action);
+                       SimpleMode m = FindContextMode (i.Action, parentState);
                        SimpleRule rule = FindElementRule (m, 
dispatcher.Reader);
 NvdlDebug.Writer.WriteLine ("***** populate interp from action {0} whose mode 
is {1}. Rule is {2} whose actions are {3}", i.Action.Location, m.Location, 
rule.Location, rule.Actions.Length);
                        foreach (SimpleAction a in rule.Actions) {
@@ -152,33 +153,43 @@
                        }
                }
 
-               private SimpleMode FindContextMode (SimpleAction a)
+               private SimpleMode FindContextMode (SimpleAction a, NvdlSection 
parentState)
                {
                        if (a.Contexts != null)
                                foreach (SimpleContext ctx in a.Contexts)
                                        foreach (SimplePath path in ctx.Path)
-                                               if (MatchPath (path))
+                                               if (MatchPath (path, 
parentState)) {
+NvdlDebug.Writer.WriteLine ("------ matched context at {0}.", ctx.Location);
                                                        return ctx.UseMode;
+}
                        return a.DefaultMode;
                }
 
-               private bool MatchPath (SimplePath path)
+               private bool MatchPath (SimplePath path, NvdlSection 
parentState)
                {
-                       int elemStep = elementNameStack.Count - 1;
-                       for (int i = path.Steps.Length; i >= 0 && elemStep >= 
0;) {
+                       ArrayList stack = parentState.elementNameStack;
+                       if (stack.Count == 0)
+                               return false;
+                       int elemStep = stack.Count - 1;
+                       for (int i = path.Steps.Length - 1; i >= 0 && elemStep 
>= 0;) {
                                SimplePathStep ps = path.Steps [i];
-                               if (ps.Name != elementNameStack [elemStep] as 
string) {
+                               if (ps.Name != stack [elemStep] as string) {
+                                       // reject a/b while allow a//b
                                        if (!ps.Descendants)
                                                return false;
-                                       if (--elemStep < 0)
-                                               return false;
+                                       --elemStep;
                                }
                                else {
                                        i--;
                                        elemStep--;
                                }
                        }
-                       return false;
+NvdlDebug.Writer.Write ("------ matched path: ");
+for (int i = 0; i < stack.Count; i++) NvdlDebug.Writer.Write ('[' + (string) 
stack [i] + ']');
+NvdlDebug.Writer.Write (" -> ");
+for (int i = 0; i < path.Steps.Length; i++) NvdlDebug.Writer.Write ('[' + 
path.Steps [i].Name + ']');
+NvdlDebug.Writer.WriteLine ();
+                       return true;
                }
 
                public NvdlDispatcher Dispatcher {

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to