Exemple #1
0
        public NvdlSection Pop()
        {
            NvdlSection ret = this [List.Count - 1];

            List.RemoveAt(List.Count - 1);
            return(ret);
        }
Exemple #2
0
        private void PopulateInterp(
            NvdlDispatcher d, NvdlInterpretation i,
            NvdlSection parentState)
        {
            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)
            {
                NvdlInterpretation cur = i;
                for (; cur != null; cur = cur.Parent)
                {
                    if (cur.CreatedMode == m && cur.Action == a)
                    {
                        NvdlDebug.Writer.WriteLine("------- corresponding PlanElem already exists.");
                        break;
                    }
                }
                if (cur == null)
                {
                    cur = CreateInterp(d, m, a, i);
                }
                ilist.Add(cur);
            }
        }
Exemple #3
0
        private bool MatchPath(SimplePath path, NvdlSection parentState)
        {
            var stack = parentState.elementNameStack.ToArray();

            if (stack.Length == 0)
            {
                return(false);
            }
            int elemStep = stack.Length - 1;

            for (int i = path.Steps.Length - 1; i >= 0 && elemStep >= 0;)
            {
                SimplePathStep ps = path.Steps [i];
                if (ps.Name != stack [elemStep] as string)
                {
                    // reject a/b while allow a//b
                    if (!ps.Descendants)
                    {
                        return(false);
                    }
                    --elemStep;
                }
                else
                {
                    i--;
                    elemStep--;
                }
            }
            return(true);
        }
Exemple #4
0
        public NvdlSection(NvdlDispatcher dispatcher,
                           NvdlSection parentState)
        {
            this.dispatcher = dispatcher;
            this.ns         = dispatcher.Reader.NamespaceURI;

            if (parentState == null)
            {
                foreach (SimpleAction a in FindElementRule(
                             dispatcher.Rules.StartMode,
                             dispatcher.Reader).Actions)
                {
                    ilist.Add(GetInterp(a, dispatcher));
                }
            }
            else
            {
                foreach (NvdlInterpretation pi in
                         parentState.ilist)
                {
                    PopulateInterp(dispatcher, pi, parentState);
                }
            }

            NvdlDebug.Writer.WriteLine("New section: ns {0} / interp.count {1} / loc: {2}", ns, ilist.Count, ((IXmlLineInfo)dispatcher.Reader).LineNumber);
        }
Exemple #5
0
 NvdlSection GetSection(NvdlSection section)
 {
     if (section == null)
     {
         return(new NvdlSection(this, null));
     }
     else if (section.Namespace != Reader.NamespaceURI)
     {
         return(new NvdlSection(this, section));
     }
     else if (qnameStack.Count > 0 && rules.Triggers.Length > 0)
     {
         for (int t = 0; t < rules.Triggers.Length; t++)
         {
             SimpleTrigger    st     = rules.Triggers [t];
             XmlQualifiedName parent =
                 (XmlQualifiedName)qnameStack.Peek();
             if (st.Cover(Reader.LocalName,
                          Reader.NamespaceURI) &&
                 !st.Cover(parent.Name, parent.Namespace))
             {
                 NvdlDebug.Writer.WriteLine("======== triggered by {0}", st.Location);
                 return(new NvdlSection(this, section));
             }
         }
     }
     return(section);
 }
Exemple #6
0
		public void StartElement ()
		{
NvdlDebug.Writer.WriteLine ("  <dispatcher.StartElement {0}. stack depth: {1}. current section ns {2}",
Reader.Name, sectionStack.Count, section == null ? "(none)" : section.Namespace);
			NvdlSection prev = section;
			section = GetSection (section);

			section.StartElement ();
			if (Reader.IsEmptyElement) {
				section.EndSection ();
				section = prev;
			} else {
				sectionStack.Push (section);
				qnameStack.Push (new XmlQualifiedName (Reader.LocalName, Reader.NamespaceURI));
			}
		}
Exemple #7
0
 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, parentState))
                 {
                     return(ctx.UseMode);
                 }
             }
         }
     }
     return(a.DefaultMode);
 }
Exemple #8
0
 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, parentState))
                 {
                     NvdlDebug.Writer.WriteLine("------ matched context at {0}.", ctx.Location);
                     return(ctx.UseMode);
                 }
             }
         }
     }
     return(a.DefaultMode);
 }
Exemple #9
0
        public void StartElement()
        {
            NvdlDebug.Writer.WriteLine("  <dispatcher.StartElement {0}. stack depth: {1}. current section ns {2}",
                                       Reader.Name, sectionStack.Count, section == null ? "(none)" : section.Namespace);
            NvdlSection prev = section;

            section = GetSection(section);

            section.StartElement();
            if (Reader.IsEmptyElement)
            {
                section.EndSection();
                section = prev;
            }
            else
            {
                sectionStack.Push(section);
                qnameStack.Push(new XmlQualifiedName(Reader.LocalName, Reader.NamespaceURI));
            }
        }
Exemple #10
0
        private bool MatchPath(SimplePath path, NvdlSection parentState)
        {
            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 != stack [elemStep] as string)
                {
                    // reject a/b while allow a//b
                    if (!ps.Descendants)
                    {
                        return(false);
                    }
                    --elemStep;
                }
                else
                {
                    i--;
                    elemStep--;
                }
            }
            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);
        }
