public SourceNodeCollection ReadNode(XmlElement elem, XmlDocument doc)
        {
            SourceNodeCollection snc = new SourceNodeCollection();
            foreach (XmlElement e2 in elem.ChildNodes)
            {
                if (e2.Name.Equals("SourceNode"))
                {
                    SourceNode sn = new SourceNode();
                    snc.Add(sn);
                    if (e2.HasAttribute("offset"))
                    {
                        long.TryParse(e2.GetAttribute("offset"), out sn.offset);
                    }
                    if (e2.HasAttribute("type"))
                    {
                        sn.type = e2.GetAttribute("type");
                    }

                    foreach (XmlElement e3 in e2.ChildNodes)
                    {
                        if (e3.Name.Equals("value"))
                            sn.value = e3.InnerText;
                        else if (e3.Name.Equals("comments"))
                            sn.comments = e3.InnerText;
                        else if (e3.Name.Equals("nodes"))
                            sn.Nodes = ReadNode(e3, doc);
                    }
                }
            }
            return snc;
        }
Example #2
0
        public override void Run()
        {
            StringBuilder sb = new StringBuilder();

            makeRegexes(Script);

            int start = 0;
            int state = 0;

            Elements = new SourceNodeCollection();

            Success = true;

            while (start < InputText.Length)
            {
                bool b = false;
                foreach (rgx r in Regexes)
                {
                    if (r.state == state)
                    {
                        Match m = r.regex.Match(InputText, start);
                        if (m.Success && m.Length > 0 && m.Index == start)
                        {
                            SourceNode dr = new SourceNode();
                            dr.offset = start;
                            dr.type = r.name;
                            dr.value = (r.printMatch ? InputText.Substring(start, m.Length) : "");
                            Elements.Add(dr);

                            start += m.Length;
                            b = true;
                            if (r.nextState >= 0)
                                state = r.nextState;
                            break;
                        }
                    }
                }
                if (!b)
                {
                    sb.AppendFormat("unrecognized sequence at {0} for state {1}\n", start, state);

                    LastPosition = start;

                    Success = false;
                    break;
                }
            }

            Message = sb.ToString();
        }
 public void Add(SourceNode sn)
 {
     CheckExistenceNodes();
     Nodes.Add(sn);
 }
Example #4
0
 public void AddSubnodes(SourceNode sn)
 {
     if (Nodes == null)
         Nodes = new SourceNodeCollection();
     Nodes.AddRange(sn.Nodes);
 }
Example #5
0
 public void AddNode(SourceNode sn)
 {
     if (Nodes == null)
         Nodes = new SourceNodeCollection();
     Nodes.Add(sn);
 }