Ejemplo n.º 1
0
        public ElementToken(int index, RangeList rangeList)
            : base(rangeList)
        {
            _startIndex = index;
            _rangeList = rangeList;

            Tokens = new LinkedList<ParseToken>();
            Attributes = new Dictionary<string, string>();
        }
Ejemplo n.º 2
0
        public static RootToken Parse(string text)
        {
            var root = XElement.Parse(text, LoadOptions.PreserveWhitespace);

            var rlist = new RangeList(root.Value);
            var rn = new RootToken(root, rlist);

            //ParamParser.Parse(rn);
            RemoveWhitespaces(rn, rlist);
            RemoveFormating(rn);
            return rn;
        }
Ejemplo n.º 3
0
 static ParseToken Create(XNode node, int index, RangeList list)
 {
     if (node is XText)
     {
         var len = ((XText)node).Value.Length;
         return new TextToken(index, len, list);
     }
     if (node is XElement)
     {
         var el = (XElement)node;
         var en = new ElementToken(index, list);
         ParseElement(en, el, index, list);
         return en;
     }
     throw new NotSupportedException(node.NodeType.ToString());
 }
Ejemplo n.º 4
0
        static void ParseElement(ElementToken en, XElement el, int index, RangeList list)
        {
            // parse name & attributes
            en.Name = el.Name.ToString();
            foreach (var attr in el.Attributes())
            {
                en.Attributes[attr.Name.ToString()] = attr.Value;
            }

            // parse nodes
            foreach (var node in el.Nodes())
            {
                var pn = Create(node, index, list);
                en.Tokens.AddLast(pn);
                index += pn.Length;
            }
        }
Ejemplo n.º 5
0
        static void ClearParamsInPre(ElementToken token, RangeList list)
        {
            foreach (var node in token.Tokens)
            {
                if (!(node is ElementToken)) continue;

                var el = (ElementToken)node;
                if (el.Name != "params")
                {
                    ClearParamsInPre(el, list);
                }
                else
                {
                    var i1 = el.StartIndex;
                    var i2 = el.EndIndex;
                    // clear range
                    ClearRange(i1, i2, list);
                }
            }
        }
Ejemplo n.º 6
0
        static void ClearRange(int i1, int i2, RangeList list)
        {
            if (i1 == i2) return;

            var str = list.GetText(i1, i2 - i1);

            // find seq-s of whitespace
            var regex = new Regex("\\s+");
            var ms = regex.Matches(str);

            foreach (Match m in ms)
            {
                var j1 = i1 + m.Index;
                var j2 = j1 + m.Length;
                list.Chars[j1] = ' ';
                for (var i = j1 + 1; i < j2; i++)
                {
                    list.Chars[i] = '\0';
                }
            }
        }
Ejemplo n.º 7
0
        static int Clear(int i1, ElementToken root, RangeList list)
        {
            foreach (var node in root.Tokens)
            {
                var i2 = node.StartIndex;
                if (!(node is ElementToken)) continue;

                var el = (ElementToken)node;
                if (el.Name != "pre")
                {
                    i1 = Clear(i1, el, list);
                }
                else
                {
                    ClearParamsInPre(el, list);
                    // clear range
                    ClearRange(i1, i2, list);
                    i1 = el.EndIndex;
                }
            }
            return i1;
        }
Ejemplo n.º 8
0
 static void RemoveWhitespaces(RootToken rt, RangeList list)
 {
     //var i1 = Clear(rt.StartIndex, rt, list);
     //ClearRange(i1, rt.EndIndex, list);
 }
Ejemplo n.º 9
0
 private TextToken(RangeList rangeList)
     : base(rangeList)
 {
 }
Ejemplo n.º 10
0
 public TextToken(int index, int len, RangeList rangeList)
     : base(rangeList)
 {
     Range = _rangeList.AddRange(index, len);
 }
Ejemplo n.º 11
0
 public RootToken(XElement root, RangeList rangeList)
     : base(0, rangeList)
 {
     ParseElement(this, root, 0, _rangeList);
 }
Ejemplo n.º 12
0
 protected ParseToken(RangeList rangeList)
 {
     _rangeList = rangeList;
     Tokens = new LinkedList<ParseToken>();
 }
Ejemplo n.º 13
0
 protected ParseToken(RangeList rangeList)
 {
     _rangeList = rangeList;
     Tokens     = new LinkedList <ParseToken>();
 }
Ejemplo n.º 14
0
 public RootToken(XElement root, RangeList rangeList)
     : base(0, rangeList)
 {
     ParseElement(this, root, 0, _rangeList);
 }