Exemple #11
0
		NvdlSection GetSection (NvdlSection section)
		{
			if (section == null)
				return new NvdlSection (this, null);
			else if (section.Namespace != Reader.NamespaceURI)
				return new NvdlSection (this, section);
			else if (qnameStack.Count > 0 && rules.Triggers.Length > 0) {
				for (int t = 0; t < rules.Triggers.Length; t++) {
					SimpleTrigger st = rules.Triggers [t];
					XmlQualifiedName parent =
						(XmlQualifiedName) qnameStack.Peek ();
					if (st.Cover (Reader.LocalName,
						      Reader.NamespaceURI) &&
					    !st.Cover (parent.Name, parent.Namespace)) {
NvdlDebug.Writer.WriteLine ("======== triggered by {0}", st.Location);
						return new NvdlSection (this, section);
					}
				}
			}
			return section;
		}
Exemple #12
0
        public void EndElement()
        {
            NvdlDebug.Writer.WriteLine("  <dispatcher.EndElement {0}. depth: {1}",
                                       Reader.Name, sectionStack.Count);
            if (section != null)
            {
                section = sectionStack.Pop();
                section.EndElement();
                section.EndSection();
                if (sectionStack.Count > 0)
                {
                    section = sectionStack.Peek();
                }
                else
                {
                    section = null;
                }
            }

            qnameStack.Pop();
        }
Exemple #13
0
        public NvdlSection(NvdlDispatcher dispatcher,
                           NvdlSection parentState)
        {
            this.dispatcher = dispatcher;
            this.ns         = dispatcher.Reader.NamespaceURI;

            if (parentState == null)
            {
                foreach (SimpleAction a in FindElementRule(
                             dispatcher.Rules.StartMode,
                             dispatcher.Reader).Actions)
                {
                    ilist.Add(GetInterp(a, dispatcher));
                }
            }
            else
            {
                foreach (NvdlInterpretation pi in
                         parentState.ilist)
                {
                    PopulateInterp(dispatcher, pi, parentState);
                }
            }
        }
Exemple #14
0
        private void PopulateInterp(
            NvdlDispatcher d, NvdlInterpretation i,
            NvdlSection parentState)
        {
            SimpleMode m    = FindContextMode(i.Action, parentState);
            SimpleRule rule = FindElementRule(m, dispatcher.Reader);

            foreach (SimpleAction a in rule.Actions)
            {
                NvdlInterpretation cur = i;
                for (; cur != null; cur = cur.Parent)
                {
                    if (cur.CreatedMode == m && cur.Action == a)
                    {
                        break;
                    }
                }
                if (cur == null)
                {
                    cur = CreateInterp(d, m, a, i);
                }
                ilist.Add(cur);
            }
        }
Exemple #15
0
		public NvdlSection (NvdlDispatcher dispatcher,
			NvdlSection parentState)
		{
			this.dispatcher = dispatcher;
			this.ns = dispatcher.Reader.NamespaceURI;

			if (parentState == null) {
				foreach (SimpleAction a in FindElementRule (
					dispatcher.Rules.StartMode,
					dispatcher.Reader).Actions)
					ilist.Add (GetInterp (a, dispatcher));
			} else {
				foreach (NvdlInterpretation pi in
					parentState.ilist) {
					PopulateInterp (dispatcher, pi, parentState);
				}
			}

NvdlDebug.Writer.WriteLine ("New section: ns {0} / interp.count {1} / loc: {2}", ns, ilist.Count, ((IXmlLineInfo) dispatcher.Reader).LineNumber);
		}
Exemple #16
0
		private void PopulateInterp (
			NvdlDispatcher d, NvdlInterpretation i,
			NvdlSection parentState)
		{
			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) {
				NvdlInterpretation cur = i;
				for (;cur != null; cur = cur.Parent)
					if (cur.CreatedMode == m && cur.Action == a) {
NvdlDebug.Writer.WriteLine ("------- corresponding PlanElem already exists.");
						break;
					}
				if (cur == null)
					cur = CreateInterp (d, m, a, i);
				ilist.Add (cur);
			}
		}
Exemple #17
0
 public void Push(NvdlSection state)
 {
     List.Add(state);
 }
Exemple #18
0
		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, parentState)) {
NvdlDebug.Writer.WriteLine ("------ matched context at {0}.", ctx.Location);
							return ctx.UseMode;
}
			return a.DefaultMode;
		}
Exemple #19
0
		private bool MatchPath (SimplePath path, NvdlSection parentState)
		{
			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 != stack [elemStep] as string) {
					// reject a/b while allow a//b
					if (!ps.Descendants)
						return false;
					--elemStep;
				}
				else {
					i--;
					elemStep--;
				}
			}
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;
		}
Exemple #20
0
		public void Push (NvdlSection state)
		{
			List.Add (state);
		}
Exemple #21
0
		public void EndElement ()
		{
NvdlDebug.Writer.WriteLine ("  <dispatcher.EndElement {0}. depth: {1}",
Reader.Name, sectionStack.Count);
			if (section != null) {
				section = sectionStack.Pop ();
				section.EndElement ();
				section.EndSection ();
				if (sectionStack.Count > 0)
					section = sectionStack.Peek ();
				else
					section = null;
			}

			qnameStack.Pop ();
		}